Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit
81 lines
1.5 KiB
PHP
Executable File
81 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace XaiCorp\AbcParser\Domain\Core;
|
|
|
|
class MultivalueAttribute
|
|
{
|
|
/**
|
|
* @var \XaiCorp\AbcParser\Domain\Core\Collection
|
|
*/
|
|
protected $data;
|
|
|
|
private function __construct()
|
|
{
|
|
$this->data = new Collection();
|
|
}
|
|
|
|
/**
|
|
* @param string $item
|
|
* @return \XaiCorp\AbcParser\Domain\Core\MultivalueAttribute
|
|
*/
|
|
public static function create(string $item)
|
|
{
|
|
return (new self())->add($item);
|
|
}
|
|
|
|
/**
|
|
* @param array $items
|
|
* @return \XaiCorp\AbcParser\Domain\Core\MultivalueAttribute
|
|
*/
|
|
public static function createFromArray(array $items)
|
|
{
|
|
$attribute = new self();
|
|
|
|
foreach ($items as $item) {
|
|
$attribute->add($item);
|
|
}
|
|
|
|
return $attribute;
|
|
}
|
|
|
|
/**
|
|
* @param string $item
|
|
* @return static
|
|
*/
|
|
public function add(string $item)
|
|
{
|
|
$this->data = $this->data->push($item)->unique();
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param MultivalueAttribute $attribute
|
|
* @return static
|
|
*/
|
|
public function merge(MultivalueAttribute $attribute)
|
|
{
|
|
$this->data = $this->data
|
|
->pushArray($attribute->data->toArray())
|
|
->unique();
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function first()
|
|
{
|
|
return $this->data->firstOrDefault('');
|
|
}
|
|
|
|
/**
|
|
* @return string[]
|
|
*/
|
|
public function toArray()
|
|
{
|
|
return $this->data->toArray();
|
|
}
|
|
}
|