add authors, composers, history and settings to Tune::merge()
This commit is contained in:
@@ -77,6 +77,26 @@ class Setting
|
||||
*/
|
||||
protected $music = [];
|
||||
|
||||
/**
|
||||
* Setting constructor.
|
||||
* @param array|null $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
foreach ($params as $attribute => $value) {
|
||||
$this->set($attribute, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributes
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\Setting
|
||||
*/
|
||||
public static function create(array $attributes)
|
||||
{
|
||||
return new static($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\Transcriber[]
|
||||
*/
|
||||
@@ -310,4 +330,25 @@ class Setting
|
||||
$this->music[] = $music;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
*/
|
||||
private function set($attribute, $value)
|
||||
{
|
||||
switch ($attribute) {
|
||||
|
||||
default:
|
||||
$this->append($attribute, $value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function append($attribute, MultivalueAttribute $values)
|
||||
{
|
||||
$method = 'add' . substr($attribute, 0, -1);
|
||||
foreach ($values->toArray() as $value) {
|
||||
call_user_func([$this, $method], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +283,16 @@ class Tune implements EntityInterface
|
||||
call_user_func([$this, 'addAuthor'], $value);
|
||||
break;
|
||||
|
||||
case 'Composers':
|
||||
$this->addComposer($value);
|
||||
break;
|
||||
|
||||
case 'settings':
|
||||
foreach ($value as $key => $settingParams) {
|
||||
$this->addSetting(Setting::create($settingParams));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->append($attribute, $value);
|
||||
}
|
||||
@@ -333,6 +343,7 @@ class Tune implements EntityInterface
|
||||
/**
|
||||
* @param StringAtom $musicLine
|
||||
* @return $this
|
||||
* @deprecated this should be on the setting
|
||||
*/
|
||||
public function addMusicLine(string $musicLine)
|
||||
{
|
||||
@@ -350,6 +361,10 @@ class Tune implements EntityInterface
|
||||
{
|
||||
//TODO
|
||||
$this->titles = array_merge($this->getTitles(), $source->getTitles());
|
||||
$this->authors = array_merge($this->getAuthors(), $source->getAuthors());
|
||||
$this->composers = array_merge($this->getComposers(), $source->getComposers());
|
||||
$this->history = array_merge($this->getHistory(), $source->getHistory());
|
||||
$this->tuneSettings = array_merge($this->getSettings(), $source->getSettings());
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,17 @@ class TuneAttributeArrayBuilder implements TuneBuilder
|
||||
{
|
||||
protected $attributes = [];
|
||||
|
||||
protected $settingIndex = 0;
|
||||
|
||||
public static function create()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Webpatser\Uuid\Uuid|null $identity
|
||||
* @return \XaiCorp\AbcParser\Domain\Core\Tune
|
||||
*/
|
||||
public function getTune(Uuid $identity = null): \XaiCorp\AbcParser\Domain\Core\Tune
|
||||
{
|
||||
return new Tune($this->attributes, $identity);
|
||||
@@ -25,7 +31,8 @@ class TuneAttributeArrayBuilder implements TuneBuilder
|
||||
*/
|
||||
public function handleEndOfMusic()
|
||||
{
|
||||
// TODO: Implement handleEndOfMusic() method.
|
||||
$this->settingIndex++;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,18 +47,18 @@ class TuneAttributeArrayBuilder implements TuneBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Enzyme\Axiom\Atoms\StringAtom $param
|
||||
* @param string $param
|
||||
* @return $this
|
||||
*/
|
||||
public function appendMusic(StringAtom $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
public function appendMusic(string $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
$index = 'MusicLines';
|
||||
$item = $param->getValue();
|
||||
$item = $param;
|
||||
|
||||
if (!isset($this->attributes[$index])) {
|
||||
$this->attributes[$index] = MultivalueAttribute::create($item);
|
||||
if (!isset($this->attributes['settings'][$this->settingIndex][$index])) {
|
||||
$this->attributes['settings'][$this->settingIndex][$index] = MultivalueAttribute::create($item);
|
||||
} else {
|
||||
$this->attributes[$index]->add($item);
|
||||
$this->attributes['settings'][$this->settingIndex][$index]->add($item);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -95,9 +102,18 @@ class TuneAttributeArrayBuilder implements TuneBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComposer(StringAtom $composerName)
|
||||
public function addComposer(string $name): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
// TODO: Implement addComposer() method.
|
||||
$index = 'Composers';
|
||||
$item = Composer::create($name, new EmailAtom(''));
|
||||
|
||||
if (!isset($this->attributes[$index])) {
|
||||
$this->attributes[$index] = $item;
|
||||
} else {
|
||||
$this->attributes[$index]->add($item);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTranscriber(StringAtom $transcriberName)
|
||||
@@ -130,9 +146,18 @@ class TuneAttributeArrayBuilder implements TuneBuilder
|
||||
// TODO: Implement addFilename() method.
|
||||
}
|
||||
|
||||
public function addHistory(StringAtom $history)
|
||||
public function addHistory(string $history): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
// TODO: Implement addHistory() method.
|
||||
$index = 'HistoryLines';
|
||||
$item = MultivalueAttribute::create($history);
|
||||
|
||||
if (!isset($this->attributes[$index])) {
|
||||
$this->attributes[$index] = $item;
|
||||
} else {
|
||||
$this->attributes[$index]->add($item);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRhythm(StringAtom $rhythm)
|
||||
|
||||
@@ -27,7 +27,7 @@ interface TuneBuilder
|
||||
*/
|
||||
public function setIndex(UnsignedIntegerAtom $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
public function appendMusic(StringAtom $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
public function appendMusic(string $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
public function addTitle(string $title): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
@@ -37,7 +37,7 @@ interface TuneBuilder
|
||||
|
||||
public function addAuthor(string $name): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
public function addComposer(StringAtom $composerName);
|
||||
public function addComposer(string $name): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
public function addTranscriber(StringAtom $transcriberName);
|
||||
|
||||
@@ -51,7 +51,7 @@ interface TuneBuilder
|
||||
|
||||
public function addFilename(StringAtom $filename);
|
||||
|
||||
public function addHistory(StringAtom $history);
|
||||
public function addHistory(string $history): \XaiCorp\AbcParser\Domain\Core\TuneBuilder;
|
||||
|
||||
public function addRhythm(StringAtom $rhythm);
|
||||
|
||||
|
||||
@@ -94,9 +94,9 @@ class Builder implements TuneBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function appendMusic(StringAtom $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
public function appendMusic(string $param): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
$this->setting->addMusicLine($param->getValue());
|
||||
$this->setting->addMusicLine($param);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -130,9 +130,9 @@ class Builder implements TuneBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComposer(StringAtom $composerName)
|
||||
public function addComposer(string $name): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
$composer = new Composer($composerName, new EmailAtom(''));
|
||||
$composer = Composer::create($name, new EmailAtom(''));
|
||||
$this->tune->addComposer($composer);
|
||||
|
||||
return $this;
|
||||
@@ -173,9 +173,11 @@ class Builder implements TuneBuilder
|
||||
$this->setting->addFilename($filename->getValue());
|
||||
}
|
||||
|
||||
public function addHistory(StringAtom $history)
|
||||
public function addHistory(string $history): \XaiCorp\AbcParser\Domain\Core\TuneBuilder
|
||||
{
|
||||
$this->tune->addHistoryLine($history->getValue());
|
||||
$this->tune->addHistoryLine($history);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRhythm(StringAtom $rhythm)
|
||||
|
||||
@@ -33,7 +33,7 @@ class Composer implements Lex
|
||||
list($key, $data) = $this->getKeyDataFromLine($line);
|
||||
|
||||
if ($key === 'C') {
|
||||
$this->builder->addComposer(new StringAtom($data));
|
||||
$this->builder->addComposer($data);
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
|
||||
@@ -36,10 +36,10 @@ class History implements Lex
|
||||
if ($key === 'H'
|
||||
&& $context->isState($context::MODE_TUNE_HEADER)
|
||||
) {
|
||||
$this->builder->addHistory(new StringAtom($data));
|
||||
$this->builder->addHistory($data);
|
||||
$context->setStateInHistory();
|
||||
} elseif ($context->isState($context::MODE_HISTORY)) {
|
||||
$this->builder->addHistory(new StringAtom($line));
|
||||
$this->builder->addHistory($line);
|
||||
|
||||
if ($this->nextLineNotHistory($context)) {
|
||||
$context->setStateInTuneHeader();
|
||||
|
||||
@@ -36,7 +36,7 @@ class MusicLine implements Lex
|
||||
&& $key !== 'K'
|
||||
&& $line !== ''
|
||||
) {
|
||||
$this->builder->appendMusic(new StringAtom($line));
|
||||
$this->builder->appendMusic($line);
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
|
||||
Reference in New Issue
Block a user