Example #1
0
 /**
  * {@inheritDoc}
  */
 protected function handleReturnValue($return, $action)
 {
     // Format strings nicely with JSON, if the client wants that
     if ($this->isJson()) {
         if (!$return instanceof JsonResponse) {
             $response = array('success' => true);
             $flashbag = $this->getFlashBag();
             if ($flashbag->has('success')) {
                 $messages = $flashbag->get('success');
                 $response['message'] = $messages[0];
             }
             $response['content'] = is_array($return) ? $this->renderDefault($return, $action) : $return;
             $response = array_replace($response, $this->attributes->all());
             $return = new JsonResponse($response);
         }
     }
     return parent::handleReturnValue($return, $action);
 }
Example #2
0
 /**
  * Convert a player ID to a model
  *
  * @throws InvalidNameException
  * @param  int                  $id The player ID
  * @return Player
  */
 private function idToModel($id)
 {
     $id = (int) $id;
     $player = new Player($id);
     if (!\HTMLController::canSee($player)) {
         throw new InvalidNameException("There is no player with ID {$id}");
     }
     return $player;
 }