Browse Source

Fleshing out rough architecture

master
Adam Pippin 3 years ago
parent
commit
1167bae2f5
  1. 14
      app/Dom/Document.php
  2. 15
      app/Dom/Node.php
  3. 52
      app/Engine/Engine.php
  4. 15
      app/Engine/ICompile.php
  5. 14
      app/Engine/IOptions.php
  6. 34
      app/Providers/YamlServiceProvider.php
  7. 15
      app/Serialize/ISerialize.php
  8. 15
      app/Serialize/IUnserialize.php
  9. 27
      app/Serialize/Yaml.php
  10. 9
      app/Util/Yaml.php

14
app/Dom/Document.php

@ -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
{
}

15
app/Dom/Node.php

@ -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
}

52
app/Engine/Engine.php

@ -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);
}
}

15
app/Engine/ICompile.php

@ -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);
}

14
app/Engine/IOptions.php

@ -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
{
}

34
app/Providers/YamlServiceProvider.php

@ -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];
}
}

15
app/Serialize/ISerialize.php

@ -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;
}

15
app/Serialize/IUnserialize.php

@ -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;
}

27
app/Serialize/Yaml.php

@ -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);
}
}

9
app/Util/Yaml.php

@ -1,9 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Util;
class Yaml
{
}
Loading…
Cancel
Save