Files
abcParser/src/Application/UseCases/ImportAbcFile.php
2018-04-24 21:11:23 -04:00

56 lines
1.4 KiB
PHP

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