Files
abcParser/src/Domain/Core/Person.php
richard 2cdf7dd1cf
Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit
update webpatser/laravel-uuid to version 3
2020-06-20 12:36:34 -04:00

89 lines
1.8 KiB
PHP
Executable File

<?php
namespace XaiCorp\AbcParser\Domain\Core;
use Enzyme\Axiom\Atoms\StringAtom;
use Exception;
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);
}
/**
* @param string $name
* @param \XaiCorp\AbcParser\Domain\Atoms\EmailAtom $email
* @param \Webpatser\Uuid\Uuid|null $identity
* @return static
* @throws \Enzyme\Axiom\Exceptions\AtomException
*/
public static function create(string $name, EmailAtom $email, Uuid $identity = null)
{
$nameAtom = new StringAtom($name);
return new static($nameAtom, $email, $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.
}
}