コード例 #1
0
 /**
  * Create from the given result a Response instance and send it.
  *
  * @param mixed  $response
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function processResponse($response)
 {
     if ($response instanceof Renderable) {
         // If the response which is returned from the called Action is a Renderable instance,
         // we will assume we want to render it using the Controller's templated environment.
         if (is_string($this->layout) && !$response instanceof Layout) {
             $response = Template::make($this->layout, $this->template)->with('content', $response);
         }
         // Create a proper Response instance.
         $response = new Response($response->render(), 200, array('Content-Type' => 'text/html'));
     }
     // If the response is not a instance of Symfony Response, create a proper one.
     if (!$response instanceof SymfonyResponse) {
         $response = new Response($response);
     }
     return $response;
 }
コード例 #2
0
 /**
  * Create a new Error Response instance.
  *
  * The Response Status code will be set using the specified code.
  *
  * The specified error should match a View in your Views/Error directory.
  *
  * <code>
  *      // Create a 404 response.
  *      return Response::error('404');
  *
  *      // Create a 404 response with data.
  *      return Response::error('404', array('message' => 'Not Found'));
  * </code>
  *
  * @param  int       $code
  * @param  array     $data
  * @return Response
  */
 public static function error($status, array $data = array(), $headers = array())
 {
     $view = Template::make('default')->shares('title', 'Error ' . $status)->nest('content', 'Error/' . $status, $data);
     return static::make($view, $status, $headers);
 }
コード例 #3
0
 /**
  * Display a one time Message, then clear it from the Session.
  *
  * @param  string $name default Session name
  *
  * @return string
  */
 public static function message($name = 'success')
 {
     if (!static::exists($name)) {
         return null;
     }
     // Pull the Message from Session.
     $message = Session::pull($name);
     if (is_array($message)) {
         // The Message is structured in the New Style.
         $name = $message['type'];
         $message = $message['text'];
     }
     // Prepare the allert Type and Icon.
     $type = null;
     switch ($name) {
         case 'info':
             $icon = 'info';
             break;
         case 'warning':
             $icon = 'warning';
             break;
         case 'danger':
             $icon = 'bomb';
             break;
         default:
             $icon = 'check';
             $type = 'success';
     }
     $type = $type !== null ? $type : $name;
     // Fetch the associated Template Fragment and return the result.
     return Template::make('message', compact('type', 'icon', 'message'))->render();
 }
コード例 #4
0
 protected static function createMessage($message, $name = null)
 {
     if (is_array($message)) {
         $type = $message['type'];
         $message = $message['text'];
     } else {
         $type = $name;
     }
     // Adjust the alert Type.
     switch ($type) {
         case 'info':
         case 'success':
         case 'warning':
         case 'danger':
             break;
         default:
             $type = 'success';
             break;
     }
     // Handle the multiple line messages.
     if ($message instanceof MessageBag) {
         $message = $message->all();
     }
     // Handle the array messages.
     if (is_array($message)) {
         if (count($message) > 1) {
             $message = '<ul><li>' . implode('</li><li>', $message) . '</li></ul>';
         } else {
             if (!empty($message)) {
                 $message = array_shift($message);
             } else {
                 // An empty array?
                 $message = '';
             }
         }
     }
     // Fetch the associated Template Fragment and return the result.
     return Template::make('message', compact('type', 'message'), TEMPLATE)->render();
 }