Skip to content

Instantly share code, notes, and snippets.

@BerezhniyDmitro
Created October 24, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BerezhniyDmitro/0ea3b1903decbb326eec35fe5ceba1d4 to your computer and use it in GitHub Desktop.
Save BerezhniyDmitro/0ea3b1903decbb326eec35fe5ceba1d4 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Domain\Company\Factory;
use App\Domain\Company\DTO\CompanyRegistrationDTO;
use App\Domain\ValueObjects\Okpo;
use App\Entities\Company\Company;
use App\Infrastructure\Repository\PersonalCabinet\PersonalCabinetRepository;
use App\ValueObjects\Email;
use App\ValueObjects\MobilePhone;
use App\ValueObjects\Title;
/**
* Class CompanyBuilder Билдер компании
*/
final class CompanyFactory implements CompanyFactoryInterface
{
/**
* @var PersonalCabinetRepository
*/
private $personalCabinetRepository;
public function __construct(PersonalCabinetRepository $personalCabinetRepository)
{
$this->personalCabinetRepository = $personalCabinetRepository;
}
/**
* Метод создает компанию
*
* @param CompanyRegistrationDTO $companyRegistrationDTO Дто для создания Компании.
*
* @return Company
*/
public function make(CompanyRegistrationDTO $companyRegistrationDTO): Company
{
$company = new Company(
Okpo::createFromString($companyRegistrationDTO->getOkpo()),
Title::createFromString($companyRegistrationDTO->getCompanyName()),
Email::createFromString($companyRegistrationDTO->getEmail())
);
if (! empty($companyRegistrationDTO->getPhoneNumber())) {
$company->changePhone(MobilePhone::createFromString($companyRegistrationDTO->getPhoneNumber()));
}
return $company;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment