Skip to content

Commit

Permalink
Merge pull request #82 from neighborhoods/BUPH-146-support-ignoring-src
Browse files Browse the repository at this point in the history
BUPH-146 | support ignoring whether files already exist in SourceDirectoryPath
  • Loading branch information
jpmarcotte committed Jun 29, 2022
2 parents 423ad19 + a40ce0f commit 465218d
Show file tree
Hide file tree
Showing 32 changed files with 369 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/V2/Actor/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class Writer implements WriterInterface
use Actor\Template\Compiler\AwareTrait;

protected $filesystem;
protected $ignore_source_directory_files;

public function write(): WriterInterface
{
$actor = $this->getActorTemplateCompiler()->getActorTemplateTokenizer()->getActor();
if (!is_file($actor->getSourceFilePath())) {
if ($this->getIgnoreSourceDirectoryFiles() || !is_file($actor->getSourceFilePath())) {
$fabricationFilePath = $actor->getFabricationFilePath();
$this->getFilesystem()->mkdir(dirname($fabricationFilePath));
if (is_file($fabricationFilePath)) {
Expand Down Expand Up @@ -51,4 +52,24 @@ public function setFilesystem(Filesystem $filesystem): WriterInterface

return $this;
}

protected function getIgnoreSourceDirectoryFiles(): bool
{
if ($this->ignore_source_directory_files === null) {
throw new LogicException('Writer ignore_source_directory_files has not been set.');
}

return $this->ignore_source_directory_files;
}

public function setIgnoreSourceDirectoryFiles(bool $ignoreSourceDirectoryFiles)
{
if ($this->ignore_source_directory_files !== null) {
throw new \LogicException('Writer ignore_source_directory_files is already set.');
}

$this->ignore_source_directory_files = $ignoreSourceDirectoryFiles;

return $this;
}
}
4 changes: 4 additions & 0 deletions src/V2/Actor/Writer.service.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
parameters:
Neighborhoods_Buphalo_V2_Actor_WriterInterface_IgnoreSourceDirectoryFilesDefault: false
Neighborhoods\Buphalo\V2\Actor\WriterInterface.IgnoreSourceDirectoryFiles: '%env(bool:default:Neighborhoods_Buphalo_V2_Actor_WriterInterface_IgnoreSourceDirectoryFilesDefault:Neighborhoods_Buphalo_V2_Actor_WriterInterface__IgnoreSourceDirectoryFiles)%'
services:
Neighborhoods\Buphalo\V2\Actor\WriterInterface:
class: Neighborhoods\Buphalo\V2\Actor\Writer
public: false
shared: false
calls:
- [setFilesystem, ['@Symfony\Component\Filesystem\Filesystem']]
- [setIgnoreSourceDirectoryFiles, ['%Neighborhoods\Buphalo\V2\Actor\WriterInterface.IgnoreSourceDirectoryFiles%']]
1 change: 1 addition & 0 deletions src/V2/Actor/WriterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
interface WriterInterface
{
public function setActorTemplateCompiler(CompilerInterface $Compiler);
public function setIgnoreSourceDirectoryFiles(bool $ignoreSourceDirectoryFiles);

public function write(): WriterInterface;
}
1 change: 1 addition & 0 deletions tests/v2/IgnoreSourceDirectoryFilesEmpty/.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;

interface IgnoringFilesInterface
{

// TODO: Implement accessors.
}
35 changes: 35 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesEmpty/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.');
}

// Add exec envs
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__SourceDirectoryPath=$PWD/src");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__FabricationDirectoryPath=$PWD/fab");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__NamespacePrefix=Neighborhoods\\BuphaloTest");
putenv("Neighborhoods_Buphalo_V2_TemplateTree_Map_Builder_FactoryInterface__TemplateTreeDirectoryPaths=$PWD/templates");
putenv("Neighborhoods_Buphalo_V2_Actor_WriterInterface__IgnoreSourceDirectoryFiles=");

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

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

if ($return > 0) {
echo(implode(PHP_EOL, $output) . PHP_EOL);
die(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actors:
<PrimaryActorName>.php:
template: PrimaryActorName.php
<PrimaryActorName>Interface.php:
template: PrimaryActorNameInterface.php
10 changes: 10 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesEmpty/src/IgnoringFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest;

class IgnoringFiles implements IgnoringFilesInterface
{

// TODO: Implement properties, and accessors.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

class PrimaryActorName implements PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoPropertiesAndAccessors
// TODO: Implement properties, and accessors.
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

interface PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoAccessors
// TODO: Implement accessors.
*/
}
1 change: 1 addition & 0 deletions tests/v2/IgnoreSourceDirectoryFilesFalse/.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;

interface IgnoringFilesInterface
{

// TODO: Implement accessors.
}
35 changes: 35 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesFalse/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.');
}

// Add exec envs
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__SourceDirectoryPath=$PWD/src");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__FabricationDirectoryPath=$PWD/fab");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__NamespacePrefix=Neighborhoods\\BuphaloTest");
putenv("Neighborhoods_Buphalo_V2_TemplateTree_Map_Builder_FactoryInterface__TemplateTreeDirectoryPaths=$PWD/templates");
putenv("Neighborhoods_Buphalo_V2_Actor_WriterInterface__IgnoreSourceDirectoryFiles=false");

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

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

if ($return > 0) {
echo(implode(PHP_EOL, $output) . PHP_EOL);
die(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actors:
<PrimaryActorName>.php:
template: PrimaryActorName.php
<PrimaryActorName>Interface.php:
template: PrimaryActorNameInterface.php
10 changes: 10 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesFalse/src/IgnoringFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest;

class IgnoringFiles implements IgnoringFilesInterface
{

// TODO: Implement properties, and accessors.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

class PrimaryActorName implements PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoPropertiesAndAccessors
// TODO: Implement properties, and accessors.
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

interface PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoAccessors
// TODO: Implement accessors.
*/
}
1 change: 1 addition & 0 deletions tests/v2/IgnoreSourceDirectoryFilesMissing/.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;

interface IgnoringFilesInterface
{

// TODO: Implement accessors.
}
35 changes: 35 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesMissing/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.');
}

// Add exec envs
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__SourceDirectoryPath=$PWD/src");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__FabricationDirectoryPath=$PWD/fab");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__NamespacePrefix=Neighborhoods\\BuphaloTest");
putenv("Neighborhoods_Buphalo_V2_TemplateTree_Map_Builder_FactoryInterface__TemplateTreeDirectoryPaths=$PWD/templates");
//putenv("Neighborhoods_Buphalo_V2_Actor_WriterInterface__IgnoreSourceDirectoryFiles=true");

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

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

if ($return > 0) {
echo(implode(PHP_EOL, $output) . PHP_EOL);
die(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actors:
<PrimaryActorName>.php:
template: PrimaryActorName.php
<PrimaryActorName>Interface.php:
template: PrimaryActorNameInterface.php
10 changes: 10 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesMissing/src/IgnoringFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest;

class IgnoringFiles implements IgnoringFilesInterface
{

// TODO: Implement properties, and accessors.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

class PrimaryActorName implements PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoPropertiesAndAccessors
// TODO: Implement properties, and accessors.
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTemplateTree\RelativeNamespace;

interface PrimaryActorNameInterface
{
/** @neighborhoods-buphalo:annotation-processor DaoAccessors
// TODO: Implement accessors.
*/
}
1 change: 1 addition & 0 deletions tests/v2/IgnoreSourceDirectoryFilesTrue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fab/*
10 changes: 10 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesTrue/control/IgnoringFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest;

class IgnoringFiles implements IgnoringFilesInterface
{

// TODO: Implement properties, and accessors.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\BuphaloTest;

interface IgnoringFilesInterface
{

// TODO: Implement accessors.
}
35 changes: 35 additions & 0 deletions tests/v2/IgnoreSourceDirectoryFilesTrue/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.');
}

// Add exec envs
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__SourceDirectoryPath=$PWD/src");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__FabricationDirectoryPath=$PWD/fab");
putenv("Neighborhoods_Buphalo_V2_TargetApplication_BuilderInterface__NamespacePrefix=Neighborhoods\\BuphaloTest");
putenv("Neighborhoods_Buphalo_V2_TemplateTree_Map_Builder_FactoryInterface__TemplateTreeDirectoryPaths=$PWD/templates");
putenv("Neighborhoods_Buphalo_V2_Actor_WriterInterface__IgnoreSourceDirectoryFiles=true");

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

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

if ($return > 0) {
echo(implode(PHP_EOL, $output) . PHP_EOL);
die(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actors:
<PrimaryActorName>.php:
template: PrimaryActorName.php
<PrimaryActorName>Interface.php:
template: PrimaryActorNameInterface.php
Loading

0 comments on commit 465218d

Please sign in to comment.