Skip to content

Commit

Permalink
Merge pull request #80 from neighborhoods/BUPH-145-shared-templates
Browse files Browse the repository at this point in the history
BUPH-145 | Shared Templates
  • Loading branch information
jpmarcotte committed Jun 21, 2022
2 parents b56c73a + 5c92eb3 commit 0437301
Show file tree
Hide file tree
Showing 74 changed files with 1,937 additions and 10 deletions.
77 changes: 70 additions & 7 deletions src/V2/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class Actor implements ActorInterface
protected $NamespacePrefix;
protected $NamespaceRelative;
protected $RelativeClassPath;
protected $ParentRelativeClassPath;
protected $ParentActorRelativeClassPath;
protected $ParentActorFullPascalCaseName;
protected $ParentActorRelativePascalCaseName;
protected $ParentActorShortPascalCaseName;
protected $PrimaryActorFullPascalCaseName;
protected $PrimaryActorShortPascalCaseName;
protected $FullPascalCaseName;
Expand All @@ -22,22 +25,82 @@ class Actor implements ActorInterface
protected $FileName;
protected $FileExtension;

public function getParentRelativeClassPath(): string
public function getParentActorRelativeClassPath(): string
{
if ($this->ParentRelativeClassPath === null) {
if ($this->ParentActorRelativeClassPath === null) {
throw new LogicException('Parent Relative Class Path has not been set.');
}

return $this->ParentRelativeClassPath;
return $this->ParentActorRelativeClassPath;
}

public function setParentRelativeClassPath(string $ParentRelativeClassPath): ActorInterface
public function setParentActorRelativeClassPath(string $ParentActorRelativeClassPath): ActorInterface
{
if ($this->ParentRelativeClassPath !== null) {
if ($this->ParentActorRelativeClassPath !== null) {
throw new LogicException('Parent Relative Class Path is already set.');
}

$this->ParentRelativeClassPath = $ParentRelativeClassPath;
$this->ParentActorRelativeClassPath = $ParentActorRelativeClassPath;

return $this;
}

public function getParentActorFullPascalCaseName(): string
{
if ($this->ParentActorFullPascalCaseName === null) {
throw new LogicException('Parent Actor Full Pascal Case Name has not been set.');
}

return $this->ParentActorFullPascalCaseName;
}

public function setParentActorFullPascalCaseName(string $ParentActorFullPascalCaseName): ActorInterface
{
if ($this->ParentActorFullPascalCaseName !== null) {
throw new LogicException('Parent Actor Full Pascal Case Name is already set.');
}

$this->ParentActorFullPascalCaseName = $ParentActorFullPascalCaseName;

return $this;
}

public function getParentActorRelativePascalCaseName(): string
{
if ($this->ParentActorRelativePascalCaseName === null) {
throw new LogicException('Parent Actor Relative Pascal Case Name has not been set.');
}

return $this->ParentActorRelativePascalCaseName;
}

public function setParentActorRelativePascalCaseName(string $ParentActorRelativePascalCaseName): ActorInterface
{
if ($this->ParentActorRelativePascalCaseName !== null) {
throw new LogicException('Parent Actor Relative Pascal Case Name is already set.');
}

$this->ParentActorRelativePascalCaseName = $ParentActorRelativePascalCaseName;

return $this;
}

public function getParentActorShortPascalCaseName(): string
{
if ($this->ParentActorShortPascalCaseName === null) {
throw new LogicException('Parent Actor Short Pascal Case Name has not been set.');
}

return $this->ParentActorShortPascalCaseName;
}

public function setParentActorShortPascalCaseName(string $ParentActorFullPascalCaseName): ActorInterface
{
if ($this->ParentActorShortPascalCaseName !== null) {
throw new LogicException('Parent Actor Short Pascal Case Name is already set.');
}

$this->ParentActorShortPascalCaseName = $ParentActorFullPascalCaseName;

return $this;
}
Expand Down
45 changes: 44 additions & 1 deletion src/V2/Actor/Builder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neighborhoods\Buphalo\V2\Actor;
Expand All @@ -18,6 +19,9 @@ class Builder implements BuilderInterface
protected $NamespaceRelative;
protected $RelativeClassPath;
protected $ParentRelativeClassPath;
protected $ParentActorFullPascalCaseName;
protected $ParentActorRelativePascalCaseName;
protected $ParentActorShortPascalCaseName;
protected $PrimaryActorFullPascalCaseName;
protected $PrimaryActorShortPascalCaseName;
protected $FullPascalCaseName;
Expand All @@ -35,7 +39,10 @@ public function build(): ActorInterface
$actor->setNamespacePrefix($this->getNamespace());
$actor->setNamespaceRelative($this->getNamespaceRelative());
$actor->setRelativeClassPath($this->getRelativeClassPath());
$actor->setParentRelativeClassPath($this->getParentRelativeClassPath());
$actor->setParentActorRelativeClassPath($this->getParentRelativeClassPath());
$actor->setParentActorFullPascalCaseName($this->getParentActorFullPascalCaseName());
$actor->setParentActorRelativePascalCaseName($this->getParentActorRelativePascalCaseName());
$actor->setParentActorShortPascalCaseName($this->getParentActorShortPascalCaseName());
$actor->setPrimaryActorFullPascalCaseName($this->getPrimaryActorFullPascalCaseName());
$actor->setPrimaryActorShortPascalCaseName($this->getPrimaryActorShortPascalCaseName());
$actor->setFullPascalCaseName($this->getFullPascalCaseName());
Expand Down Expand Up @@ -63,6 +70,42 @@ protected function getParentRelativeClassPath(): string
return $this->ParentRelativeClassPath;
}

protected function getParentActorFullPascalCaseName(): string
{
if ($this->ParentActorFullPascalCaseName === null) {
$this->ParentActorFullPascalCaseName = str_replace(
'\\',
'',
$this->getNamespaceRelative() . $this->getParentRelativeClassPath()
);
}

return $this->ParentActorFullPascalCaseName;
}

protected function getParentActorRelativePascalCaseName(): string
{
if ($this->ParentActorRelativePascalCaseName === null) {
$this->ParentActorRelativePascalCaseName = str_replace(
'\\',
'',
$this->getParentRelativeClassPath()
);
}

return $this->ParentActorRelativePascalCaseName;
}

protected function getParentActorShortPascalCaseName(): string
{
if ($this->ParentActorShortPascalCaseName === null) {
$parts = explode('\\', $this->getParentRelativeClassPath());
$this->ParentActorShortPascalCaseName = array_pop($parts);
}

return $this->ParentActorShortPascalCaseName;
}

protected function getNamespace(): string
{
if ($this->NamespacePrefix === null) {
Expand Down
5 changes: 5 additions & 0 deletions src/V2/Actor/Template/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function getCompiledContents(): string
TokenizerInterface::TOKEN_PRIMARY_ACTOR_NAME_FULL_PASCAL => $actor->getPrimaryActorFullPascalCaseName(),
TokenizerInterface::TOKEN_PRIMARY_ACTOR_NAME_SHORT_PASCAL =>
$actor->getPrimaryActorShortPascalCaseName(),
TokenizerInterface::TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL => $actor->getParentActorFullPascalCaseName(),
TokenizerInterface::TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL =>
$actor->getParentActorRelativePascalCaseName(),
TokenizerInterface::TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL => $actor->getParentActorShortPascalCaseName(),
TokenizerInterface::TOKEN_PARENT_ACTOR_CLASS_PATH_RELATIVE => $actor->getParentActorRelativeClassPath(),
];

$compiledContents = str_replace(
Expand Down
4 changes: 4 additions & 0 deletions src/V2/Actor/Template/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Tokenizer implements TokenizerInterface
'\RelativeNamespace' => self::TOKEN_NAMESPACE_RELATIVE,
'NamespacedPrimaryActorName' => self::TOKEN_PRIMARY_ACTOR_NAME_FULL_PASCAL,
'PrimaryActorName' => self::TOKEN_PRIMARY_ACTOR_NAME_SHORT_PASCAL,
'NamespacedParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL,
'RelativeParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL,
'ParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL,
'RelativeParentActorClassPath' => self::TOKEN_PARENT_ACTOR_CLASS_PATH_RELATIVE,
];

protected $TokenizedContents;
Expand Down
4 changes: 4 additions & 0 deletions src/V2/Actor/Template/TokenizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface TokenizerInterface
public const TOKEN_NAMESPACE_RELATIVE = '**TOKEN_NAMESPACE_RELATIVE**';
public const TOKEN_PRIMARY_ACTOR_NAME_FULL_PASCAL = '**TOKEN_PRIMARY_ACTOR_NAME_FULL_PASCAL**';
public const TOKEN_PRIMARY_ACTOR_NAME_SHORT_PASCAL = '**TOKEN_PRIMARY_ACTOR_NAME_SHORT_PASCAL**';
public const TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL = '**TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL**';
public const TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL = '**TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL**';
public const TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL = '**TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL**';
public const TOKEN_PARENT_ACTOR_CLASS_PATH_RELATIVE = '**TOKEN_PARENT_ACTOR_CLASS_PATH_RELATIVE**';

public function getTokenizedContents(): string;

Expand Down
17 changes: 15 additions & 2 deletions src/V2/GenericActorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neighborhoods\Buphalo\V2;
Expand All @@ -7,7 +8,13 @@ interface GenericActorInterface
{
public function getRelativeClassPath(): string;

public function getParentRelativeClassPath(): string;
public function getParentActorRelativeClassPath(): string;

public function getParentActorFullPascalCaseName(): string;

public function getParentActorRelativePascalCaseName(): string;

public function getParentActorShortPascalCaseName(): string;

public function getNamespacePrefix(): string;

Expand All @@ -31,7 +38,13 @@ public function setShortPascalCaseName(string $ShortPascalCaseName): ActorInterf

public function setNamespacePrefix(string $NamespacePrefix): ActorInterface;

public function setParentRelativeClassPath(string $ParentRelativeClassPath): ActorInterface;
public function setParentActorRelativeClassPath(string $ParentRelativeClassPath): ActorInterface;

public function setParentActorFullPascalCaseName(string $ParentActorFullPascalCaseName): ActorInterface;

public function setParentActorRelativePascalCaseName(string $ParentActorRelativePascalCaseName): ActorInterface;

public function setParentActorShortPascalCaseName(string $ParentActorShortPascalCaseName): ActorInterface;

public function setSourceDirectoryPath(string $SourceDirectoryPath): ActorInterface;

Expand Down
1 change: 1 addition & 0 deletions tests/v2/SharedTemplates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fab/*
76 changes: 76 additions & 0 deletions tests/v2/SharedTemplates/control/DOR/Version/Car.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest\SharedTemplates\DOR\Version;

class Car implements CarInterface
{
/** @var int */
private $year;

/** @var string */
private $make;

/** @var string */
private $model;

public function getYear(): int
{
if ($this->year === null) {
throw new \LogicException('year has not been set');
}

return $this->year;
}

public function setYear(int $year): CarInterface
{
if ($this->year !== null) {
throw new \LogicException('year has already been set');
}

$this->year = $year;

return $this;
}

public function getMake(): string
{
if ($this->make === null) {
throw new \LogicException('make has not been set');
}

return $this->make;
}

public function setMake(string $make): CarInterface
{
if ($this->make !== null) {
throw new \LogicException('make has already been set');
}

$this->make = $make;

return $this;
}

public function getModel(): string
{
if ($this->model === null) {
throw new \LogicException('model has not been set');
}

return $this->model;
}

public function setModel(string $model): CarInterface
{
if ($this->model !== null) {
throw new \LogicException('model has already been set');
}

$this->model = $model;

return $this;
}
}
5 changes: 5 additions & 0 deletions tests/v2/SharedTemplates/control/DOR/Version/Car.service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
Neighborhoods\BuphaloTest\SharedTemplates\DOR\Version\CarInterface:
class: Neighborhoods\BuphaloTest\SharedTemplates\DOR\Version\Car
public: false
shared: false
46 changes: 46 additions & 0 deletions tests/v2/SharedTemplates/control/DOR/Version/Car/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest\SharedTemplates\DOR\Version\Car;

use LogicException;
use Neighborhoods\BuphaloTest\SharedTemplates\DOR\Version\CarInterface;

trait AwareTrait
{
protected $DORVersionCar;

public function setDORVersionCar(CarInterface $Car): self
{
if ($this->hasDORVersionCar()) {
throw new LogicException('DORVersionCar is already set.');
}
$this->DORVersionCar = $Car;

return $this;
}

protected function getDORVersionCar(): CarInterface
{
if (!$this->hasDORVersionCar()) {
throw new LogicException('DORVersionCar is not set.');
}

return $this->DORVersionCar;
}

protected function hasDORVersionCar(): bool
{
return isset($this->DORVersionCar);
}

protected function unsetDORVersionCar(): self
{
if (!$this->hasDORVersionCar()) {
throw new LogicException('DORVersionCar is not set.');
}
unset($this->DORVersionCar);

return $this;
}
}
Loading

0 comments on commit 0437301

Please sign in to comment.