finished default parser
This commit is contained in:
@@ -14,13 +14,25 @@
|
||||
"zackkitzmiller/tiny": "^1.2",
|
||||
"webpatser/laravel-uuid": "^2.0",
|
||||
"enzyme/axiom": "^4.2",
|
||||
"enzyme/freckle": "^0.3.0"
|
||||
"enzyme/freckle": "^0.3.0",
|
||||
"squizlabs/php_codesniffer": "^3.1",
|
||||
"phpmd/phpmd": "^2.6",
|
||||
"illuminate/database": "^5.5",
|
||||
"enzyme/collection": "^1.0",
|
||||
"illuminate/Pipeline": "^5.5",
|
||||
"league/pipeline": "^0.3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"XaiCorp\\AbcParser\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/",
|
||||
"Tests\\Unit\\": "tests/unit"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0"
|
||||
}
|
||||
|
||||
1651
composer.lock
generated
1651
composer.lock
generated
File diff suppressed because it is too large
Load Diff
20
src/Application/Boundary/PersonMapper.php
Normal file
20
src/Application/Boundary/PersonMapper.php
Normal 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);
|
||||
}
|
||||
14
src/Application/PersonFactory.php
Normal file
14
src/Application/PersonFactory.php
Normal 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);
|
||||
}
|
||||
}
|
||||
44
src/Application/PersonRepository.php
Normal file
44
src/Application/PersonRepository.php
Normal 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;
|
||||
}
|
||||
}
|
||||
55
src/Application/UseCases/ImportAbcFile.php
Normal file
55
src/Application/UseCases/ImportAbcFile.php
Normal 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;
|
||||
}
|
||||
}
|
||||
38
src/Domain/Atoms/EmailAtom.php
Normal file
38
src/Domain/Atoms/EmailAtom.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Atoms;
|
||||
|
||||
use Enzyme\Axiom\Atoms\AtomInterface;
|
||||
|
||||
class EmailAtom implements AtomInterface
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function __construct($email)
|
||||
{
|
||||
$this->validateEmail($email);
|
||||
$this->value = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying value associated with this atom.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
private function validateEmail($value)
|
||||
{
|
||||
if (!$this->isValid($value)) {
|
||||
throw new \Exception('Not a valid email');
|
||||
}
|
||||
}
|
||||
|
||||
private function isValid($value)
|
||||
{
|
||||
//TODO:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
12
src/Domain/Atoms/UnsignedIntegerAtom.php
Normal file
12
src/Domain/Atoms/UnsignedIntegerAtom.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Atoms;
|
||||
|
||||
use Enzyme\Axiom\Atoms\IntegerAtom;
|
||||
|
||||
class UnsignedIntegerAtom extends IntegerAtom
|
||||
{
|
||||
protected function isInvalidOrFloat($value)
|
||||
{
|
||||
return parent::isInvalidOrFloat($value) || $value <= 0;
|
||||
}
|
||||
}
|
||||
7
src/Domain/Boundary/PersonFactory.php
Normal file
7
src/Domain/Boundary/PersonFactory.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Boundary;
|
||||
|
||||
interface PersonFactory
|
||||
{
|
||||
|
||||
}
|
||||
7
src/Domain/Boundary/PersonRepository.php
Normal file
7
src/Domain/Boundary/PersonRepository.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Boundary;
|
||||
|
||||
interface PersonRepository
|
||||
{
|
||||
|
||||
}
|
||||
7
src/Domain/Core/AttributeTrait.php
Normal file
7
src/Domain/Core/AttributeTrait.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
trait AttributeTrait
|
||||
{
|
||||
|
||||
}
|
||||
7
src/Domain/Core/Author.php
Normal file
7
src/Domain/Core/Author.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
class Author extends Person
|
||||
{
|
||||
|
||||
}
|
||||
7
src/Domain/Core/Composer.php
Normal file
7
src/Domain/Core/Composer.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
class Composer extends Person
|
||||
{
|
||||
|
||||
}
|
||||
15
src/Domain/Core/EntityInterface.php
Normal file
15
src/Domain/Core/EntityInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
use Webpatser\Uuid\Uuid;
|
||||
|
||||
interface EntityInterface extends ModelInterface
|
||||
{
|
||||
/**
|
||||
* Get the unique identity for this mode.
|
||||
*
|
||||
* @return Uuid
|
||||
*/
|
||||
public function identity();
|
||||
}
|
||||
32
src/Domain/Core/IdentityTrait.php
Normal file
32
src/Domain/Core/IdentityTrait.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
use Webpatser\Uuid\Uuid;
|
||||
|
||||
trait IdentityTrait
|
||||
{
|
||||
/**
|
||||
* @var Uuid
|
||||
*/
|
||||
protected $identity;
|
||||
|
||||
|
||||
/**
|
||||
* Get the unique identity for this model.
|
||||
*
|
||||
* @return Uuid
|
||||
*/
|
||||
public function identity()
|
||||
{
|
||||
return $this->identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uuid|null $identity
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function setIdentity(Uuid $identity = null)
|
||||
{
|
||||
$this->identity = is_null($identity) ? Uuid::generate(4) : $identity;
|
||||
}
|
||||
}
|
||||
73
src/Domain/Core/Person.php
Normal file
73
src/Domain/Core/Person.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use Webpatser\Uuid\Uuid;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
|
||||
class Person implements EntityInterface
|
||||
{
|
||||
use IdentityTrait;
|
||||
|
||||
const TYPE_COMPOSER = 'composer';
|
||||
const TYPE_AUTHOR = 'author';
|
||||
|
||||
/**
|
||||
* @var StringAtom
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var EmailAtom
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
public function __construct(StringAtom $name, EmailAtom $email, Uuid $identity = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
|
||||
$this->setIdentity($identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this model has the given attribute set.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($attribute)
|
||||
{
|
||||
return in_array($attribute, [
|
||||
'name',
|
||||
'email',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the given attribute.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($attribute)
|
||||
{
|
||||
if (!$this->has($attribute)) {
|
||||
throw new \Exception('Cannot access attribute on person');
|
||||
}
|
||||
|
||||
return $this->{$attribute};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the attributes associated with this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
// TODO: Implement getAll() method.
|
||||
}
|
||||
}
|
||||
313
src/Domain/Core/Setting.php
Normal file
313
src/Domain/Core/Setting.php
Normal file
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
|
||||
class Setting
|
||||
{
|
||||
use IdentityTrait;
|
||||
|
||||
//fields that support multiple values
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $transcribers = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $notes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $discography = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $sources = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $words = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $books = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $filenames = [];
|
||||
|
||||
//fields that only ever have one value
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $part = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempo = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $noteLength = '1/8';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $meter = '4/4';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'C';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $music = [];
|
||||
|
||||
/**
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\Transcriber[]
|
||||
*/
|
||||
public function getTranscribers(): array
|
||||
{
|
||||
return $this->transcribers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transcriber $transcriber
|
||||
* @return Setting
|
||||
*/
|
||||
public function addTranscriber(Transcriber $transcriber): Setting
|
||||
{
|
||||
$this->transcribers[] = $transcriber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getNotes(): array
|
||||
{
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $note
|
||||
* @return Setting
|
||||
*/
|
||||
public function addNote(string $note): Setting
|
||||
{
|
||||
$this->notes[] = $note;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDiscography(): array
|
||||
{
|
||||
return $this->discography;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $recording
|
||||
* @return Setting
|
||||
*/
|
||||
public function addRecording(string $recording): Setting
|
||||
{
|
||||
$this->discography[] = $recording;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSources(): array
|
||||
{
|
||||
return $this->sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return Setting
|
||||
*/
|
||||
public function addSource(string $source): Setting
|
||||
{
|
||||
$this->sources[] = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWords(): array
|
||||
{
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $words
|
||||
* @return Setting
|
||||
*/
|
||||
public function addWords(string $words): Setting
|
||||
{
|
||||
$this->words[] = $words;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getBooks(): array
|
||||
{
|
||||
return $this->books;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $book
|
||||
* @return Setting
|
||||
*/
|
||||
public function addBook(string $book): Setting
|
||||
{
|
||||
$this->books[] = $book;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilenames(): array
|
||||
{
|
||||
return $this->filenames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return Setting
|
||||
*/
|
||||
public function addFilename(string $filename): Setting
|
||||
{
|
||||
$this->filenames[] = $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPart(): string
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $part
|
||||
* @return Setting
|
||||
*/
|
||||
public function setPart(string $part): Setting
|
||||
{
|
||||
$this->part = $part;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTempo(): string
|
||||
{
|
||||
return $this->tempo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tempo
|
||||
* @return Setting
|
||||
*/
|
||||
public function setTempo(string $tempo): Setting
|
||||
{
|
||||
$this->tempo = $tempo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNoteLength(): string
|
||||
{
|
||||
return $this->noteLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $noteLength
|
||||
* @return Setting
|
||||
*/
|
||||
public function setNoteLength(string $noteLength): Setting
|
||||
{
|
||||
$this->noteLength = $noteLength;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMeter(): string
|
||||
{
|
||||
return $this->meter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $meter
|
||||
* @return Setting
|
||||
*/
|
||||
public function setMeter(string $meter): Setting
|
||||
{
|
||||
$this->meter = $meter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return Setting
|
||||
*/
|
||||
public function setKey(string $key): Setting
|
||||
{
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMusic(): string
|
||||
{
|
||||
return implode('\n', $this->music);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $music
|
||||
* @return Setting
|
||||
*/
|
||||
public function addMusicLine(string $music): Setting
|
||||
{
|
||||
$this->music[] = $music;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
7
src/Domain/Core/Transcriber.php
Normal file
7
src/Domain/Core/Transcriber.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
class Transcriber extends Person
|
||||
{
|
||||
|
||||
}
|
||||
309
src/Domain/Core/Tune.php
Normal file
309
src/Domain/Core/Tune.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Axiom\Atoms\IntegerAtom;
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use Webpatser\Uuid\Uuid;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
|
||||
class Tune implements EntityInterface
|
||||
{
|
||||
use IdentityTrait;
|
||||
|
||||
/**
|
||||
* @var Int
|
||||
*/
|
||||
protected $index = 1;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $titles = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $authors = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $composers = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $groups = [];
|
||||
|
||||
/**
|
||||
* multiline history
|
||||
* @var array
|
||||
*/
|
||||
protected $history = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $origins = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $rhythms = [];
|
||||
|
||||
/**
|
||||
* @var Setting[]
|
||||
*/
|
||||
protected $tuneSettings;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $music = '';
|
||||
|
||||
// public static $propertyNames = [
|
||||
// 'X' => 'id',
|
||||
// 'T' => 'Title',
|
||||
// 'A' => 'Author',
|
||||
// 'C' => 'Composer',
|
||||
// 'G' => 'Group,',
|
||||
// 'H' => 'History',
|
||||
// 'O' => 'Origin',
|
||||
// 'R' => 'Rhythm',
|
||||
// ];
|
||||
|
||||
public function __construct(array $params, Uuid $identity = null)
|
||||
{
|
||||
$this->setIdentity($identity);
|
||||
foreach ($params as $attribute => $value) {
|
||||
$this->set($attribute, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UnsignedIntegerAtom $index
|
||||
* @return $this
|
||||
*/
|
||||
public function setIndex(UnsignedIntegerAtom $index) : Tune
|
||||
{
|
||||
$this->index = $index->getValue();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Int
|
||||
*/
|
||||
public function getIndex() : int
|
||||
{
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTitles() : array
|
||||
{
|
||||
return $this->titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return $this
|
||||
*/
|
||||
public function addTitle(string $title) : Tune
|
||||
{
|
||||
$this->titles[] = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Author $author
|
||||
* @return $this
|
||||
*/
|
||||
public function addAuthor(Author $author) : Tune
|
||||
{
|
||||
$this->authors[] = $author;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Author[]
|
||||
*/
|
||||
public function getAuthors() : array //TODO: PersonCollection
|
||||
{
|
||||
return $this->authors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Composer $composer
|
||||
* @return $this
|
||||
*/
|
||||
public function addComposer(Composer $composer) : Tune
|
||||
{
|
||||
$this->composers[] = $composer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Composer[]
|
||||
*/
|
||||
public function getComposers()
|
||||
{
|
||||
return $this->composers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
* @return $this
|
||||
*/
|
||||
public function addGroup(string $group) : Tune
|
||||
{
|
||||
$this->groups[] = $group;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $historyLine
|
||||
* @return $this
|
||||
*/
|
||||
public function addHistoryLine(string $historyLine)
|
||||
{
|
||||
$this->history[] = $historyLine;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHistory()
|
||||
{
|
||||
return $this->history;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $origin
|
||||
* @return $this
|
||||
*/
|
||||
public function addOrigin(string $origin)
|
||||
{
|
||||
$this->origins[] = $origin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrigins()
|
||||
{
|
||||
return $this->origins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StringAtom $rhythm
|
||||
* @return $this
|
||||
*/
|
||||
public function addRhythm(string $rhythm)
|
||||
{
|
||||
$this->rhythms[] = $rhythm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRhythms()
|
||||
{
|
||||
return $this->rhythms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Setting $tuneSetting
|
||||
* @return $this
|
||||
*/
|
||||
public function addSetting(Setting $tuneSetting)
|
||||
{
|
||||
$this->tuneSettings[] = $tuneSetting;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Setting[]
|
||||
*/
|
||||
public function getSettings()
|
||||
{
|
||||
return $this->tuneSettings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
*/
|
||||
protected function set($attribute, $value)
|
||||
{
|
||||
call_user_func([$this, 'set'.$attribute], [$value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this model has the given attribute set.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($attribute)
|
||||
{
|
||||
return isset($this->{$attribute});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value associated with the given attribute.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($attribute)
|
||||
{
|
||||
// TODO: Implement get() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the attributes associated with this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
// TODO: Implement getAll() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StringAtom $musicLine
|
||||
* @return $this
|
||||
*/
|
||||
public function appendMusicLine(string $musicLine)
|
||||
{
|
||||
$this->music .= $musicLine->getValue() . PHP_EOL;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
19
src/Domain/Core/TuneCollection.php
Normal file
19
src/Domain/Core/TuneCollection.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Collection\Collection;
|
||||
|
||||
class TuneCollection extends Collection
|
||||
{
|
||||
/**
|
||||
* Get the value of the first element in this collection.
|
||||
*
|
||||
* @throws \Enzyme\Collection\CollectionException If the collection is empty.
|
||||
*
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\Tune
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
return parent::first();
|
||||
}
|
||||
}
|
||||
204
src/Domain/Modules/Interpreter/Builder.php
Normal file
204
src/Domain/Modules/Interpreter/Builder.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Author;
|
||||
use XaiCorp\AbcParser\Domain\Core\Composer;
|
||||
use XaiCorp\AbcParser\Domain\Core\Setting;
|
||||
use XaiCorp\AbcParser\Domain\Core\Transcriber;
|
||||
use XaiCorp\AbcParser\Domain\Core\Tune;
|
||||
use XaiCorp\AbcParser\Domain\Core\TuneCollection;
|
||||
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
|
||||
|
||||
class Builder
|
||||
{
|
||||
/**
|
||||
* @var Tune
|
||||
*/
|
||||
protected $tune;
|
||||
|
||||
/**
|
||||
* @var TuneCollection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* @var Setting
|
||||
*/
|
||||
protected $setting;
|
||||
|
||||
/**
|
||||
* Interpreter constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->collection = new TuneCollection();
|
||||
$this->tune = new Tune([]);
|
||||
$this->setting = new Setting();
|
||||
|
||||
$this->tune->addSetting($this->setting);
|
||||
}
|
||||
|
||||
public function getTune()
|
||||
{
|
||||
return $this->tune;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\TuneCollection
|
||||
*/
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function handleEndOfMusic()
|
||||
{
|
||||
if ($this->tune && empty($this->tune->getTitles())) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->tune->addSetting($this->setting);
|
||||
$this->collection[] = $this->tune;
|
||||
|
||||
$this->tune = new Tune([]);
|
||||
$this->setting = new Setting();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UnsignedIntegerAtom $index
|
||||
* @return $this
|
||||
*/
|
||||
public function setIndex(UnsignedIntegerAtom $index)
|
||||
{
|
||||
$this->tune->setIndex($index);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function appendMusic(StringAtom $musicLine)
|
||||
{
|
||||
$this->setting->addMusicLine($musicLine->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTitle(StringAtom $title)
|
||||
{
|
||||
$this->tune->addTitle($title->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setKey(StringAtom $key)
|
||||
{
|
||||
$this->setting->setKey($key->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMeter(StringAtom $key)
|
||||
{
|
||||
$this->setting->setMeter($key->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAuthor(StringAtom $name)
|
||||
{
|
||||
$author = new Author($name, new EmailAtom(''));
|
||||
$this->tune->addAuthor($author);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComposer(StringAtom $composerName)
|
||||
{
|
||||
$composer = new Composer($composerName, new EmailAtom(''));
|
||||
$this->tune->addComposer($composer);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTranscriber(StringAtom $transcriberName)
|
||||
{
|
||||
$transcriber = new Transcriber($transcriberName, new EmailAtom(''));
|
||||
$this->setting->addTranscriber($transcriber);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addDiscography(StringAtom $recording)
|
||||
{
|
||||
$this->setting->addRecording($recording->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addGroup(StringAtom $groupName)
|
||||
{
|
||||
$this->tune->addGroup($groupName->getValue());
|
||||
}
|
||||
|
||||
public function setParts(StringAtom $part)
|
||||
{
|
||||
$this->setting->setPart($part->getValue());
|
||||
}
|
||||
|
||||
public function addSource(StringAtom $source)
|
||||
{
|
||||
$this->setting->addSource($source->getValue());
|
||||
}
|
||||
|
||||
public function addFilename(StringAtom $filename)
|
||||
{
|
||||
$this->setting->addFilename($filename->getValue());
|
||||
}
|
||||
|
||||
public function addHistory(StringAtom $history)
|
||||
{
|
||||
$this->tune->addHistoryLine($history->getValue());
|
||||
}
|
||||
|
||||
public function addRhythm(StringAtom $rhythm)
|
||||
{
|
||||
$this->tune->addRhythm($rhythm->getValue());
|
||||
}
|
||||
|
||||
public function addBook(StringAtom $param)
|
||||
{
|
||||
$this->setting->addBook($param->getValue());
|
||||
}
|
||||
|
||||
public function addWords(StringAtom $param)
|
||||
{
|
||||
$this->setting->addWords($param->getValue());
|
||||
}
|
||||
|
||||
public function addTempo(StringAtom $param)
|
||||
{
|
||||
$this->setting->setTempo($param->getValue());
|
||||
}
|
||||
|
||||
public function addNoteLength(StringAtom $param)
|
||||
{
|
||||
$this->setting->setNoteLength($param->getValue());
|
||||
}
|
||||
|
||||
public function addNote(StringAtom $param)
|
||||
{
|
||||
$this->setting->addNote($param->getValue());
|
||||
}
|
||||
|
||||
public function addOrigin(StringAtom $param)
|
||||
{
|
||||
$this->tune->addOrigin($param->getValue());
|
||||
}
|
||||
}
|
||||
116
src/Domain/Modules/Interpreter/Context.php
Normal file
116
src/Domain/Modules/Interpreter/Context.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use Enzyme\Collection\Collection;
|
||||
|
||||
class Context extends Collection
|
||||
{
|
||||
const MODE_NO_DATA = 0;
|
||||
const MODE_FILE_HEADER = 1;
|
||||
const MODE_TUNE_HEADER = 2;
|
||||
const MODE_TUNE_BODY = 3;
|
||||
const MODE_HISTORY = 4;
|
||||
|
||||
const ABC_VERSION_20 = '2.0';
|
||||
const ABC_VERSION_21 = '2.1';
|
||||
const ABC_VERSION_DEFAULT = self::ABC_VERSION_21;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $abcText;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected $abcLines;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $state = self::MODE_NO_DATA;
|
||||
|
||||
public function __construct(StringAtom $abc)
|
||||
{
|
||||
$this->abcText = $abc->getValue();
|
||||
|
||||
parent::__construct(preg_split("/(\r?\n)/", $abc->getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStateInFileHeader()
|
||||
{
|
||||
$this->state = self::MODE_FILE_HEADER;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStateInTuneHeader()
|
||||
{
|
||||
$this->state = self::MODE_TUNE_HEADER;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStateInTuneBody()
|
||||
{
|
||||
$this->state = self::MODE_TUNE_BODY;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStateInHistory()
|
||||
{
|
||||
$this->state = self::MODE_HISTORY;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStateInBetween()
|
||||
{
|
||||
$this->state = self::MODE_NO_DATA;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $state
|
||||
* @return bool
|
||||
*/
|
||||
public function isState(int $state) : bool
|
||||
{
|
||||
return $this->state === $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* get abc version of the file
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return '2.1';
|
||||
}
|
||||
}
|
||||
121
src/Domain/Modules/Interpreter/DefaultInterpreter.php
Normal file
121
src/Domain/Modules/Interpreter/DefaultInterpreter.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Tune;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Author;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Book;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Composer;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Discography;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\EndOfTune;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Filename;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Group;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\History;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Index;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\KeySignature;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Meter;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\MusicLine;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\NoteLength;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Notes;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Origin;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Parts;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Rhythm;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Source;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Tempo;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Title;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Transcriber;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon\Words;
|
||||
|
||||
class DefaultInterpreter extends Interpreter
|
||||
{
|
||||
protected $keyMap = [
|
||||
'K' => 'key',
|
||||
'L' => 'length',
|
||||
'M' => 'meter',
|
||||
'P' => 'part',
|
||||
'Q' => 'tempo',
|
||||
'B' => 'book',
|
||||
'N' => 'note',
|
||||
'D' => 'disc',
|
||||
'S' => 'source',
|
||||
'W' => 'words',
|
||||
'Z' => 'transcriber',
|
||||
'F' => 'filename',
|
||||
'H' => 'history',
|
||||
'A' => 'author',
|
||||
'C' => 'composer',
|
||||
'G' => 'group',
|
||||
'R' => 'rhythm',
|
||||
'T' => 'title',
|
||||
'O' => 'origin'
|
||||
];
|
||||
|
||||
protected $lexers = [
|
||||
Index::class,
|
||||
Title::class,
|
||||
Author::class,
|
||||
Book::class,
|
||||
Composer::class,
|
||||
Transcriber::class,
|
||||
Discography::class,
|
||||
Group::class,
|
||||
Source::class,
|
||||
Origin::class,
|
||||
KeySignature::class,
|
||||
Meter::class,
|
||||
Parts::class,
|
||||
Tempo::class,
|
||||
NoteLength::class,
|
||||
Notes::class,
|
||||
History::class,
|
||||
Filename::class,
|
||||
Words::class,
|
||||
Rhythm::class,
|
||||
MusicLine::class,
|
||||
EndOfTune::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param \XaiCorp\AbcParser\Domain\Modules\Interpreter\Context $context
|
||||
* @return $this
|
||||
*/
|
||||
public function execute(Context $context)
|
||||
{
|
||||
$lexicon = $this->pipeline();
|
||||
|
||||
do {
|
||||
$result = (new InterpreterPipeline())
|
||||
->send($context)
|
||||
->through($lexicon)
|
||||
->via('handle')
|
||||
->then(function ($context) {
|
||||
return $context;
|
||||
});
|
||||
$context->next();
|
||||
} while ($context->count() > $context->key());
|
||||
|
||||
// return $this->builder->getTune();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastTune()
|
||||
{
|
||||
return $this->builder->getTune();
|
||||
}
|
||||
|
||||
public function getTunes()
|
||||
{
|
||||
return $this->builder->getCollection();
|
||||
}
|
||||
|
||||
protected function pipeline()
|
||||
{
|
||||
$pipeline = [];
|
||||
|
||||
foreach ($this->lexers as $lexerClass) {
|
||||
$pipeline[] = new $lexerClass($this->builder);
|
||||
}
|
||||
|
||||
return $pipeline;
|
||||
}
|
||||
}
|
||||
36
src/Domain/Modules/Interpreter/Interpreter.php
Normal file
36
src/Domain/Modules/Interpreter/Interpreter.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use XaiCorp\AbcParser\Domain\Core\Tune;
|
||||
use XaiCorp\AbcParser\Domain\Core\TuneCollection;
|
||||
|
||||
abstract class Interpreter
|
||||
{
|
||||
const LN_VERSION = '/^%abc(-\d\.\d)?$/';
|
||||
const LN_BLANK = '/^\s*$/';
|
||||
const LN_FIELD = '/^\w:(.+)$/';
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* Interpreter constructor.
|
||||
*/
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @return Interpreter
|
||||
*/
|
||||
abstract public function execute(Context $context);
|
||||
|
||||
/**
|
||||
* @return TuneCollection
|
||||
*/
|
||||
abstract public function getTunes();
|
||||
}
|
||||
9
src/Domain/Modules/Interpreter/InterpreterPipeline.php
Normal file
9
src/Domain/Modules/Interpreter/InterpreterPipeline.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Illuminate\Pipeline\Pipeline;
|
||||
|
||||
class InterpreterPipeline extends Pipeline
|
||||
{
|
||||
|
||||
}
|
||||
40
src/Domain/Modules/Interpreter/Lexicon/Composer.php
Normal file
40
src/Domain/Modules/Interpreter/Lexicon/Composer.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class Composer implements Lex
|
||||
{
|
||||
use LineKeyDataTrait;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws \Enzyme\Axiom\Exceptions\AtomException
|
||||
*/
|
||||
public function handle(Context $context, \Closure $next)
|
||||
{
|
||||
$line = $context->current();
|
||||
list($key, $data) = $this->getKeyDataFromLine($line);
|
||||
|
||||
if ($key === 'C') {
|
||||
$this->builder->addComposer(new StringAtom($data));
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
}
|
||||
}
|
||||
36
src/Domain/Modules/Interpreter/Lexicon/Index.php
Normal file
36
src/Domain/Modules/Interpreter/Lexicon/Index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class Index implements Lex
|
||||
{
|
||||
use LineKeyDataTrait;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
public function handle(Context $context, \Closure $next)
|
||||
{
|
||||
$line = $context->current();
|
||||
list($key, $data) = $this->getKeyDataFromLine($line);
|
||||
|
||||
if ($key === 'X') {
|
||||
$context->setStateInTuneHeader();
|
||||
|
||||
$this->builder->setIndex(new UnsignedIntegerAtom($data));
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
}
|
||||
}
|
||||
7
src/Domain/Modules/Interpreter/Lexicon/Lex.php
Normal file
7
src/Domain/Modules/Interpreter/Lexicon/Lex.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
interface Lex
|
||||
{
|
||||
|
||||
}
|
||||
23
src/Domain/Modules/Interpreter/Lexicon/LineKeyDataTrait.php
Normal file
23
src/Domain/Modules/Interpreter/Lexicon/LineKeyDataTrait.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
trait LineKeyDataTrait
|
||||
{
|
||||
/**
|
||||
* @param string $line
|
||||
* @return array [$key, $data]
|
||||
*/
|
||||
protected function getKeyDataFromLine(string $line)
|
||||
{
|
||||
$key = '';
|
||||
$data = '';
|
||||
$matches = [];
|
||||
preg_match('/^(.):(.*)/', $line, $matches);
|
||||
|
||||
if (count($matches) === 3) {
|
||||
$key = trim($matches[1]);
|
||||
$data = trim($matches[2]);
|
||||
}
|
||||
return [$key, $data];
|
||||
}
|
||||
}
|
||||
40
src/Domain/Modules/Interpreter/Lexicon/Title.php
Normal file
40
src/Domain/Modules/Interpreter/Lexicon/Title.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class Title implements Lex
|
||||
{
|
||||
use LineKeyDataTrait;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws \Enzyme\Axiom\Exceptions\AtomException
|
||||
*/
|
||||
public function handle(Context $context, \Closure $next)
|
||||
{
|
||||
$line = $context->current();
|
||||
list($key, $data) = $this->getKeyDataFromLine($line);
|
||||
|
||||
if ($key === 'T') {
|
||||
$this->builder->addTitle(new StringAtom($data));
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
}
|
||||
}
|
||||
37
src/Framework/Laravel5/Models/Person.php
Normal file
37
src/Framework/Laravel5/Models/Person.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Framework\Laravel5\Models;
|
||||
|
||||
class Person extends ValidatingModel
|
||||
{
|
||||
use UuidTrait;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'persons';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name', 'email'];
|
||||
|
||||
protected $validationRules = [
|
||||
'id' => 'required',
|
||||
'name' => 'required|string|max:63',
|
||||
'email' => 'required|email|max:255'
|
||||
];
|
||||
|
||||
protected $hidden = ['email'];
|
||||
|
||||
//Relationships
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
namespace XaiCorp\AbcParser\Framework\Laravel5\Models;
|
||||
|
||||
use Webpatser\Uuid\Uuid;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Models\Laravel5;
|
||||
namespace XaiCorp\AbcParser\Framework\Laravel5\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as BaseModel;
|
||||
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
||||
|
||||
class ValidatingModel extends BaseModel
|
||||
{
|
||||
60
src/Framework/Laravel5/Models/ValidationTrait.php
Normal file
60
src/Framework/Laravel5/Models/ValidationTrait.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Framework\Laravel5\Models;
|
||||
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
Trait ValidationTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MessageBag
|
||||
*/
|
||||
protected $messages;
|
||||
|
||||
public function validate()
|
||||
{
|
||||
// validation
|
||||
$data = $this->getAttributes();
|
||||
|
||||
$validator = Validator::make($data, $this->validationRules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
if (! $this->messages) {
|
||||
$this->messages = new MessageBag();
|
||||
}
|
||||
$this->messages = $validator->getMessageBag();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|MessageBag
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages?$this->messages->toArray():[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidationRules()
|
||||
{
|
||||
return $this->validationRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the validation rules for a model class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRules()
|
||||
{
|
||||
$class = get_called_class();
|
||||
$instance = new $class();
|
||||
return $instance->getValidationRules();
|
||||
}
|
||||
}
|
||||
26
src/Framework/PersonDbMapper.php
Normal file
26
src/Framework/PersonDbMapper.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Framework;
|
||||
|
||||
use XaiCorp\AbcParser\Application\Boundary\PersonMapper;
|
||||
|
||||
class PersonDbMapper implements PersonMapper
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function insert()
|
||||
{
|
||||
// TODO: Implement insert() method.
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
// TODO: Implement delete() method.
|
||||
}
|
||||
}
|
||||
112
tests/unit/AbcParser/Domain/Core/SettingTest.php
Normal file
112
tests/unit/AbcParser/Domain/Core/SettingTest.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/26/17
|
||||
* Time: 9:21 PM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Setting;
|
||||
use XaiCorp\AbcParser\Domain\Core\Transcriber;
|
||||
|
||||
class SettingTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$params = [];
|
||||
|
||||
$setting = new Setting();
|
||||
|
||||
$this->assertInstanceOf(Setting::class, $setting);
|
||||
}
|
||||
|
||||
public function testAddTranscriber()
|
||||
{
|
||||
$name = new StringAtom('me');
|
||||
$email = new EmailAtom('me@example.com');
|
||||
$transcriber = new Transcriber($name, $email);
|
||||
$setting = new Setting();
|
||||
$setting->addTranscriber($transcriber);
|
||||
|
||||
$result = $setting->getTranscribers();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($transcriber, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddNote()
|
||||
{
|
||||
$note = 'a note';
|
||||
$setting = new Setting();
|
||||
$setting->addNote($note);
|
||||
|
||||
$result = $setting->getNotes();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($note, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddRecording()
|
||||
{
|
||||
$recording = 'cd recording number';
|
||||
$setting = new Setting();
|
||||
$setting->addRecording($recording);
|
||||
|
||||
$result = $setting->getDiscography();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($recording, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddSource()
|
||||
{
|
||||
$source = 'thesession.org';
|
||||
$setting = new Setting();
|
||||
$setting->addSource($source);
|
||||
|
||||
$result = $setting->getSources();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($source, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddWords()
|
||||
{
|
||||
$words = 'sing along with me';
|
||||
$setting = new Setting();
|
||||
$setting->addWords($words);
|
||||
|
||||
$result = $setting->getWords();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($words, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddBook()
|
||||
{
|
||||
$book = 'sing along with me';
|
||||
$setting = new Setting();
|
||||
$setting->addBook($book);
|
||||
|
||||
$result = $setting->getBooks();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($book, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddFilename()
|
||||
{
|
||||
$filename = 'test.abc';
|
||||
$setting = new Setting();
|
||||
$setting->addFilename($filename);
|
||||
|
||||
$result = $setting->getFilenames();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($filename, $result[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/27/17
|
||||
* Time: 6:14 AM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class ContextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$this->assertInstanceOf(Context::class, $context);
|
||||
}
|
||||
|
||||
public function testLoopingThroughLines()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$this->assertGreaterThan(1, count($context));
|
||||
foreach ($context as $key => $line) {
|
||||
$this->assertInternalType('string', $line);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetStateDefaultsToNoData()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->getState();
|
||||
|
||||
$this->assertEquals(Context::MODE_NO_DATA, $result);
|
||||
}
|
||||
|
||||
public function testSetStateInFileHeader()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->setStateInFileHeader()->getState();
|
||||
|
||||
$this->assertEquals(Context::MODE_FILE_HEADER, $result);
|
||||
}
|
||||
|
||||
public function testGetVersionReturnsDefault()
|
||||
{
|
||||
$expected = Context::ABC_VERSION_DEFAULT;
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->getVersion();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/30/17
|
||||
* Time: 8:58 AM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use Enzyme\Collection\CollectionException;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Author;
|
||||
use XaiCorp\AbcParser\Domain\Core\Composer;
|
||||
use XaiCorp\AbcParser\Domain\Core\Tune;
|
||||
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 DefaultInterpreterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Interpreter
|
||||
*/
|
||||
protected $interpreter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$builder = new Builder();
|
||||
$this->interpreter = new DefaultInterpreter($builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @return StringAtom
|
||||
*/
|
||||
private function createStringAtom($string = '')
|
||||
{
|
||||
try {
|
||||
return new StringAtom($string);
|
||||
} catch (\Exception $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
private function createAuthor($name, $email = '')
|
||||
{
|
||||
return new Author(
|
||||
$this->createStringAtom($name),
|
||||
new EmailAtom($email)
|
||||
);
|
||||
}
|
||||
|
||||
private function createComposer($name, $email = '')
|
||||
{
|
||||
return new Composer(
|
||||
$this->createStringAtom($name),
|
||||
new EmailAtom($email)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$builder = new Builder();
|
||||
$interpreter = new DefaultInterpreter($builder);
|
||||
|
||||
$this->assertInstanceOf(Interpreter::class, $interpreter);
|
||||
}
|
||||
|
||||
public function testExecuteReturnsInterpreter()
|
||||
{
|
||||
$abc = $this->createStringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $this->interpreter->execute($context);
|
||||
|
||||
$this->assertInstanceOf(Interpreter::class, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTitles()
|
||||
{
|
||||
$expectedTitle = ['Abbotts Bromley Horn Dance'];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getTitles();
|
||||
|
||||
$this->assertEquals($expectedTitle, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesAuthor()
|
||||
{
|
||||
$expected = 'trad';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getAuthors()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected, $result->getValue());
|
||||
}
|
||||
|
||||
public function testExecuteParsesComposer()
|
||||
{
|
||||
$expected = [$this->createComposer('trad.')];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getComposers()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected[0]->get('name'), $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTranscriber()
|
||||
{
|
||||
$expected = [$this->createComposer('Andy Hornby')];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getTranscribers()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected[0]->get('name'), $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesDiscography()
|
||||
{
|
||||
$expected = 'None';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getDiscography()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesGroups()
|
||||
{
|
||||
$expected = 'lute';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getGroups()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesKey()
|
||||
{
|
||||
$expected = 'G';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getKey();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesMusic()
|
||||
{
|
||||
$expected = implode('\n', [
|
||||
'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|',
|
||||
'|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|',
|
||||
'e2g efg|c2e cde|dcB AGF|E3E2',
|
||||
'|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]',
|
||||
]);
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getMusic();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesMeter()
|
||||
{
|
||||
$expected = '6/8';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getMeter();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesParts()
|
||||
{
|
||||
$expected = 'ABC';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getPart();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesSources()
|
||||
{
|
||||
$expected = 'http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getSources()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesHistory()
|
||||
{
|
||||
$expected = [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year',
|
||||
];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getHistory();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesRhythms()
|
||||
{
|
||||
$expected = 'Jig';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getRhythms()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesFilename()
|
||||
{
|
||||
$expected = 'none.abc';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getFilenames()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesBook()
|
||||
{
|
||||
$expected = 'Traditional English tunes';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getBooks()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesWords()
|
||||
{
|
||||
$expected = 'None';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getWords()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTempo()
|
||||
{
|
||||
$expected = '1/8=80';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getTempo();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesNoteLength()
|
||||
{
|
||||
$expected = '1/8';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getNoteLength();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesNotes()
|
||||
{
|
||||
$expected = 'Traditional English';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getNotes()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesOrigin()
|
||||
{
|
||||
$expected = 'England';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getOrigins()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMultipleTunesInAFile()
|
||||
{
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/jigs.abc'));
|
||||
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes();
|
||||
|
||||
$this->assertCount(52, $result);
|
||||
}
|
||||
}
|
||||
36
tests/unit/Application/PersonFactoryTest.php
Normal file
36
tests/unit/Application/PersonFactoryTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/19/17
|
||||
* Time: 4:49 PM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Application;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Application\PersonFactory;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Person;
|
||||
|
||||
class PersonFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$factory = new PersonFactory();
|
||||
|
||||
$this->assertInstanceOf(PersonFactory::class, $factory);
|
||||
}
|
||||
|
||||
public function testCreatePerson()
|
||||
{
|
||||
$factory = new PersonFactory();
|
||||
$name = new StringAtom('Roger');
|
||||
$email = new EmailAtom('');
|
||||
|
||||
$result = $factory->create($name, $email);
|
||||
|
||||
$this->assertInstanceOf(Person::class, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user