コード例 #1
0
ファイル: AccountResource.php プロジェクト: zource/zource
 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);
 }