mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-22 22:13:57 +00:00
48 lines
1.1 KiB
PHP
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());
|
|
}
|
|
|
|
}
|
|
|
|
} |