Source for file View.php

Documentation is available at View.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * Viewの実行準備および実行を行うFilter
  20.  *
  21.  * @package     teeple.filter
  22.  */
  23. {
  24.     /**
  25.      * @var Teeple_Response 
  26.      */
  27.     private $response;
  28.     public function setComponent_Teeple_Response($c{
  29.         $this->response $c;
  30.     }
  31.     
  32.     /**
  33.      * @var Teeple_Token 
  34.      */
  35.     private $token;
  36.     public function setComponent_Teeple_Token($c{
  37.         $this->token $c;
  38.     }
  39.     
  40.     /**
  41.      * コンストラクタ
  42.      *
  43.      */
  44.     public function __construct({
  45.         parent::__construct();
  46.     }
  47.  
  48.     public function prefilter({}
  49.     
  50.     /**
  51.      * Viewの処理を実行
  52.      *
  53.      **/
  54.  
  55.     public function postfilter({
  56.  
  57.         if ($this->isCompleteResponse()) {
  58.             $this->log->info("CompleteResponseフラグが立っているため、Viewは実行されませんでした。");
  59.             return;
  60.         }        
  61.  
  62.         $view $this->response->getView();
  63.         $this->log->debug("view: $view");
  64.         
  65.         if ($view == ""{
  66.             $view $_SERVER['PATH_INFO'];
  67.         }
  68.  
  69.         if ($view != ""{
  70.             $template preg_replace("/^\//"""$view);
  71.             if ($template == ""{
  72.                 throw new Teeple_Exception("テンプレートの指定が不正です。($template)");
  73.             }
  74.             
  75.             if (preg_match("/^location:/"$template)) {
  76.                 $url preg_replace("/^location:/"""$template);
  77.                 $url trim($url);
  78.                 $this->response->setRedirect($url);
  79.             else if (preg_match("/^redirect:/"$template)) {
  80.                 $url preg_replace("/^redirect:/"""$template);
  81.                 $url trim($url);
  82.                 $url str_replace('_','/',$url);
  83.                 
  84.                 $base str_replace("/teeple_controller.php"""$_SERVER['SCRIPT_NAME']);
  85.                 $url $base .'/'$url .'.html';
  86.                 $this->request->setFilterError(NULL);
  87.                 // TODO 定数化
  88.                 $this->session->setParameter("__REDIRECT_SCOPE_REQUEST"$this->request);
  89.                 $this->response->setRedirect($url);
  90.             else {
  91.                 $renderer Teeple_Smarty4Maple::getInstance();
  92.                 $action $this->actionChain->getCurAction();
  93.                 $renderer->setAction($action);
  94.                 if (is_object($this->token)) {
  95.                     $renderer->setToken($this->token);
  96.                 }
  97.                 if (is_object($this->session)) {
  98.                     $renderer->setSession($this->session);
  99.                 }
  100.                 if (is_object($this->request)) {
  101.                     $renderer->setRequest($this->request);
  102.                 }
  103.                 $renderer->setScriptName($_SERVER['SCRIPT_NAME']);
  104.                 
  105.                 $result $renderer->fetch($template);
  106.                 if ($result == ""{
  107.                     throw new Teeple_Exception("Viewのレンダリングに失敗しました。");
  108.                 }
  109.                 
  110.                 $this->response->setResult($result);
  111.             }
  112.         }
  113.  
  114.         $contentDisposition $this->response->getContentDisposition();
  115.         $contentType        $this->response->getContentType();
  116.         $result             $this->response->getResult();
  117.         $redirect           $this->response->getRedirect();
  118.  
  119.         if ($redirect{
  120.             $this->redirect($redirect);
  121.         else {
  122.             if ($contentDisposition != ""{
  123.                 header("Content-disposition: ${contentDisposition}");
  124.             }
  125.             if ($contentType != ""{
  126.                 header("Content-type: ${contentType}");
  127.             }
  128.  
  129.             print $result;
  130.         }
  131.  
  132.         return;
  133.     }
  134.     
  135.     /**
  136.      * リダイレクトします。
  137.      * @param string $url 
  138.      */
  139.     private function redirect($url{
  140.         
  141.         if (isset($_COOKIE[session_name()])) {
  142.             if (strpos($url'?'=== FALSE{
  143.                 $url .= '?';
  144.             else {
  145.                 $url .= '&';
  146.             }
  147.             $url .= session_name(."="session_id();
  148.         }
  149.         
  150.         header("Location: $url");
  151.     }
  152.     
  153. }
  154. ?>

Documentation generated on Mon, 26 Apr 2010 09:00:05 +0900 by phpDocumentor 1.4.3