diff --git a/composer.json b/composer.json index c7df21e5..05187024 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "symfony/expression-language": "^4.2", "symfony/filesystem": "^4.2", "symfony/finder": "^4.2", - "symfony/yaml": "^4.2" + "symfony/yaml": "^4.2", + "symfony/options-resolver": "^4.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index fbe85ccb..3352163f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e8a5119b7b3d1632bcc78a50845b04d9", + "content-hash": "68c4b0ecce3b1ddf4ada13528b27346b", "packages": [ { "name": "psr/cache", @@ -572,6 +572,60 @@ "homepage": "https://symfony.com", "time": "2019-06-13T11:03:18+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v4.4.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "2be23e63f33de16b49294ea6581f462932a77e2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/2be23e63f33de16b49294ea6581f462932a77e2f", + "reference": "2be23e63f33de16b49294ea6581f462932a77e2f", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony OptionsResolver Component", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "time": "2019-10-28T21:57:16+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.11.0", diff --git a/src/V1/Actor/Template/Tokenizer.php b/src/V1/Actor/Template/Tokenizer.php index fc247e22..08c8f064 100644 --- a/src/V1/Actor/Template/Tokenizer.php +++ b/src/V1/Actor/Template/Tokenizer.php @@ -4,9 +4,11 @@ namespace Neighborhoods\Buphalo\V1\Actor\Template; use Neighborhoods\Buphalo\V1\Actor; +use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface; class Tokenizer implements TokenizerInterface { + use Actor\Template\Tokenizer\Rule\Builder\Repository\AwareTrait; use Actor\Template\AwareTrait; use Actor\Template\AnnotationTokenizer\AwareTrait; use Actor\AwareTrait { @@ -27,6 +29,18 @@ public function getTokenizedContents(): string if ($this->TokenizedContents === null) { $this->getActorTemplateAnnotationTokenizer()->tokenize(); $templateContents = $this->getActorTemplate()->getTokenizedContents(); + + $ruleBuilderRepository = $this->getV1ActorTemplateTokenizerRuleBuilderRepository(); + $ruleBuilderMap = $ruleBuilderRepository->getMapByFileExtension(RepositoryInterface::FILE_TYPE_ALL); + foreach ($ruleBuilderMap as $key => $ruleBuilder) { + $ruleBuilder->setTemplateContents($templateContents); + $ruleBuilder->setActor($this->getActor()); + $ruleBuilder->setActorTemplate($this->getActorTemplate()); + $rule = $ruleBuilder->build(); + $tokenizedContents = $rule->getTokenizedContents(); + continue; + } + /** @noinspection NotOptimalRegularExpressionsInspection */ $tokenizedContents = preg_replace( '/namespace(\s+)Neighborhoods\\\BuphaloTemplateTree\\\PrimaryActorName/', diff --git a/src/V1/Actor/Template/Tokenizer.service.yml b/src/V1/Actor/Template/Tokenizer.service.yml index 24710dfd..55d2ada2 100644 --- a/src/V1/Actor/Template/Tokenizer.service.yml +++ b/src/V1/Actor/Template/Tokenizer.service.yml @@ -3,3 +3,5 @@ services: class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer public: false shared: false + calls: + - [setV1ActorTemplateTokenizerRuleBuilderRepository, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule.buphalo.v1.fabrication.yml b/src/V1/Actor/Template/Tokenizer/Rule.buphalo.v1.fabrication.yml new file mode 100644 index 00000000..bd50e808 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule.buphalo.v1.fabrication.yml @@ -0,0 +1,57 @@ +actors: + Interface.php: + template: PrimaryActorNameInterface.php + /AwareTrait.php: + template: PrimaryActorName/AwareTrait.php + /FactoryInterface.php: + template: PrimaryActorName/FactoryInterface.php + /Factory/AwareTrait.php: + template: PrimaryActorName/Factory/AwareTrait.php + /BuilderInterface.php: + template: PrimaryActorName/BuilderInterface.php + /Builder/AwareTrait.php: + template: PrimaryActorName/Builder/AwareTrait.php + /Builder/FactoryInterface.php: + template: PrimaryActorName/Builder/FactoryInterface.php + /Builder/Factory/AwareTrait.php: + template: PrimaryActorName/Builder/Factory/AwareTrait.php + /Repository.php: + template: PrimaryActorName/Repository.php + /Repository.service.yml: + template: PrimaryActorName/Repository.service.yml + /RepositoryInterface.php: + template: PrimaryActorName/RepositoryInterface.php + /Repository/AwareTrait.php: + template: PrimaryActorName/Repository/AwareTrait.php + /Map.php: + template: PrimaryActorName/Map.php + /Map.service.yml: + template: PrimaryActorName/Map.service.yml + /MapInterface.php: + template: PrimaryActorName/MapInterface.php + /Map/AwareTrait.php: + template: PrimaryActorName/Map/AwareTrait.php + /Map/Factory.php: + template: PrimaryActorName/Map/Factory.php + /Map/Factory.service.yml: + template: PrimaryActorName/Map/Factory.service.yml + /Map/FactoryInterface.php: + template: PrimaryActorName/Map/FactoryInterface.php + /Map/Factory/AwareTrait.php: + template: PrimaryActorName/Map/Factory/AwareTrait.php + /Map/Builder.php: + template: PrimaryActorName/Map/Builder.php + /Map/Builder.service.yml: + template: PrimaryActorName/Map/Builder.service.yml + /Map/BuilderInterface.php: + template: PrimaryActorName/Map/BuilderInterface.php + /Map/Builder/AwareTrait.php: + template: PrimaryActorName/Map/Builder/AwareTrait.php + /Map/Builder/Factory.php: + template: PrimaryActorName/Map/Builder/Factory.php + /Map/Builder/Factory.service.yml: + template: PrimaryActorName/Map/Builder/Factory.service.yml + /Map/Builder/FactoryInterface.php: + template: PrimaryActorName/Map/Builder/FactoryInterface.php + /Map/Builder/Factory/AwareTrait.php: + template: PrimaryActorName/Map/Builder/Factory/AwareTrait.php diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.php new file mode 100644 index 00000000..0d637b6c --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.php @@ -0,0 +1,73 @@ +count() !== 0) { + throw new \LogicException('Map is not empty.'); + } + + if (!empty($builders)) { + $this->assertValidArrayType(...array_values($builders)); + } + + parent::__construct($builders, $flags); + } + + public function offsetGet($index): BuilderInterface + { + return $this->assertValidArrayItemType(parent::offsetGet($index)); + } + + /** @param BuilderInterface $builder */ + public function offsetSet($index, $builder) + { + parent::offsetSet($index, $this->assertValidArrayItemType($builder)); + } + + /** @param BuilderInterface $builder */ + public function append($builder) + { + $this->assertValidArrayItemType($builder); + parent::append($builder); + } + + public function current(): BuilderInterface + { + return parent::current(); + } + + protected function assertValidArrayItemType(BuilderInterface $builder) + { + return $builder; + } + + protected function assertValidArrayType(BuilderInterface ...$builders): MapInterface + { + return $this; + } + + public function getArrayCopy(): MapInterface + { + return new self(parent::getArrayCopy(), (int)$this->getFlags()); + } + + public function toArray(): array + { + return (array)$this; + } + + public function hydrate(array $array): MapInterface + { + $this->__construct($array); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.service.yml new file mode 100644 index 00000000..a0d96b75 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map.service.yml @@ -0,0 +1,5 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\MapInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map + public: false + shared: false diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/AwareTrait.php new file mode 100644 index 00000000..9cc7e0a6 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/AwareTrait.php @@ -0,0 +1,45 @@ +hasV1ActorTemplateTokenizerRuleBuilderMap()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap = $v1ActorTemplateTokenizerRuleBuilderMap; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderMap(): MapInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMap()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderMap(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderMap(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMap()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.php new file mode 100644 index 00000000..e52af9bf --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.php @@ -0,0 +1,16 @@ +getV1ActorTemplateTokenizerRuleBuilderMap()->getArrayCopy(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.service.yml new file mode 100644 index 00000000..9fdc0c4c --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory.service.yml @@ -0,0 +1,7 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\FactoryInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Factory + public: false + shared: true + calls: + - [setV1ActorTemplateTokenizerRuleBuilderMap, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\MapInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory/AwareTrait.php new file mode 100644 index 00000000..9c58614b --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1ActorTemplateTokenizerRuleBuilderMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory = $v1ActorTemplateTokenizerRuleBuilderMapFactory; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderMapFactory(): FactoryInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderMapFactory(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderMapFactory(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/FactoryInterface.php new file mode 100644 index 00000000..d781f0e6 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/FactoryInterface.php @@ -0,0 +1,11 @@ +count() !== 0) { + throw new LogicException('Map is not empty.'); + } + + if (!empty($maps)) { + $this->assertValidArrayType(...array_values($maps)); + } + + parent::__construct($maps, $flags); + } + + public function offsetGet($index): Builder\MapInterface + { + return $this->assertValidArrayItemType(parent::offsetGet($index)); + } + + /** @param Builder\MapInterface $map */ + public function offsetSet($index, $map) + { + parent::offsetSet($index, $this->assertValidArrayItemType($map)); + } + + /** @param Builder\MapInterface $map */ + public function append($map) + { + $this->assertValidArrayItemType($map); + parent::append($map); + } + + public function current(): Builder\MapInterface + { + return parent::current(); + } + + protected function assertValidArrayItemType(Builder\MapInterface $map) + { + return $map; + } + + protected function assertValidArrayType(Builder\MapInterface ...$maps): MapInterface + { + return $this; + } + + public function getArrayCopy(): MapInterface + { + return new self(parent::getArrayCopy(), (int)$this->getFlags()); + } + + public function toArray(): array + { + return (array)$this; + } + + public function hydrate(array $array): MapInterface + { + $this->__construct($array); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map.service.yml new file mode 100644 index 00000000..7e62f87d --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map.service.yml @@ -0,0 +1,5 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\MapInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Map + public: false + shared: false diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/AwareTrait.php new file mode 100644 index 00000000..431a0520 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1ActorTemplateTokenizerRuleBuilderMapMap()) { + throw new LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap = $v1ActorTemplateTokenizerRuleBuilderMapMap; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderMapMap(): MapInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapMap()) { + throw new LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderMapMap(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderMapMap(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapMap()) { + throw new LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMap); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.php new file mode 100644 index 00000000..5eb9deba --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.php @@ -0,0 +1,16 @@ +getV1ActorTemplateTokenizerRuleBuilderMapMap()->getArrayCopy(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.service.yml new file mode 100644 index 00000000..8586dc32 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory.service.yml @@ -0,0 +1,7 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Map\FactoryInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Map\Factory + public: false + shared: true + calls: + - [setV1ActorTemplateTokenizerRuleBuilderMapMap, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\MapInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory/AwareTrait.php new file mode 100644 index 00000000..da23f6bf --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1ActorTemplateTokenizerRuleBuilderMapMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory = $v1ActorTemplateTokenizerRuleBuilderMapMapFactory; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderMapMapFactory(): FactoryInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderMapMapFactory(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderMapMapFactory(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderMapMapFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapMapFactory); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/FactoryInterface.php new file mode 100644 index 00000000..830e9d86 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Map/Map/FactoryInterface.php @@ -0,0 +1,11 @@ +getOptions()[BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY]; + if (!isset($this->getV1ActorTemplateTokenizerRuleBuilderMapMap()[$fileExtensionAffinity])) { + $builderMap = $this->getV1ActorTemplateTokenizerRuleBuilderMapFactory()->create(); + $this->getV1ActorTemplateTokenizerRuleBuilderMapMap()[$fileExtensionAffinity] = $builderMap; + } + $this->getV1ActorTemplateTokenizerRuleBuilderMapMap()[$fileExtensionAffinity]->append($Builder); + + return $this; + } + + public function getMapByFileExtension(string $FileExtension): MapInterface + { + $map = $this->getV1ActorTemplateTokenizerRuleBuilderMapFactory()->create(); + foreach ($this->getV1ActorTemplateTokenizerRuleBuilderMapMap()[$FileExtension] as $prototype) { + $map[] = $this->copy($prototype); + } + + return $map; + } + + private function copy(BuilderInterface $prototype): BuilderInterface + { + /** @var BuilderInterface $builder */ + $builder = $prototype->getOptions()[Repository\BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE]->create(); + $builder->setOptions($prototype->getOptions()); + + return $builder; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository.service.yml new file mode 100644 index 00000000..f2048a27 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository.service.yml @@ -0,0 +1,8 @@ +parameters: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface.fqcn: '\Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository' +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface: + class: '%Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface.fqcn%' + factory: ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface', 'build'] + public: false + shared: true diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/AwareTrait.php new file mode 100644 index 00000000..31614f7e --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1ActorTemplateTokenizerRuleBuilderRepository()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository = $v1ActorTemplateTokenizerRuleBuilderRepository; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderRepository(): RepositoryInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderRepository()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderRepository(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderRepository(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderRepository()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepository); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.php new file mode 100644 index 00000000..e12aaf6d --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.php @@ -0,0 +1,72 @@ +assertRepositoryIsNotBuilt(); + $repository = $this->getV1ActorTemplateTokenizerRuleBuilderRepositoryFactory()->create(); + $repository->setV1ActorTemplateTokenizerRuleBuilderMapFactory( + $this->getV1ActorTemplateTokenizerRuleBuilderMapFactory() + ); + $repository->setV1ActorTemplateTokenizerRuleBuilderMapMap( + $this->getV1ActorTemplateTokenizerRuleBuilderMapMapFactory()->create() + ); + + $this->setV1ActorTemplateTokenizerRuleBuilderRepository($repository); + + foreach ($this->getRuleOptions() as $options) { + $ruleBuilder = $this->extractRuleBuilder($options); + $ruleBuilder->setOptions($options); + $repository->add($ruleBuilder); + } + + return $repository; + } + + private function extractRuleBuilder(array $options): Rule\BuilderInterface + { + return $options[BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE]->create(); + } + + protected function getRuleOptions(): array + { + if ($this->Options === null) { + throw new LogicException('Builder options has not been set.'); + } + + return $this->Options; + } + + public function addOptions(array $options): BuilderInterface + { + $this->assertRepositoryIsNotBuilt(); + $this->Options[] = $options; + + return $this; + } + + private function assertRepositoryIsNotBuilt(): BuilderInterface + { + if ($this->hasV1ActorTemplateTokenizerRuleBuilderRepository()) { + throw new LogicException('Repository is already built.'); + } + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.service.yml new file mode 100644 index 00000000..82149e70 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Builder.service.yml @@ -0,0 +1,38 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\Builder + public: false + shared: true + calls: + - [setV1ActorTemplateTokenizerRuleBuilderMapMapFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Map\FactoryInterface']] + - [setV1ActorTemplateTokenizerRuleBuilderMapFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\FactoryInterface']] + - [setV1ActorTemplateTokenizerRuleBuilderRepositoryFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\FactoryInterface']] + - [addOptions, + [{ + file.extension.affinity: !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface::FILE_TYPE_ALL, + builder.factory.service: '@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\FactoryInterface', + rule.search: "\"['@Neighborhoods\\\\BuphaloTemplateTree\\\\PrimaryActorName\"", + rule.replace: "sprintf( + '[\\'@%%s%%s\\\\%%s', + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::NAMESPACE_PREFIX_TOKEN\"), + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::NAMESPACE_RELATIVE_TOKEN\"), + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::PRIMARY_ACTOR_SHORT_PASCAL_CASE_NAME_TOKEN\") + )"}]] + - [addOptions, + [{ + file.extension.affinity: !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface::FILE_TYPE_ALL, + builder.factory.service: '@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\FactoryInterface', + rule.search: "'\\PrimaryActorName;'", + rule.replace: "sprintf('%%s;', constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::EMPTY_TOKEN\") + )"}]] + - [addOptions, + [{ + file.extension.affinity: !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface::FILE_TYPE_ALL, + builder.factory.service: '@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\Builder\FactoryInterface', + rule.pattern: "'/namespace(\\s+)Neighborhoods\\\\\\BuphaloTemplateTree\\\\\\PrimaryActorName/'", + rule.replacement: "sprintf( + 'namespace %%s%%s\\\\%%s', + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::NAMESPACE_PREFIX_TOKEN\"), + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::NAMESPACE_RELATIVE_TOKEN\"), + constant(\"Neighborhoods\\\\Buphalo\\\\V1\\\\Actor\\\\Template\\\\TokenizerInterface::PRIMARY_ACTOR_SHORT_PASCAL_CASE_NAME_TOKEN\") + )"}]] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/BuilderInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/BuilderInterface.php new file mode 100644 index 00000000..69836e44 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/BuilderInterface.php @@ -0,0 +1,13 @@ +hasV1ActorTemplateTokenizerRuleBuilderRepository()) { + throw new LogicException('The repository factory create method was called twice.'); + } + + $repositoryFQCN = $this->getV1ActorTemplateTokenizerRuleBuilderRepositoryFQCN(); + $this->setV1ActorTemplateTokenizerRuleBuilderRepository(new $repositoryFQCN); + + return $this->getV1ActorTemplateTokenizerRuleBuilderRepository(); + } + + private function getV1ActorTemplateTokenizerRuleBuilderRepositoryFQCN() + { + if ($this->V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN === null) { + throw new LogicException('V1 Actor Template Tokenizer Rule Repository FQCN has not been set.'); + } + + return $this->V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN; + } + + public function setV1ActorTemplateTokenizerRuleBuilderRepositoryFQCN($V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN + ): FactoryInterface { + if ($this->V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN !== null) { + throw new LogicException('V1 Actor Template Tokenizer Rule Repository FQCN is already set.'); + } + + $this->V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN = $V1ActorTemplateTokenizerRuleBuilderRepositoryFQCN; + + return $this; + } + +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory.service.yml new file mode 100644 index 00000000..3cbbb391 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory.service.yml @@ -0,0 +1,7 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\FactoryInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\Factory + public: false + shared: true + calls: + - [setV1ActorTemplateTokenizerRuleBuilderRepositoryFQCN, ['%Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\RepositoryInterface.fqcn%']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory/AwareTrait.php new file mode 100644 index 00000000..e65672c9 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1ActorTemplateTokenizerRuleBuilderRepositoryFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory = $v1ActorTemplateTokenizerRuleBuilderRepositoryFactory; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleBuilderRepositoryFactory(): FactoryInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderRepositoryFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory; + } + + protected function hasV1ActorTemplateTokenizerRuleBuilderRepositoryFactory(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory); + } + + protected function unsetV1ActorTemplateTokenizerRuleBuilderRepositoryFactory(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleBuilderRepositoryFactory()) { + throw new \LogicException('NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderRepositoryFactory); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/FactoryInterface.php new file mode 100644 index 00000000..85e20458 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Builder/Repository/FactoryInterface.php @@ -0,0 +1,11 @@ +.php: + template: PrimaryActorName.php + .service.yml: + template: PrimaryActorName.service.yml + Interface.php: + template: PrimaryActorNameInterface.php + /AwareTrait.php: + template: PrimaryActorName/AwareTrait.php + /Factory.php: + template: PrimaryActorName/Factory.php + /Factory.service.yml: + template: PrimaryActorName/Factory.service.yml + /FactoryInterface.php: + template: PrimaryActorName/FactoryInterface.php + /Factory/AwareTrait.php: + template: PrimaryActorName/Factory/AwareTrait.php + /Builder.php: + template: PrimaryActorName/Builder.php + /Builder.service.yml: + template: PrimaryActorName/Builder.service.yml + /BuilderInterface.php: + template: PrimaryActorName/BuilderInterface.php + /Builder/AwareTrait.php: + template: PrimaryActorName/Builder/AwareTrait.php + /Builder/Factory.php: + template: PrimaryActorName/Builder/Factory.php + /Builder/Factory.service.yml: + template: PrimaryActorName/Builder/Factory.service.yml + /Builder/FactoryInterface.php: + template: PrimaryActorName/Builder/FactoryInterface.php + /Builder/Factory/AwareTrait.php: + template: PrimaryActorName/Builder/Factory/AwareTrait.php + /Repository.php: + template: PrimaryActorName/Repository.php + /Repository.service.yml: + template: PrimaryActorName/Repository.service.yml + /RepositoryInterface.php: + template: PrimaryActorName/RepositoryInterface.php + /Repository/AwareTrait.php: + template: PrimaryActorName/Repository/AwareTrait.php diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Context.php b/src/V1/Actor/Template/Tokenizer/Rule/Context.php new file mode 100644 index 00000000..0fdb85ec --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Context.php @@ -0,0 +1,19 @@ +getV1ActorTemplateTokenizerRuleContextFactory()->create(); + $Context->setActor($this->getActor()); + $Context->setActorTemplate($this->getActorTemplate()); + + return $Context; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Context/Builder.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/Context/Builder.service.yml new file mode 100644 index 00000000..41680d89 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Context/Builder.service.yml @@ -0,0 +1,7 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Context\BuilderInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Context\Builder + public: false + shared: false + calls: + - [setV1ActorTemplateTokenizerRuleContextFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Context\FactoryInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/Context/BuilderInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/Context/BuilderInterface.php new file mode 100644 index 00000000..52c1f1ac --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/Context/BuilderInterface.php @@ -0,0 +1,17 @@ +.php: + template: PrimaryActorName.php + .service.yml: + template: PrimaryActorName.service.yml + Interface.php: + template: PrimaryActorNameInterface.php + /AwareTrait.php: + template: PrimaryActorName/AwareTrait.php + /Factory.php: + template: PrimaryActorName/Factory.php + /Factory.service.yml: + template: PrimaryActorName/Factory.service.yml + /FactoryInterface.php: + template: PrimaryActorName/FactoryInterface.php + /Factory/AwareTrait.php: + template: PrimaryActorName/Factory/AwareTrait.php + /Builder.php: + template: PrimaryActorName/Builder.php + /Builder.service.yml: + template: PrimaryActorName/Builder.service.yml + /BuilderInterface.php: + template: PrimaryActorName/BuilderInterface.php + /Builder/AwareTrait.php: + template: PrimaryActorName/Builder/AwareTrait.php + /Builder/Factory.php: + template: PrimaryActorName/Builder/Factory.php + /Builder/Factory.service.yml: + template: PrimaryActorName/Builder/Factory.service.yml + /Builder/FactoryInterface.php: + template: PrimaryActorName/Builder/FactoryInterface.php + /Builder/Factory/AwareTrait.php: + template: PrimaryActorName/Builder/Factory/AwareTrait.php diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.php new file mode 100644 index 00000000..0f9ef197 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.php @@ -0,0 +1,113 @@ +addFunction(ExpressionFunction::fromPhp('sprintf')); + $pattern = $expressionLanguage->evaluate($this->getPattern()); + $replacement = $expressionLanguage->evaluate($this->getReplacement()); + $tokenizedContents = preg_replace( + $pattern, + $replacement, + $this->getTemplateContents() + ); + + return $tokenizedContents; + } + + private function getPattern(): string + { + if ($this->Pattern === null) { + throw new LogicException('Pattern has not been set.'); + } + + return $this->Pattern; + } + + public function setPattern(string $Pattern): PregReplaceInterface + { + if ($this->Pattern !== null) { + throw new LogicException('Pattern is already set.'); + } + $this->Pattern = $Pattern; + + return $this; + } + + private function getReplacement(): string + { + if ($this->Replacement === null) { + throw new LogicException('Replacement has not been set.'); + } + + return $this->Replacement; + } + + public function setReplacement(string $Replacement): PregReplaceInterface + { + if ($this->Replacement !== null) { + throw new LogicException('Replacement is already set.'); + } + + $this->Replacement = $Replacement; + + return $this; + } + + private function getTemplateContents(): string + { + if ($this->TemplateContents === null) { + throw new LogicException('Template Contents has not been set.'); + } + + return $this->TemplateContents; + } + + public function setTemplateContents(string $TemplateContents): PregReplaceInterface + { + if ($this->TemplateContents !== null) { + throw new LogicException('Template Contents is already set.'); + } + + $this->TemplateContents = $TemplateContents; + + return $this; + } + + public function getFileExtensionAffinity(): string + { + if ($this->FileExtensionAffinity === null) { + throw new LogicException('File Extension Affinity has not been set.'); + } + + return $this->FileExtensionAffinity; + } + + public function setFileExtensionAffinity(string $FileExtensionAffinity): PregReplaceInterface + { + if ($this->FileExtensionAffinity !== null) { + throw new LogicException('File Extension Affinity is already set.'); + } + + $this->FileExtensionAffinity = $FileExtensionAffinity; + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.service.yml new file mode 100644 index 00000000..a53776b2 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace.service.yml @@ -0,0 +1,5 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplaceInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace + public: false + shared: false diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.php new file mode 100644 index 00000000..c77792e7 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.php @@ -0,0 +1,81 @@ +getV1ActorTemplateTokenizerRulePregReplaceFactory()->create(); + $pregReplace->setPattern($this->getOptions()[V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_SEARCH]); + $pregReplace->setReplacement( + $this->getOptions()[V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_REPLACE] + ); + $pregReplace->setFileExtensionAffinity( + $this->getOptions()[V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY] + ); + $pregReplace->setTemplateContents($this->getTemplateContents()); + $ruleContextBuilder = $this->getV1ActorTemplateTokenizerRuleContextBuilderFactory()->create(); + $ruleContextBuilder->setActorTemplate($this->getActorTemplate()); + $ruleContextBuilder->setActor($this->getActor()); + $pregReplace->setV1ActorTemplateTokenizerRuleContext($ruleContextBuilder->build()); + + return $pregReplace; + } + + public function getOptions(): array + { + if ($this->Options === null) { + throw new LogicException('Builder options has not been set.'); + } + + return $this->Options; + } + + public function setOptions(array $options): BuilderInterface + { + if ($this->Options !== null) { + throw new LogicException('Builder options is already set.'); + } + + $this->getV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator()->resolve($options); + + $this->Options = $options; + + return $this; + } + + private function getTemplateContents(): string + { + if ($this->TemplateContents === null) { + throw new LogicException('Template Contents has not been set.'); + } + + return $this->TemplateContents; + } + + public function setTemplateContents(string $TemplateContents): BuilderInterface + { + if ($this->TemplateContents !== null) { + throw new LogicException('Template Contents is already set.'); + } + + $this->TemplateContents = $TemplateContents; + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.service.yml new file mode 100644 index 00000000..52c5def7 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder.service.yml @@ -0,0 +1,9 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\BuilderInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\Builder + public: false + shared: false + calls: + - [setV1ActorTemplateTokenizerRulePregReplaceFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\FactoryInterface']] + - [setV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\Builder\OptionsResolverDecoratorInterface']] + - [setV1ActorTemplateTokenizerRuleContextBuilderFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Context\Builder\FactoryInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/Factory.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/Factory.php new file mode 100644 index 00000000..6740ae8a --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/Factory.php @@ -0,0 +1,16 @@ +getV1ActorTemplateTokenizerRulePregReplaceBuilder(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/FactoryInterface.php new file mode 100644 index 00000000..8c8340ed --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/FactoryInterface.php @@ -0,0 +1,10 @@ +getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefault($option, $value); + + return $this; + } + + public function setDefaults(array $defaults): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefaults($defaults); + + return $this; + } + + public function hasDefault(string $option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->hasDefault($option); + } + + public function setRequired($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setRequired($optionNames); + + return $this; + } + + public function isRequired($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isRequired($option); + } + + public function getRequiredOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getRequiredOptions(); + } + + public function isMissing($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isMissing($option); + } + + public function getMissingOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getMissingOptions(); + } + + public function setDefined($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefined($optionNames); + + return $this; + } + + public function isDefined($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isDefined($option); + } + + public function getDefinedOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getDefinedOptions(); + } + + public function isNested(string $option): bool + { + return isset($this->nested[$option]); + } + + public function setDeprecated( + string $option, + $deprecationMessage = 'The option "%name%" is deprecated.' + ): OptionsResolverDecoratorInterface { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDeprecated($option, $deprecationMessage); + + return $this; + } + + public function isDeprecated(string $option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isDeprecated($option); + } + + public function setNormalizer($option, Closure $normalizer): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setNormalizer($option, $normalizer); + + return $this; + } + + public function addNormalizer( + string $option, + Closure $normalizer, + bool $forcePrepend = false + ): OptionsResolverDecoratorInterface { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver() + ->addNormalizer($option, $normalizer, $forcePrepend); + + return $this; + } + + public function setAllowedValues($option, $allowedValues): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setAllowedValues($option, $allowedValues); + + return $this; + } + + public function addAllowedValues($option, $allowedValues): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->addAllowedValues($option, $allowedValues); + + return $this; + } + + public function setAllowedTypes($option, $allowedTypes): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setAllowedTypes($option, $allowedTypes); + + return $this; + } + + public function addAllowedTypes($option, $allowedTypes): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->addAllowedTypes($option, $allowedTypes); + + return $this; + } + + public function remove($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->remove($optionNames); + + return $this; + } + + public function clear(): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->clear(); + + return $this; + } + + public function resolve(array $options = []): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->resolve($options); + } + + public function offsetGet($option) + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetGet($option); + } + + public function offsetExists($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetExists($option); + } + + public function offsetSet($option, $value): void + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetSet($option, $value); + } + + public function offsetUnset($option): void + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetUnset($option); + } + + public function count(): int + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->count(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator.service.yml new file mode 100644 index 00000000..1a49e792 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator.service.yml @@ -0,0 +1,18 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\Builder\OptionsResolverDecoratorInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\Builder\OptionsResolverDecorator + public: false + shared: false + calls: + - [setV1SymfonyComponentOptionsResolverOptionsResolver, ['@Symfony\Component\OptionsResolver\OptionsResolver']] + - [setRequired, + [[ + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\BuilderInterface::OPTION_PATTERN, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\BuilderInterface::OPTION_REPLACEMENT + ]]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY, "string",]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE, "\\Neighborhoods\\Buphalo\\V1\\Actor\\Template\\Tokenizer\\Rule\\Builder\\FactoryInterface"]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\BuilderInterface::OPTION_PATTERN, "string"]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\PregReplace\BuilderInterface::OPTION_REPLACEMENT, "string"]] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator/AwareTrait.php new file mode 100644 index 00000000..b0113092 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecorator/AwareTrait.php @@ -0,0 +1,48 @@ +hasV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule PregReplace Builder OptionsResolverDecorator is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator = $v1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator( + ): OptionsResolverDecoratorInterface + { + if (!$this->hasV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule PregReplace Builder OptionsResolverDecorator is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator; + } + + protected function hasV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator); + } + + protected function unsetV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator(): self + { + if (!$this->hasV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule PregReplace Builder OptionsResolverDecorator is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRulePregReplaceBuilderOptionsResolverDecorator); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecoratorInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecoratorInterface.php new file mode 100644 index 00000000..cfe22a53 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/PregReplace/Builder/OptionsResolverDecoratorInterface.php @@ -0,0 +1,73 @@ +.php: + template: PrimaryActorName.php + .service.yml: + template: PrimaryActorName.service.yml + Interface.php: + template: PrimaryActorNameInterface.php + /AwareTrait.php: + template: PrimaryActorName/AwareTrait.php + /Factory.php: + template: PrimaryActorName/Factory.php + /Factory.service.yml: + template: PrimaryActorName/Factory.service.yml + /FactoryInterface.php: + template: PrimaryActorName/FactoryInterface.php + /Factory/AwareTrait.php: + template: PrimaryActorName/Factory/AwareTrait.php + /Builder.php: + template: PrimaryActorName/Builder.php + /Builder.service.yml: + template: PrimaryActorName/Builder.service.yml + /BuilderInterface.php: + template: PrimaryActorName/BuilderInterface.php + /Builder/AwareTrait.php: + template: PrimaryActorName/Builder/AwareTrait.php + /Builder/Factory.php: + template: PrimaryActorName/Builder/Factory.php + /Builder/Factory.service.yml: + template: PrimaryActorName/Builder/Factory.service.yml + /Builder/FactoryInterface.php: + template: PrimaryActorName/Builder/FactoryInterface.php + /Builder/Factory/AwareTrait.php: + template: PrimaryActorName/Builder/Factory/AwareTrait.php diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace.php new file mode 100644 index 00000000..aa96ab38 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace.php @@ -0,0 +1,113 @@ +addFunction(ExpressionFunction::fromPhp('sprintf')); + $search = $expressionLanguage->evaluate($this->getSearch()); + $replace = $expressionLanguage->evaluate($this->getReplace()); + $tokenizedContents = str_replace( + $search, + $replace, + $this->getTemplateContents() + ); + + return $tokenizedContents; + } + + private function getSearch(): string + { + if ($this->Search === null) { + throw new LogicException('Search has not been set.'); + } + + return $this->Search; + } + + public function setSearch(string $Search): StrReplaceInterface + { + if ($this->Search !== null) { + throw new LogicException('Search is already set.'); + } + $this->Search = $Search; + + return $this; + } + + private function getReplace(): string + { + if ($this->Replace === null) { + throw new LogicException('Replace has not been set.'); + } + + return $this->Replace; + } + + public function setReplace(string $Replace): StrReplaceInterface + { + if ($this->Replace !== null) { + throw new LogicException('Replace is already set.'); + } + + $this->Replace = $Replace; + + return $this; + } + + private function getTemplateContents(): string + { + if ($this->TemplateContents === null) { + throw new LogicException('Template Contents has not been set.'); + } + + return $this->TemplateContents; + } + + public function setTemplateContents(string $TemplateContents): StrReplaceInterface + { + if ($this->TemplateContents !== null) { + throw new LogicException('Template Contents is already set.'); + } + + $this->TemplateContents = $TemplateContents; + + return $this; + } + + public function getFileExtensionAffinity(): string + { + if ($this->FileExtensionAffinity === null) { + throw new LogicException('File Extension Affinity has not been set.'); + } + + return $this->FileExtensionAffinity; + } + + public function setFileExtensionAffinity(string $FileExtensionAffinity): StrReplaceInterface + { + if ($this->FileExtensionAffinity !== null) { + throw new LogicException('File Extension Affinity is already set.'); + } + + $this->FileExtensionAffinity = $FileExtensionAffinity; + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.php new file mode 100644 index 00000000..a1fad1a2 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.php @@ -0,0 +1,79 @@ +getV1ActorTemplateTokenizerRuleStrReplaceFactory()->create(); + $StrReplace->setSearch($this->getOptions()[BuilderInterface::OPTION_SEARCH]); + $StrReplace->setReplace($this->getOptions()[BuilderInterface::OPTION_REPLACE]); + $StrReplace->setFileExtensionAffinity( + $this->getOptions()[V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY] + ); + $StrReplace->setTemplateContents($this->getTemplateContents()); + $ruleContextBuilder = $this->getV1ActorTemplateTokenizerRuleContextBuilderFactory()->create(); + $ruleContextBuilder->setActorTemplate($this->getActorTemplate()); + $ruleContextBuilder->setActor($this->getActor()); + $StrReplace->setV1ActorTemplateTokenizerRuleContext($ruleContextBuilder->build()); + + return $StrReplace; + } + + public function getOptions(): array + { + if ($this->Options === null) { + throw new LogicException('Builder options has not been set.'); + } + + return $this->Options; + } + + public function setOptions(array $options): BuilderInterface + { + if ($this->Options !== null) { + throw new LogicException('Builder options is already set.'); + } + + $this->getV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator()->resolve($options); + + $this->Options = $options; + + return $this; + } + + private function getTemplateContents(): string + { + if ($this->TemplateContents === null) { + throw new LogicException('Template Contents has not been set.'); + } + + return $this->TemplateContents; + } + + public function setTemplateContents(string $TemplateContents): BuilderInterface + { + if ($this->TemplateContents !== null) { + throw new LogicException('Template Contents is already set.'); + } + + $this->TemplateContents = $TemplateContents; + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.service.yml new file mode 100644 index 00000000..4b978acb --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder.service.yml @@ -0,0 +1,9 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder + public: false + shared: false + calls: + - [setV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\OptionsResolverDecoratorInterface']] + - [setV1ActorTemplateTokenizerRuleStrReplaceFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\FactoryInterface']] + - [setV1ActorTemplateTokenizerRuleContextBuilderFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Context\Builder\FactoryInterface']] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/Factory.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/Factory.php new file mode 100644 index 00000000..df3d6d16 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/Factory.php @@ -0,0 +1,16 @@ +getV1ActorTemplateTokenizerRuleStrReplaceBuilder(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/FactoryInterface.php new file mode 100644 index 00000000..b0a1e7b4 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/FactoryInterface.php @@ -0,0 +1,10 @@ +getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefault($option, $value); + + return $this; + } + + public function setDefaults(array $defaults): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefaults($defaults); + + return $this; + } + + public function hasDefault(string $option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->hasDefault($option); + } + + public function setRequired($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setRequired($optionNames); + + return $this; + } + + public function isRequired($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isRequired($option); + } + + public function getRequiredOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getRequiredOptions(); + } + + public function isMissing($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isMissing($option); + } + + public function getMissingOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getMissingOptions(); + } + + public function setDefined($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDefined($optionNames); + + return $this; + } + + public function isDefined($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isDefined($option); + } + + public function getDefinedOptions(): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->getDefinedOptions(); + } + + public function isNested(string $option): bool + { + return isset($this->nested[$option]); + } + + public function setDeprecated( + string $option, + $deprecationMessage = 'The option "%name%" is deprecated.' + ): OptionsResolverDecoratorInterface { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setDeprecated($option, $deprecationMessage); + + return $this; + } + + public function isDeprecated(string $option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->isDeprecated($option); + } + + public function setNormalizer($option, Closure $normalizer): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setNormalizer($option, $normalizer); + + return $this; + } + + public function addNormalizer( + string $option, + Closure $normalizer, + bool $forcePrepend = false + ): OptionsResolverDecoratorInterface { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver() + ->addNormalizer($option, $normalizer, $forcePrepend); + + return $this; + } + + public function setAllowedValues($option, $allowedValues): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setAllowedValues($option, $allowedValues); + + return $this; + } + + public function addAllowedValues($option, $allowedValues): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->addAllowedValues($option, $allowedValues); + + return $this; + } + + public function setAllowedTypes($option, $allowedTypes): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->setAllowedTypes($option, $allowedTypes); + + return $this; + } + + public function addAllowedTypes($option, $allowedTypes): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->addAllowedTypes($option, $allowedTypes); + + return $this; + } + + public function remove($optionNames): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->remove($optionNames); + + return $this; + } + + public function clear(): OptionsResolverDecoratorInterface + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->clear(); + + return $this; + } + + public function resolve(array $options = []): array + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->resolve($options); + } + + public function offsetGet($option) + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetGet($option); + } + + public function offsetExists($option): bool + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetExists($option); + } + + public function offsetSet($option, $value): void + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetSet($option, $value); + } + + public function offsetUnset($option): void + { + $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->offsetUnset($option); + } + + public function count(): int + { + return $this->getV1SymfonyComponentOptionsResolverOptionsResolver()->count(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator.service.yml new file mode 100644 index 00000000..d5271f08 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator.service.yml @@ -0,0 +1,18 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\OptionsResolverDecoratorInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\OptionsResolverDecorator + public: false + shared: false + calls: + - [setV1SymfonyComponentOptionsResolverOptionsResolver, ['@Symfony\Component\OptionsResolver\OptionsResolver']] + - [setRequired, + [[ + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_SEARCH, + !php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_REPLACE + ]]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\BuilderInterface::OPTION_FILE_EXTENSION_AFFINITY, "string",]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Repository\BuilderInterface::OPTION_BUILDER_FACTORY_SERVICE, "\\Neighborhoods\\Buphalo\\V1\\Actor\\Template\\Tokenizer\\Rule\\Builder\\FactoryInterface"]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_SEARCH, "string"]] + - [setAllowedTypes, [!php/const \Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\BuilderInterface::OPTION_REPLACE, "string"]] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator/AwareTrait.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator/AwareTrait.php new file mode 100644 index 00000000..de978c79 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecorator/AwareTrait.php @@ -0,0 +1,48 @@ +hasV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule StrReplace Builder OptionsResolverDecorator is already set.'); + } + $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator = $v1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator; + + return $this; + } + + protected function getV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator( + ): OptionsResolverDecoratorInterface + { + if (!$this->hasV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule StrReplace Builder OptionsResolverDecorator is not set.'); + } + + return $this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator; + } + + protected function hasV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator(): bool + { + return isset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator); + } + + protected function unsetV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator(): self + { + if (!$this->hasV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator()) { + throw new LogicException('Neighborhoods Buphalo V1 Actor Template Tokenizer Rule StrReplace Builder OptionsResolverDecorator is not set.'); + } + unset($this->NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleStrReplaceBuilderOptionsResolverDecorator); + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecoratorInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecoratorInterface.php new file mode 100644 index 00000000..5aaf76d9 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Builder/OptionsResolverDecoratorInterface.php @@ -0,0 +1,73 @@ +getV1ActorTemplateTokenizerRuleStrReplace(); + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/FactoryInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/FactoryInterface.php new file mode 100644 index 00000000..f17a6ad5 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/FactoryInterface.php @@ -0,0 +1,11 @@ +getV1ActorTemplateTokenizerRuleStrReplaceMapFactory()->create(); + foreach ($this->getInstructions() as $instruction) { + $ruleBuilder = $this->getV1ActorTemplateTokenizerRuleStrReplaceBuilderFactory()->create(); + $ruleBuilder->setOptions($instruction); + $ruleBuilder->setV1ActorTemplateTokenizerRuleContext($this->getV1ActorTemplateTokenizerRuleContext()); + $map->append($ruleBuilder->build()); + } + + return $map; + } + + protected function getInstructions(): array + { + if ($this->Instructions === null) { + throw new LogicException('Builder instructions has not been set.'); + } + + return $this->Instructions; + } + + public function addInstruction(array $instruction): BuilderInterface + { + if (count($instruction) !== 2) { + throw new InvalidArgumentException('Instruction does not have exactly two fields.'); + } + if (!array_key_exists(StrReplace\BuilderInterface::OPTION_SEARCH, $instruction)) { + throw new InvalidArgumentException( + sprintf( + 'Instruction does not contain a "%s" field.', + StrReplace\BuilderInterface::OPTION_SEARCH + ) + ); + } + if (!array_key_exists(StrReplace\BuilderInterface::OPTION_REPLACE, $instruction)) { + throw new InvalidArgumentException( + sprintf( + 'Instruction does not contain a "%s" field.', + StrReplace\BuilderInterface::OPTION_REPLACE + ) + ); + } + + $this->Instructions[] = $instruction; + + return $this; + } +} diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/Builder.service.yml b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/Builder.service.yml new file mode 100644 index 00000000..dc0a6900 --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/Builder.service.yml @@ -0,0 +1,19 @@ +services: + Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Map\BuilderInterface: + class: Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Map\Builder + public: false + shared: false + calls: + - [setV1ActorTemplateTokenizerRuleStrReplaceMapFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Map\FactoryInterface']] + - [setV1ActorTemplateTokenizerRuleStrReplaceBuilderFactory, ['@Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\StrReplace\Builder\FactoryInterface']] + - [addInstruction, [{ + search: "['@Neighborhoods\\BuphaloTemplateTree\\PrimaryActorName", + replace: "sprintf( + '[\\'@%%s%%s\\\\%%s', + TokenizerInterface::NAMESPACE_PREFIX_TOKEN, + TokenizerInterface::NAMESPACE_RELATIVE_TOKEN, + TokenizerInterface::PRIMARY_ACTOR_SHORT_PASCAL_CASE_NAME_TOKEN + )"}]] + - [addInstruction, [{ + search: "\\PrimaryActorName;", + replace: "sprintf('%%s;', TokenizerInterface::EMPTY_TOKEN)"}]] diff --git a/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/BuilderInterface.php b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/BuilderInterface.php new file mode 100644 index 00000000..81107e5d --- /dev/null +++ b/src/V1/Actor/Template/Tokenizer/Rule/StrReplace/Map/BuilderInterface.php @@ -0,0 +1,17 @@ +hasBuphalo()) { - throw new LogicException('Neighborhoods Buphalo Buphalo is already set.'); - } - $this->NeighborhoodsBuphaloBuphalo = $buphalo; - - return $this; - } - - protected function getBuphalo(): BuphaloInterface - { - if (!$this->hasBuphalo()) { - throw new LogicException('Neighborhoods Buphalo Buphalo is not set.'); - } - - return $this->NeighborhoodsBuphaloBuphalo; - } - - protected function hasBuphalo(): bool - { - return isset($this->NeighborhoodsBuphaloBuphalo); - } - - protected function unsetBuphalo(): self - { - if (!$this->hasBuphalo()) { - throw new LogicException('Neighborhoods Buphalo Buphalo is not set.'); - } - unset($this->NeighborhoodsBuphaloBuphalo); - - return $this; - } -} diff --git a/src/V1/Buphalo/Builder.php b/src/V1/Buphalo/Builder.php deleted file mode 100644 index 345b4034..00000000 --- a/src/V1/Buphalo/Builder.php +++ /dev/null @@ -1,16 +0,0 @@ -getBuphaloFactory()->create(); - } -} diff --git a/src/V1/Buphalo/Builder/AwareTrait.php b/src/V1/Buphalo/Builder/AwareTrait.php deleted file mode 100644 index ce433e35..00000000 --- a/src/V1/Buphalo/Builder/AwareTrait.php +++ /dev/null @@ -1,46 +0,0 @@ -hasBuphaloBuilder()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder is already set.'); - } - $this->NeighborhoodsBuphaloBuphaloBuilder = $buphaloBuilder; - - return $this; - } - - protected function getBuphaloBuilder(): BuilderInterface - { - if (!$this->hasBuphaloBuilder()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder is not set.'); - } - - return $this->NeighborhoodsBuphaloBuphaloBuilder; - } - - protected function hasBuphaloBuilder(): bool - { - return isset($this->NeighborhoodsBuphaloBuphaloBuilder); - } - - protected function unsetBuphaloBuilder(): self - { - if (!$this->hasBuphaloBuilder()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder is not set.'); - } - unset($this->NeighborhoodsBuphaloBuphaloBuilder); - - return $this; - } -} diff --git a/src/V1/Buphalo/Builder/Factory.php b/src/V1/Buphalo/Builder/Factory.php deleted file mode 100644 index 0da47fc6..00000000 --- a/src/V1/Buphalo/Builder/Factory.php +++ /dev/null @@ -1,16 +0,0 @@ -getBuphaloBuilder(); - } -} diff --git a/src/V1/Buphalo/Builder/Factory/AwareTrait.php b/src/V1/Buphalo/Builder/Factory/AwareTrait.php deleted file mode 100644 index bee9209b..00000000 --- a/src/V1/Buphalo/Builder/Factory/AwareTrait.php +++ /dev/null @@ -1,46 +0,0 @@ -hasBuphaloBuilderFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder Factory is already set.'); - } - $this->NeighborhoodsBuphaloBuphaloBuilderFactory = $buphaloBuilderFactory; - - return $this; - } - - protected function getBuphaloBuilderFactory(): FactoryInterface - { - if (!$this->hasBuphaloBuilderFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder Factory is not set.'); - } - - return $this->NeighborhoodsBuphaloBuphaloBuilderFactory; - } - - protected function hasBuphaloBuilderFactory(): bool - { - return isset($this->NeighborhoodsBuphaloBuphaloBuilderFactory); - } - - protected function unsetBuphaloBuilderFactory(): self - { - if (!$this->hasBuphaloBuilderFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Builder Factory is not set.'); - } - unset($this->NeighborhoodsBuphaloBuphaloBuilderFactory); - - return $this; - } -} diff --git a/src/V1/Buphalo/Builder/FactoryInterface.php b/src/V1/Buphalo/Builder/FactoryInterface.php deleted file mode 100644 index 371cc3d7..00000000 --- a/src/V1/Buphalo/Builder/FactoryInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -getBuphalo(); - } -} diff --git a/src/V1/Buphalo/Factory/AwareTrait.php b/src/V1/Buphalo/Factory/AwareTrait.php deleted file mode 100644 index 3c711c8b..00000000 --- a/src/V1/Buphalo/Factory/AwareTrait.php +++ /dev/null @@ -1,46 +0,0 @@ -hasBuphaloFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Factory is already set.'); - } - $this->NeighborhoodsBuphaloBuphaloFactory = $buphaloFactory; - - return $this; - } - - protected function getBuphaloFactory(): FactoryInterface - { - if (!$this->hasBuphaloFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Factory is not set.'); - } - - return $this->NeighborhoodsBuphaloBuphaloFactory; - } - - protected function hasBuphaloFactory(): bool - { - return isset($this->NeighborhoodsBuphaloBuphaloFactory); - } - - protected function unsetBuphaloFactory(): self - { - if (!$this->hasBuphaloFactory()) { - throw new LogicException('Neighborhoods Buphalo Buphalo Factory is not set.'); - } - unset($this->NeighborhoodsBuphaloBuphaloFactory); - - return $this; - } -} diff --git a/src/V1/Buphalo/FactoryInterface.php b/src/V1/Buphalo/FactoryInterface.php deleted file mode 100644 index 5d2a7a66..00000000 --- a/src/V1/Buphalo/FactoryInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -.service.yml: + template: PrimaryActorName.service.yml + /AwareTrait.php: + template: PrimaryActorName/AwareTrait.php diff --git a/src/V1/Symfony/Component/OptionsResolver/OptionsResolver.service.yml b/src/V1/Symfony/Component/OptionsResolver/OptionsResolver.service.yml new file mode 100644 index 00000000..4a206314 --- /dev/null +++ b/src/V1/Symfony/Component/OptionsResolver/OptionsResolver.service.yml @@ -0,0 +1,5 @@ +services: + Symfony\Component\OptionsResolver\OptionsResolver: + class: Symfony\Component\OptionsResolver\OptionsResolver + public: false + shared: false diff --git a/src/V1/Symfony/Component/OptionsResolver/OptionsResolver/AwareTrait.php b/src/V1/Symfony/Component/OptionsResolver/OptionsResolver/AwareTrait.php new file mode 100644 index 00000000..dd8d4717 --- /dev/null +++ b/src/V1/Symfony/Component/OptionsResolver/OptionsResolver/AwareTrait.php @@ -0,0 +1,46 @@ +hasV1SymfonyComponentOptionsResolverOptionsResolver()) { + throw new LogicException('V1SymfonyComponentOptionsResolverOptionsResolver is already set.'); + } + $this->V1SymfonyComponentOptionsResolverOptionsResolver = $OptionsResolver; + + return $this; + } + + protected function getV1SymfonyComponentOptionsResolverOptionsResolver(): OptionsResolver + { + if (!$this->hasV1SymfonyComponentOptionsResolverOptionsResolver()) { + throw new LogicException('V1SymfonyComponentOptionsResolverOptionsResolver is not set.'); + } + + return $this->V1SymfonyComponentOptionsResolverOptionsResolver; + } + + protected function hasV1SymfonyComponentOptionsResolverOptionsResolver(): bool + { + return isset($this->V1SymfonyComponentOptionsResolverOptionsResolver); + } + + protected function unsetV1SymfonyComponentOptionsResolverOptionsResolver(): self + { + if (!$this->hasV1SymfonyComponentOptionsResolverOptionsResolver()) { + throw new LogicException('V1SymfonyComponentOptionsResolverOptionsResolver is not set.'); + } + unset($this->V1SymfonyComponentOptionsResolverOptionsResolver); + + return $this; + } +}