Files
izyim/app/Classes/Modules/Contacts/Services/CreatesContact.php
T
2019-03-05 15:23:11 +08:00

48 lines
1.1 KiB
PHP

<?php
namespace App\Modules\Contacts\Services;
use App\Classes\Modules\Contacts\Exceptions\CannotCreateContactException;
use App\Models\Contact;
use App\Modules\Contacts\DataTransferObjects\ContactObject;
class CreatesContact
{
/** @var Contact */
private $repository;
/**
* CreatesContact constructor.
* @param Contact $repository
*/
public function __construct(Contact $repository)
{
$this->repository = $repository;
}
public function execute(ContactObject $object){
try {
$this->repository->type = $object->getType();
$this->repository->reference_id = $object->getReferenceId();
$this->repository->name = $object->getName();
$this->repository->designation = $object->getDesignation();
$this->repository->contact = $object->getContact();
$this->repository->email = $object->getEmail();
$this->repository->save();
return $this->repository;
} catch (\Exception $exception){
throw new CannotCreateContactException($exception->getMessage());
}
}
}