public function create($data) { $person = new Person($data->first_name, $data->last_name); if (isset($data->middle_name)) { $person->setMiddleName($data->middle_name); } if (isset($data->display_name)) { $person->setDisplayName($data->display_name); } $account = new Account($person); switch ($data->status) { case 'active': $account->setStatus(AccountInterface::STATUS_ACTIVE); break; case 'inactive': $account->setStatus(AccountInterface::STATUS_INACTIVE); break; default: throw new RuntimeException('Invalid account status provided.'); } $this->entityManager->persist($person); $this->entityManager->persist($account); $this->entityManager->flush($account); return new AccountEntity($account); }
public function accountCreateAction() { $firstName = $this->params('first-name'); if (!$firstName) { $firstName = Line::prompt('Please enter the first name of the person: '); } $lastName = $this->params('last-name'); if (!$lastName) { $lastName = Line::prompt('Please enter the last name of the person: '); } $credential = $this->params('credential'); if (!$credential) { $credential = Password::prompt('Please enter the credential of this new account: '); $verification = Password::prompt('Please enter the credential again to verify: '); if ($credential !== $verification) { $this->getConsole()->writeLine('The two credentials do not match.'); return 1; } } $person = new Person($firstName, $lastName); $account = new Account($person); $account->setCredential($this->crypter->create($credential)); $this->entityManager->persist($account); $this->entityManager->flush($account); $this->getConsole()->writeLine('Account created with id ' . $account->getId()->toString()); return 0; }
public function load(ObjectManager $manager) { /** @var PasswordInterface $password */ $password = $this->getServiceLocator()->get(PasswordInterface::class); $person = new Person('Walter', 'Tamboer'); $manager->persist($person); $account = new Account($person); $account->setCredential($password->create('root')); $manager->persist($account); $identity = new Identity($account, 'username', 'root'); $manager->persist($identity); $manager->flush(); }
public function load(ObjectManager $manager) { /** @var PasswordInterface $password */ $password = $this->getServiceLocator()->get(PasswordInterface::class); for ($i = 0; $i < 10; ++$i) { $person = new Person('Account', $i); $manager->persist($person); $account = new AccountEntity($person); $account->setCredential($password->create('account' . $i)); $manager->persist($account); $identity = new Identity($account, 'username', 'account' . $i); $manager->persist($identity); } $manager->flush(); }
public function inviteAccount($data) { // Lookup the e-mail address: $repository = $this->entityManager->getRepository(Email::class); $accountEmail = $repository->findOneBy(['address' => $data['email']]); if ($accountEmail !== null) { return $accountEmail->getAccount(); } $person = new Person($data['first_name'], $data['last_name']); $person->setMiddleName($data['middle_name']); $emailAddress = new EmailAddress($person, EmailAddress::TYPE_WORK, $data['email']); $account = new AccountEntity($person); $account->setStatus(AccountEntity::STATUS_INVITED); $accountEmail = new Email($account, $data['email']); $accountEmail->setValidationCode(Rand::getString(32, range('a', 'z'))); $account->getEmailAddresses()->add($accountEmail); $this->entityManager->persist($person); $this->entityManager->persist($emailAddress); $this->entityManager->persist($account); $this->entityManager->flush(); return $account; }
public function __construct(Account $account) { $this->id = $account->getId(); $this->creationDate = $account->getCreationDate(); switch ($account->getStatus()) { case AccountInterface::STATUS_ACTIVE: $this->status = 'active'; break; case AccountInterface::STATUS_INACTIVE: $this->status = 'inactive'; break; case AccountInterface::STATUS_INVITED: $this->status = 'invited'; break; default: throw new RuntimeException('The account status could not be converted to a string.'); } $contact = $account->getContact(); if ($contact instanceof Person) { $this->contact = new PersonEntity($contact); } else { $this->contact = new CompanyEntity($contact); } }