Browse Source

Flesh out engine + compile interface, add no-op compiler

master
Adam Pippin 3 years ago
parent
commit
042478a27a
  1. 28
      app/Engine/Cfnpp.php
  2. 36
      app/Engine/Engine.php
  3. 22
      app/Engine/ICompile.php

28
app/Engine/Cfnpp.php

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace App\Engine;
use App\Dom\Document;
class Cfnpp implements ICompile
{
/** @var Document */
protected $document;
public function setDocument(Document $document): void
{
$this->document = $document;
}
public function compile(Document $document, IOptions $options): void
{
// noop
}
public function getDocument(): Document
{
return $this->document;
}
}

36
app/Engine/Engine.php

@ -20,6 +20,9 @@ class Engine
/** @var \App\Serialize\IUnserialize */
protected $unserialize;
/** @var \App\Dom\Document */
protected $document;
public function setCompiler(ICompile $compiler): Engine
{
$this->compile = $compiler;
@ -38,15 +41,40 @@ class Engine
return $this;
}
public function compile(string $document_string, IOptions $options): string
public function setInputDocument(\App\Dom\Document $document): Engine
{
$this->document = $document;
$this->compile->setDocument($document);
return $this;
}
public function setInput(string $document_string): Engine
{
$document = $this->unserialize->unserialize($document_string);
$document = $this->compile->compile($document, $options);
return $this->serialize->serialize($document);
$this->setInputDocument($document);
return $this;
}
public function compileDocument(\App\Dom\Document $document, IOptions $options): \App\Dom\Document
public function compile(string $document_string, IOptions $options): Engine
{
$document = $this->unserialize->unserialize($document_string);
$this->compileDocument($document, $options);
return $this;
}
public function compileDocument(\App\Dom\Document $document, IOptions $options): Engine
{
return $this->compile->compile($document, $options);
}
public function getOutputDocument(): \App\Dom\Document
{
return $this->compile->getDocument();
}
public function getOutput(): string
{
$document = $this->getOutputDocument();
return $this->serialize->serialize($document);
}
}

22
app/Engine/ICompile.php

@ -12,11 +12,27 @@ namespace App\Engine;
interface ICompile
{
/**
* Perform compilation/transform process on a document.
* Set the base document all our compilations are run against.
*
* @param \App\Dom\Document $document
* @return void
*/
public function setDocument(\App\Dom\Document $document): void;
/**
* Perform transform process on the document held by this class,
* using the one passed in as instructions.
*
* @param \App\Dom\Document $document document to compile
* @param IOptions $options options to control compilation process
* @return \App\Dom\Document the compiled document
* @return void
*/
public function compile(\App\Dom\Document $document, IOptions $options): void;
/**
* Retrieve the current result.
*
* @return \App\Dom\Document
*/
public function compile(\App\Dom\Document $document, IOptions $options): \App\Dom\Document;
public function getDocument(): \App\Dom\Document;
}

Loading…
Cancel
Save