Skip to content

Commit

Permalink
Merge pull request #73 from neighborhoods/BUPH-75-fully-qualified-tra…
Browse files Browse the repository at this point in the history
…its-1x

BUPH-75 | Support Fully Qualified Traits [1.x]
  • Loading branch information
jpmarcotte authored Nov 19, 2021
2 parents 37811d8 + 6c2e0b2 commit e02e3d8
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/V1/Actor/Template/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public function getTokenizedContents(): string
/** @noinspection CascadeStringReplacementInspection */
/** @noinspection NotOptimalRegularExpressionsInspection */
$tokenizedContents = preg_replace(
'/use(\s+)Neighborhoods\\\BuphaloTemplateTree\\\PrimaryActorName/',
'/use\\s+(\\\\?)Neighborhoods\\\\BuphaloTemplateTree\\\\PrimaryActorName/',
sprintf(
'use %s%s\\%s',
'use \\1%s%s\\%s',
TokenizerInterface::NAMESPACE_PREFIX_TOKEN,
TokenizerInterface::NAMESPACE_RELATIVE_TOKEN,
TokenizerInterface::PRIMARY_ACTOR_SHORT_PASCAL_CASE_NAME_TOKEN
),
$tokenizedContents
);
$tokenizedContents = preg_replace(
'/use(\s+)Neighborhoods\\\BuphaloTemplateTree/',
'/use\\s+(\\\\?)Neighborhoods\\\\BuphaloTemplateTree/',
sprintf(
'use %s',
'use \\1%s',
TokenizerInterface::NAMESPACE_PREFIX_TOKEN
),
$tokenizedContents
Expand Down
1 change: 1 addition & 0 deletions tests/v1/FullyQualifiedTraits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fab/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest\Fully\QualifiedTrait;

class Handler implements HandlerInterface
{
use \Neighborhoods\BuphaloTest\NonPrimaryActor\AwareTrait;
use \Neighborhoods\BuphaloTest\Fully\QualifiedTrait\Map\Repository\AwareTrait;
}
37 changes: 37 additions & 0 deletions tests/v1/FullyQualifiedTraits/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
error_reporting(E_ALL);

$PWD = __DIR__;

// Must load autoloader before including any Annotation Processors
if (file_exists($autoloaderFilePath = dirname($PWD, 5) . '/autoload.php')) {
/** @noinspection PhpIncludeInspection */
require_once $autoloaderFilePath;
} elseif (file_exists($autoloaderFilePath = dirname($PWD, 3) . '/vendor/autoload.php')) {
/** @noinspection PhpIncludeInspection */
require_once $autoloaderFilePath;
} else {
throw new RuntimeException('Unable to find the Composer autoloader.');
}

// Include Annotation Processors for Buphalo
// None for this test

// Add exec envs
putenv("Neighborhoods_Buphalo_V1_TargetApplication_BuilderInterface__SourceDirectoryPath=$PWD/src");
putenv("Neighborhoods_Buphalo_V1_TargetApplication_BuilderInterface__FabricationDirectoryPath=$PWD/fab");
putenv("Neighborhoods_Buphalo_V1_TargetApplication_BuilderInterface__NamespacePrefix=Neighborhoods\\BuphaloTest");
putenv("Neighborhoods_Buphalo_V1_TemplateTree_Map_Builder_FactoryInterface__TemplateTreeDirectoryPaths=$PWD/templates");

// Include Buphalo
require_once($PWD . '/../../../bin/v1/buphalo.php');

// Diff the two directories
exec("diff -r $PWD/control/ $PWD/fab/", $output, $return);

if ($return) {
echo(implode(PHP_EOL, $output) . PHP_EOL);
die(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actors:
<PrimaryActorName>/Handler.php:
template: PrimaryActorName/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\PrimaryActorName;

class Handler implements HandlerInterface
{
use \Neighborhoods\BuphaloTemplateTree\NonPrimaryActor\AwareTrait;
use \Neighborhoods\BuphaloTemplateTree\PrimaryActorName\Map\Repository\AwareTrait;
}

0 comments on commit e02e3d8

Please sign in to comment.