Skip to content

Commit

Permalink
Added interface for #315
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Aug 15, 2018
1 parent fdda59c commit cb980bc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Modules/Generators/ContentGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tapestry\Modules\Generators;

use Tapestry\Entities\Generators\FileGenerator;
use Tapestry\Entities\Project;
use Tapestry\Modules\Source\AbstractSource;

Expand All @@ -19,7 +18,7 @@ class ContentGeneratorFactory
/**
* Registered item stack.
*
* @var array|FileGenerator[]
* @var string[]
*/
private $items = [];

Expand Down Expand Up @@ -62,9 +61,9 @@ public function add(string $class)
*
* @param string $name
* @param AbstractSource $file
* @return FileGenerator
* @return GeneratorInterface
*/
public function get(string $name, AbstractSource $file): FileGenerator
public function get(string $name, AbstractSource $file): GeneratorInterface
{
// @todo register new FileGenerator with the graph for #315
return new $this->items[$name]($file);
Expand Down
34 changes: 34 additions & 0 deletions src/Modules/Generators/GeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tapestry\Modules\Generators;

use Tapestry\Entities\Project;
use Tapestry\Modules\Source\SourceInterface;

/**
* Interface GeneratorInterface
*
* Each Generator should implement this basic interface and
* regardless of whether they generate one file or many
* the generate method should always return an array.
*/
interface GeneratorInterface
{
/**
* Set the source that this generator works from.
*
* @param SourceInterface $source
* @return void
*/
public function setSource(SourceInterface $source);

/**
* Run the generation and return an array of generated
* files (oddly implementing SourceInterface, naming
* things is hard!)
*
* @param Project $project
* @return array|SourceInterface[]
*/
public function generate(Project $project): array;
}

0 comments on commit cb980bc

Please sign in to comment.