| @@ 19-57 (lines=39) @@ | ||
| 16 | use Nette\Utils\Validators; |
|
| 17 | ||
| 18 | ||
| 19 | final class SluggableExtension extends AbstractBehaviorExtension |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var array |
|
| 24 | */ |
|
| 25 | private $default = [ |
|
| 26 | 'isRecursive' => TRUE, |
|
| 27 | 'trait' => Sluggable::class |
|
| 28 | ]; |
|
| 29 | ||
| 30 | ||
| 31 | public function loadConfiguration() |
|
| 32 | { |
|
| 33 | $config = $this->getConfig($this->default); |
|
| 34 | $this->validateConfigTypes($config); |
|
| 35 | $builder = $this->getContainerBuilder(); |
|
| 36 | ||
| 37 | $builder->addDefinition($this->prefix('listener')) |
|
| 38 | ->setClass(SluggableSubscriber::class, [ |
|
| 39 | '@' . $this->getClassAnalyzer()->getClass(), |
|
| 40 | $config['isRecursive'], |
|
| 41 | $config['trait'] |
|
| 42 | ]) |
|
| 43 | ->setAutowired(FALSE) |
|
| 44 | ->addTag(EventsExtension::TAG_SUBSCRIBER); |
|
| 45 | } |
|
| 46 | ||
| 47 | ||
| 48 | /** |
|
| 49 | * @throws AssertionException |
|
| 50 | */ |
|
| 51 | private function validateConfigTypes(array $config) |
|
| 52 | { |
|
| 53 | Validators::assertField($config, 'isRecursive', 'bool'); |
|
| 54 | Validators::assertField($config, 'trait', 'type'); |
|
| 55 | } |
|
| 56 | ||
| 57 | } |
|
| 58 | ||
| @@ 20-61 (lines=42) @@ | ||
| 17 | use Nette\Utils\Validators; |
|
| 18 | ||
| 19 | ||
| 20 | final class SoftDeletableExtension extends AbstractBehaviorExtension |
|
| 21 | { |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @var array |
|
| 25 | */ |
|
| 26 | private $default = [ |
|
| 27 | 'isRecursive' => TRUE, |
|
| 28 | 'trait' => SoftDeletable::class |
|
| 29 | ]; |
|
| 30 | ||
| 31 | ||
| 32 | public function loadConfiguration() |
|
| 33 | { |
|
| 34 | $config = $this->getConfig($this->default); |
|
| 35 | $this->validateConfigTypes($config); |
|
| 36 | $builder = $this->getContainerBuilder(); |
|
| 37 | ||
| 38 | $builder->addDefinition($this->prefix('listener')) |
|
| 39 | ->setClass(SoftDeletableSubscriber::class, [ |
|
| 40 | '@' . $this->getClassAnalyzer()->getClass(), |
|
| 41 | $config['isRecursive'], |
|
| 42 | $config['trait'] |
|
| 43 | ]) |
|
| 44 | ->setAutowired(FALSE) |
|
| 45 | ->addTag(EventsExtension::TAG_SUBSCRIBER); |
|
| 46 | } |
|
| 47 | ||
| 48 | ||
| 49 | /** |
|
| 50 | * @throws AssertionException |
|
| 51 | */ |
|
| 52 | private function validateConfigTypes(array $config) |
|
| 53 | { |
|
| 54 | Validators::assertField($config, 'isRecursive', 'bool'); |
|
| 55 | Validators::assertField($config, 'trait', 'type'); |
|
| 56 | } |
|
| 57 | ||
| 58 | } |
|
| 59 | ||
| @@ 19-60 (lines=42) @@ | ||
| 16 | use Nette\Utils\Validators; |
|
| 17 | ||
| 18 | ||
| 19 | final class TreeExtension extends AbstractBehaviorExtension |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var array |
|
| 24 | */ |
|
| 25 | private $default = [ |
|
| 26 | 'isRecursive' => TRUE, |
|
| 27 | 'nodeTrait' => Node::class |
|
| 28 | ]; |
|
| 29 | ||
| 30 | ||
| 31 | public function loadConfiguration() |
|
| 32 | { |
|
| 33 | $config = $this->getConfig($this->default); |
|
| 34 | $this->validateConfigTypes($config); |
|
| 35 | $builder = $this->getContainerBuilder(); |
|
| 36 | ||
| 37 | $builder->addDefinition($this->prefix('listener')) |
|
| 38 | ->setClass(TreeSubscriber::class, [ |
|
| 39 | '@' . $this->getClassAnalyzer()->getClass(), |
|
| 40 | $config['isRecursive'], |
|
| 41 | $config['nodeTrait'] |
|
| 42 | ]) |
|
| 43 | ->setAutowired(FALSE) |
|
| 44 | ->addTag(EventsExtension::TAG_SUBSCRIBER); |
|
| 45 | } |
|
| 46 | ||
| 47 | ||
| 48 | /** |
|
| 49 | * @throws AssertionException |
|
| 50 | */ |
|
| 51 | private function validateConfigTypes(array $config) |
|
| 52 | { |
|
| 53 | Validators::assertField($config, 'isRecursive', 'bool'); |
|
| 54 | Validators::assertField($config, 'nodeTrait', 'type'); |
|
| 55 | } |
|
| 56 | ||
| 57 | } |
|
| 58 | ||