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