Browse Source

Move cfnpp stuff into its own namespace

master
Adam Pippin 3 years ago
parent
commit
1bb3e50cfb
  1. 2
      app/Commands/Stack/Compile.php
  2. 14
      app/Engine/Cfnpp/Compiler.php
  3. 14
      app/Engine/Cfnpp/Functions.php
  4. 6
      app/Engine/Cfnpp/Options.php

2
app/Commands/Stack/Compile.php

@ -40,7 +40,7 @@ class Compile extends Command
$serializer = $this->getSerializer(); $serializer = $this->getSerializer();
$unserializer = $this->getUnserializer(); $unserializer = $this->getUnserializer();
$options = null; $options = null;
$engine->setSerializer($serializer)->setUnserializer($unserializer)->setCompiler(new \App\Engine\Cfnpp($options = new \App\Engine\CfnppOptions())); $engine->setSerializer($serializer)->setUnserializer($unserializer)->setCompiler(new \App\Engine\Cfnpp\Compiler($options = new \App\Engine\Cfnpp\Options()));
$output = $engine->process($this->argument('in_file'), $options); $output = $engine->process($this->argument('in_file'), $options);

14
app/Engine/Cfnpp.php → app/Engine/Cfnpp/Compiler.php

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Engine; namespace App\Engine\Cfnpp;
use App\Dom\Document; use App\Dom\Document;
use App\Dom\Node; use App\Dom\Node;
@ -14,7 +14,7 @@ use App\Dom\NodeFunction;
* *
* @author Adam Pippin <hello@adampippin.ca> * @author Adam Pippin <hello@adampippin.ca>
*/ */
class Cfnpp implements ICompile class Compiler implements \App\Engine\ICompile
{ {
/** /**
* Functions that can be called by the document. * Functions that can be called by the document.
@ -67,14 +67,14 @@ class Cfnpp implements ICompile
* Compile a set of documents and return the result. * Compile a set of documents and return the result.
* *
* @param Document[] $documents * @param Document[] $documents
* @param IOptions $options * @param \App\Engine\IOptions $options
* @return void * @return void
*/ */
public function compile(array $documents, IOptions $options): Document public function compile(array $documents, \App\Engine\IOptions $options): Document
{ {
if (!($options instanceof CfnppOptions)) if (!($options instanceof Options))
{ {
throw new \Exception('Cfnpp compiler requires CfnppOptions'); throw new \Exception('Cfnpp\Compiler requires Cfnpp\Options');
} }
// Initialize state // Initialize state
@ -83,7 +83,7 @@ class Cfnpp implements ICompile
$this->merge_functions = []; $this->merge_functions = [];
// Register built-in functions // Register built-in functions
$cfnpp_functions = new CfnppFunctions($this, $options); $cfnpp_functions = new Functions($this, $options);
$cfnpp_functions->register($this); $cfnpp_functions->register($this);
// Process each passed document // Process each passed document

14
app/Engine/CfnppFunctions.php → app/Engine/Cfnpp/Functions.php

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Engine; namespace App\Engine\Cfnpp;
use App\Dom\Node; use App\Dom\Node;
use App\Dom\NodeValue; use App\Dom\NodeValue;
@ -14,21 +14,21 @@ use App\Dom\NodeFunctionValue;
* *
* @author Adam Pippin <hello@adampippin.ca> * @author Adam Pippin <hello@adampippin.ca>
*/ */
class CfnppFunctions class Functions
{ {
/** /**
* cfnpp compiler. * cfnpp compiler.
* @var Cfnpp * @var Compiler
*/ */
protected $compiler; protected $compiler;
/** /**
* cfnpp compiler options, stores state. * cfnpp compiler options, stores state.
* @var CfnppOptions * @var Options
*/ */
protected $options; protected $options;
public function __construct(Cfnpp $compiler, CfnppOptions $options) public function __construct(Compiler $compiler, Options $options)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->options = $options; $this->options = $options;
@ -38,10 +38,10 @@ class CfnppFunctions
* Examines this class with reflection and registers all functions on a cfnpp * Examines this class with reflection and registers all functions on a cfnpp
* compiler instance. * compiler instance.
* *
* @param Cfnpp $compiler * @param Compiler $compiler
* @return void * @return void
*/ */
public function register(Cfnpp $compiler): void public function register(Compiler $compiler): void
{ {
$reflection = new \ReflectionClass(static::class); $reflection = new \ReflectionClass(static::class);
$methods = $reflection->getMethods(); $methods = $reflection->getMethods();

6
app/Engine/CfnppOptions.php → app/Engine/Cfnpp/Options.php

@ -2,14 +2,16 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Engine; namespace App\Engine\Cfnpp;
use \App\Engine\IOptions;
/** /**
* Options for controlling the Cfnpp compilation process. * Options for controlling the Cfnpp compilation process.
* *
* @author Adam Pippin <hello@adampippin.ca> * @author Adam Pippin <hello@adampippin.ca>
*/ */
class CfnppOptions implements IOptions class Options implements \App\Engine\IOptions
{ {
/** /**
* Store variables for use in templates. * Store variables for use in templates.
Loading…
Cancel
Save