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

309
src/Domain/Core/Tune.php Normal file
View 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;
}
}