예제 #1
0
 /**
  * Get a model from its name
  * @param  string     $name The name of the model
  * @param  string     $type The type of the model in lower case
  * @return \NamedModel|null  The model or null if no name was specified
  */
 protected function getModelFromName($name, $type)
 {
     if ($name === '') {
         return null;
     }
     if ($type === 'player') {
         return \Player::getFromUsername($name);
     } elseif ($type === 'team') {
         return \Team::getFromName($name);
     } else {
         throw new \InvalidArgumentException('Unsupported model type');
     }
 }
예제 #2
0
 /**
  * @Given a new user called :user joins :team
  */
 public function aNewUserCalledJoins($user, $team)
 {
     $player = $this->getNewUser($user);
     Team::getFromName($team)->addMember($player->getId());
 }
예제 #3
0
 protected function validateNew($form)
 {
     $name = $form->get('name');
     $team = Team::getFromName($name->getData());
     // The name for the team that the user gave us already exists
     // TODO: This takes deleted teams into account, do we want that?
     if ($team->isValid()) {
         $name->addError(new FormError("A team called {$team->getName()} already exists"));
     }
 }