finished default parser

This commit is contained in:
2018-04-24 21:11:23 -04:00
parent 8a1c752045
commit 3817394951
39 changed files with 3725 additions and 328 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace XaiCorp\AbcParser\Application\Boundary;
use Enzyme\Axiom\Bags\BagInterface;
use Webpatser\Uuid\Uuid;
interface PersonMapper
{
public function insert();
public function update();
public function delete();
/**
* @param Uuid $id
* @return BagInterface
*/
public function fetch(Uuid $id);
}

View File

@@ -0,0 +1,14 @@
<?php
namespace XaiCorp\AbcParser\Application;
use Enzyme\Axiom\Atoms\StringAtom;
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
use XaiCorp\AbcParser\Domain\Core\Person;
class PersonFactory implements \XaiCorp\AbcParser\Domain\Boundary\PersonFactory
{
public function create(StringAtom $name, EmailAtom $email)
{
return new Person($name, $email);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace XaiCorp\AbcParser\Application;
use Enzyme\Axiom\Atoms\StringAtom;
use Webpatser\Uuid\Uuid;
use XaiCorp\AbcParser\Application\Boundary\PersonMapper;
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
use XaiCorp\AbcParser\Domain\Core\Person;
class PersonRepository implements \XaiCorp\AbcParser\Domain\Boundary\PersonRepository
{
/**
* @var PersonMapper
*/
protected $mapper;
protected $store = [];
public function __construct(PersonMapper $personMapper)
{
$this->mapper = $personMapper;
}
/**
* @param Uuid $id
* @return mixed
*/
public function getPerson(Uuid $id)
{
if (!empty($this->store[$id->string])) {
$person = $this->store[$id->string];
} else {
$personInfo = $this->mapper->fetch($id);
$person = new Person(
new StringAtom($personInfo->get('name')),
new EmailAtom($personInfo->get('email'))
);
$this->store[$id->string] = $person;
}
return $person;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace XaiCorp\AbcParser\Application\UseCases;
use Enzyme\Axiom\Atoms\StringAtom;
use XaiCorp\AbcParser\Domain\Core\TuneCollection;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\DefaultInterpreter;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Interpreter;
class ImportAbcFile
{
/**
* @var Builder
*/
protected $builderTemplate;
/**
* @param Builder|null $builderTemplate
*/
public function __construct(Builder $builderTemplate = null)
{
$this->builderTemplate = $builderTemplate ?: new Builder();
}
/**
* @param string $abc
* @return TuneCollection
* @throws \Enzyme\Axiom\Exceptions\AtomException
*/
public function import(string $abc) : TuneCollection
{
$context = new Context(new StringAtom($abc));
$parser = $this->getBestParser($context);
$result = $parser->execute($context);
return $result;
}
/**
* @param Context $context
* @return Interpreter
*/
public function getBestParser(Context $context) : Interpreter
{
$builder = clone $this->builderTemplate;
switch($context->getVersion()) {
default:
$interpreter = new DefaultInterpreter($builder);
}
return $interpreter;
}
}