Adam Pippin
3 years ago
10 changed files with 167 additions and 43 deletions
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Dom; |
|||
|
|||
/** |
|||
* Root node of a document. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
class Document extends Node |
|||
{ |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Dom; |
|||
|
|||
/** |
|||
* Node in a document. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
class Node |
|||
{ |
|||
// parent, children, type |
|||
} |
@ -0,0 +1,52 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Engine; |
|||
|
|||
/** |
|||
* Main class responsible for controlling the compilation process. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
class Engine |
|||
{ |
|||
/** @var \App\Engine\ICompile */ |
|||
protected $compile; |
|||
|
|||
/** @var \App\Serialize\ISerialize */ |
|||
protected $serialize; |
|||
|
|||
/** @var \App\Serialize\IUnserialize */ |
|||
protected $unserialize; |
|||
|
|||
public function setCompiler(ICompile $compiler): Engine |
|||
{ |
|||
$this->compile = $compiler; |
|||
return $this; |
|||
} |
|||
|
|||
public function setSerializer(\App\Serialize\ISerialize $serializer): Engine |
|||
{ |
|||
$this->serialize = $serializer; |
|||
return $this; |
|||
} |
|||
|
|||
public function setUnserializer(\App\Serialize\IUnserialize $unserializer): Engine |
|||
{ |
|||
$this->unserialize = $unserializer; |
|||
return $this; |
|||
} |
|||
|
|||
public function compile(string $document_string): string |
|||
{ |
|||
$document = $this->unserialize->unserialize($document_string); |
|||
$document = $this->compile->compile($document); |
|||
return $this->serialize->serialize($document); |
|||
} |
|||
|
|||
public function compileDocument(\App\Dom\Document $document): \App\Dom\Document |
|||
{ |
|||
return $this->compile->compile($document); |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Engine; |
|||
|
|||
/** |
|||
* Perform compilation of a document. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
interface ICompile |
|||
{ |
|||
public function compile(\App\Dom\Document $document, IOptions $options); |
|||
} |
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Engine; |
|||
|
|||
/** |
|||
* Configure the compilation process or provide state. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
interface IOptions |
|||
{ |
|||
} |
@ -1,34 +0,0 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Providers; |
|||
|
|||
use Illuminate\Contracts\Support\DeferrableProvider; |
|||
use Illuminate\Support\ServiceProvider; |
|||
use App\Yaml; |
|||
|
|||
class YamlServiceProvider extends ServiceProvider implements DeferrableProvider |
|||
{ |
|||
/** |
|||
* Register application services. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function register() |
|||
{ |
|||
$this->app->singleton(Yaml::class, static function($app) { |
|||
return new Yaml(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Get the services provided by this provider. |
|||
* |
|||
* @return string[] |
|||
*/ |
|||
public function provides() |
|||
{ |
|||
return [Yaml::class]; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Serialize; |
|||
|
|||
/** |
|||
* Something that can turn a Dom\Document into a string. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
interface ISerialize |
|||
{ |
|||
public function serialize(\App\Dom\Document $document): string; |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Serialize; |
|||
|
|||
/** |
|||
* Something that can turn a string into a Dom\Document. |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
interface IUnserialize |
|||
{ |
|||
public function unserialize(string $document): \App\Dom\Document; |
|||
} |
@ -0,0 +1,27 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Yaml; |
|||
|
|||
use Symfony\Component\Yaml\Yaml as SymfonyYaml; |
|||
use App\Serialize\ISerialize; |
|||
use App\Serialize\IUnserialize; |
|||
use App\Dom\Document; |
|||
|
|||
class Yaml implements ISerialize, IUnserialize |
|||
{ |
|||
public function unserialize(string $document): Document |
|||
{ |
|||
$data = SymfonyYaml::parse($document, SymfonyYaml::PARSE_CUSTOM_TAGS); |
|||
// TODO: Convert data to dom document |
|||
} |
|||
|
|||
public function serialize(Document $document): string |
|||
{ |
|||
// TODO: Convert document to array |
|||
// Convert custom tags to Symfony\Component\Yaml\Tag\TaggedValue |
|||
// new TaggedValue('my_tag', ['data'=>'here']) |
|||
return SymfonyYaml::dump($data); |
|||
} |
|||
} |
@ -1,9 +0,0 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Util; |
|||
|
|||
class Yaml |
|||
{ |
|||
} |
Loading…
Reference in new issue