Created
October 24, 2019 12:30
-
-
Save BerezhniyDmitro/0ea3b1903decbb326eec35fe5ceba1d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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