-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move tokenizer rules to di #56
base: master
Are you sure you want to change the base?
Changes from all commits
c05f337
c4fe83e
3eda622
a44e705
07c3ca9
0e7b856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no-op continue?
Suggested change
|
||||
} | ||||
|
||||
/** @noinspection NotOptimalRegularExpressionsInspection */ | ||||
$tokenizedContents = preg_replace( | ||||
'/namespace(\s+)Neighborhoods\\\BuphaloTemplateTree\\\PrimaryActorName/', | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
actors: | ||
<PrimaryActorName>Interface.php: | ||
template: PrimaryActorNameInterface.php | ||
<PrimaryActorName>/AwareTrait.php: | ||
template: PrimaryActorName/AwareTrait.php | ||
<PrimaryActorName>/FactoryInterface.php: | ||
template: PrimaryActorName/FactoryInterface.php | ||
<PrimaryActorName>/Factory/AwareTrait.php: | ||
template: PrimaryActorName/Factory/AwareTrait.php | ||
<PrimaryActorName>/BuilderInterface.php: | ||
template: PrimaryActorName/BuilderInterface.php | ||
<PrimaryActorName>/Builder/AwareTrait.php: | ||
template: PrimaryActorName/Builder/AwareTrait.php | ||
<PrimaryActorName>/Builder/FactoryInterface.php: | ||
template: PrimaryActorName/Builder/FactoryInterface.php | ||
<PrimaryActorName>/Builder/Factory/AwareTrait.php: | ||
template: PrimaryActorName/Builder/Factory/AwareTrait.php | ||
<PrimaryActorName>/Repository.php: | ||
template: PrimaryActorName/Repository.php | ||
<PrimaryActorName>/Repository.service.yml: | ||
template: PrimaryActorName/Repository.service.yml | ||
<PrimaryActorName>/RepositoryInterface.php: | ||
template: PrimaryActorName/RepositoryInterface.php | ||
<PrimaryActorName>/Repository/AwareTrait.php: | ||
template: PrimaryActorName/Repository/AwareTrait.php | ||
<PrimaryActorName>/Map.php: | ||
template: PrimaryActorName/Map.php | ||
<PrimaryActorName>/Map.service.yml: | ||
template: PrimaryActorName/Map.service.yml | ||
<PrimaryActorName>/MapInterface.php: | ||
template: PrimaryActorName/MapInterface.php | ||
<PrimaryActorName>/Map/AwareTrait.php: | ||
template: PrimaryActorName/Map/AwareTrait.php | ||
<PrimaryActorName>/Map/Factory.php: | ||
template: PrimaryActorName/Map/Factory.php | ||
<PrimaryActorName>/Map/Factory.service.yml: | ||
template: PrimaryActorName/Map/Factory.service.yml | ||
<PrimaryActorName>/Map/FactoryInterface.php: | ||
template: PrimaryActorName/Map/FactoryInterface.php | ||
<PrimaryActorName>/Map/Factory/AwareTrait.php: | ||
template: PrimaryActorName/Map/Factory/AwareTrait.php | ||
<PrimaryActorName>/Map/Builder.php: | ||
template: PrimaryActorName/Map/Builder.php | ||
<PrimaryActorName>/Map/Builder.service.yml: | ||
template: PrimaryActorName/Map/Builder.service.yml | ||
<PrimaryActorName>/Map/BuilderInterface.php: | ||
template: PrimaryActorName/Map/BuilderInterface.php | ||
<PrimaryActorName>/Map/Builder/AwareTrait.php: | ||
template: PrimaryActorName/Map/Builder/AwareTrait.php | ||
<PrimaryActorName>/Map/Builder/Factory.php: | ||
template: PrimaryActorName/Map/Builder/Factory.php | ||
<PrimaryActorName>/Map/Builder/Factory.service.yml: | ||
template: PrimaryActorName/Map/Builder/Factory.service.yml | ||
<PrimaryActorName>/Map/Builder/FactoryInterface.php: | ||
template: PrimaryActorName/Map/Builder/FactoryInterface.php | ||
<PrimaryActorName>/Map/Builder/Factory/AwareTrait.php: | ||
template: PrimaryActorName/Map/Builder/Factory/AwareTrait.php |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note-to-self: We should probably move a bunch of stuff like this into a committed |
||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder; | ||
|
||
use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\BuilderInterface; | ||
|
||
class Map extends \ArrayIterator implements MapInterface | ||
{ | ||
/** @param BuilderInterface ...$builders */ | ||
public function __construct(array $builders = array(), int $flags = 0) | ||
{ | ||
if ($this->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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map; | ||
|
||
use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\MapInterface; | ||
|
||
trait AwareTrait | ||
{ | ||
protected $NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMap; | ||
|
||
public function setV1ActorTemplateTokenizerRuleBuilderMap(MapInterface $v1ActorTemplateTokenizerRuleBuilderMap | ||
): self { | ||
if ($this->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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map; | ||
|
||
use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\MapInterface; | ||
|
||
class Factory implements FactoryInterface | ||
{ | ||
use AwareTrait; | ||
|
||
public function create(): MapInterface | ||
{ | ||
return $this->getV1ActorTemplateTokenizerRuleBuilderMap()->getArrayCopy(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\Factory; | ||
|
||
use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map\FactoryInterface; | ||
|
||
trait AwareTrait | ||
{ | ||
protected $NeighborhoodsBuphaloV1ActorTemplateTokenizerRuleBuilderMapFactory; | ||
|
||
public function setV1ActorTemplateTokenizerRuleBuilderMapFactory( | ||
FactoryInterface $v1ActorTemplateTokenizerRuleBuilderMapFactory | ||
): self { | ||
if ($this->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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\Map; | ||
|
||
use Neighborhoods\Buphalo\V1\Actor\Template\Tokenizer\Rule\Builder\MapInterface; | ||
|
||
interface FactoryInterface | ||
{ | ||
public function create(): MapInterface; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this pass in the current file extension?