Source for file Ethna_Renderer.php

Documentation is available at Ethna_Renderer.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Renderer.php
  5.  *
  6.  *  @author     Kazuhiro Hosoi <hosoi@gree.co.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id$
  10.  */
  11.  
  12. // {{{ Ethna_Renderer
  13. /**
  14.  *  レンダラクラス(Mojaviのまね)
  15.  *
  16.  *  @author     Kazuhiro Hosoi <hosoi@gree.co.jp>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**#@+
  22.      *  @access private
  23.      */
  24.  
  25.     /** @var    object  Ethna_Controller    controllerオブジェクト */
  26.     var $controller;
  27.  
  28.     /** @var    object  Ethna_Controller    controllerオブジェクト($controllerの省略形) */
  29.     var $ctl;
  30.  
  31.     /** @var    array   [appid]-ini.phpのレンダラ設定 */
  32.     var $config;
  33.  
  34.     /** @var    string  template directory  */
  35.     var $template_dir;
  36.  
  37.     /** @var    string  template engine */
  38.     var $engine;
  39.  
  40.     /** @var    string  template file */
  41.     var $template;
  42.  
  43.     /** @var    string  テンプレート変数 */
  44.     var $prop;
  45.     
  46.     /** @var    string  レンダラプラグイン(Ethna_Pluginとは関係なし) */
  47.     var $plugin_registry;
  48.     
  49.     /**
  50.      *  Ethna_Rendererクラスのコンストラクタ
  51.      *
  52.      *  @access public
  53.      */
  54.     function Ethna_Renderer(&$controller)
  55.     {
  56.         $this->controller =$controller;
  57.         $this->ctl =$this->controller;
  58.         $this->template_dir null;
  59.         $this->engine null;
  60.         $this->template null;
  61.         $this->prop array();
  62.         $this->plugin_registry array();
  63.         $config $this->ctl->getConfig();
  64.         $this->config $config->get('renderer')
  65.     }
  66.  
  67.     /**
  68.      *  ビューを出力する
  69.      *
  70.      *  @param string   $template   テンプレート
  71.      *  @param  bool    $capture    true ならば出力を表示せずに返す
  72.      *
  73.      *  @access public
  74.      */
  75.     function perform($template null$capture false)
  76.     {
  77.         if ($template == null && $this->template == null{
  78.             return Ethna::raiseWarning('template is not defined');
  79.         }
  80.  
  81.         if ($template != null{
  82.             $this->template $template;
  83.         }
  84.  
  85.         // テンプレートの有無のチェック
  86.         if (is_readable($this->template_dir $this->template=== false{
  87.             return Ethna::raiseWarning("template is not found: " $this->template);
  88.         }
  89.  
  90.         if ($capture === true{
  91.             ob_start();
  92.             include_once $this->template_dir $this->template;
  93.             $captured ob_get_contents();
  94.             ob_end_clean();
  95.             return $captured;
  96.         else {
  97.             include_once $this->template_dir $this->template;
  98.             return true;
  99.         }
  100.     }
  101.  
  102.     /**
  103.      *  テンプレートエンジンを取得する
  104.      * 
  105.      *  @return object   Template Engine.
  106.      * 
  107.      *  @access public
  108.      */
  109.     function &getEngine()
  110.     {
  111.         return $this->engine;
  112.     }
  113.  
  114.     /**
  115.      *  テンプレートディレクトリを取得する
  116.      * 
  117.      *  @return string   Template Directory
  118.      * 
  119.      *  @access public
  120.      */
  121.     function getTemplateDir()
  122.     {
  123.         return $this->template_dir;
  124.     }
  125.  
  126.     /**
  127.      *  テンプレート変数を取得する
  128.      * 
  129.      *  @param string $name  変数名
  130.      * 
  131.      *  @return mixed    変数
  132.      * 
  133.      *  @access public
  134.      */
  135.     function &getProp($name)
  136.     {
  137.         if (isset($this->prop[$name])) {
  138.             return $this->prop[$name];
  139.         }
  140.  
  141.         return null;
  142.     }
  143.  
  144.     /**
  145.      *  テンプレート変数を削除する
  146.      * 
  147.      *  @param name    変数名
  148.      * 
  149.      *  @access public
  150.      */
  151.     function &removeProp($name)
  152.     {
  153.         if (isset($this->prop[$name])) {
  154.             unset($this->prop[$name]);
  155.         }
  156.     }
  157.  
  158.     /**
  159.      *  テンプレート変数に配列を割り当てる
  160.      * 
  161.      *  @param array $array 
  162.      * 
  163.      *  @access public
  164.      */
  165.     function setPropArray($array)
  166.     {
  167.         $this->prop array_merge($this->prop$array);
  168.     }
  169.  
  170.     /**
  171.      *  テンプレート変数に配列を参照として割り当てる
  172.      * 
  173.      *  @param array $array 
  174.      * 
  175.      *  @access public
  176.      */
  177.     function setPropArrayByRef(&$array)
  178.     {
  179.         $keys  array_keys($array);
  180.         $count sizeof($keys);
  181.  
  182.         for ($i 0$i $count$i++{
  183.             $this->prop[$keys[$i]] =$array[$keys[$i]];
  184.         }
  185.     }
  186.  
  187.     /**
  188.      * テンプレート変数を割り当てる
  189.      * 
  190.      * @param string $name 変数名
  191.      * @param mixed $value 
  192.      * 
  193.      * @access public
  194.      */
  195.     function setProp($name$value)
  196.     {
  197.         $this->prop[$name$value;
  198.     }
  199.  
  200.     /**
  201.      *  テンプレート変数に参照を割り当てる
  202.      * 
  203.      *  @param string $name 変数名
  204.      *  @param mixed $value 
  205.      * 
  206.      *  @access public
  207.      */
  208.     function setPropByRef($name&$value)
  209.     {
  210.         $this->prop[$name=$value;
  211.     }
  212.  
  213.     /**
  214.      *  テンプレートを割り当てる
  215.      * 
  216.      *  @param string $template テンプレート名
  217.      * 
  218.      *  @access public
  219.      */
  220.     function setTemplate($template)
  221.     {
  222.         $this->template $template;
  223.     }
  224.  
  225.     /**
  226.      *  テンプレートディレクトリを割り当てる
  227.      * 
  228.      *  @param string $dir ディレクトリ名
  229.      * 
  230.      *  @access public
  231.      */
  232.     function setTemplateDir($dir)
  233.     {
  234.         $this->template_dir $dir;
  235.  
  236.         if (substr($this->template_dir-1!= '/'{
  237.             $this->template_dir .= '/';
  238.         }
  239.     }
  240.     
  241.     /**
  242.      *  テンプレートの有無をチェックする
  243.      * 
  244.      *  @param string $template テンプレート名
  245.      * 
  246.      *  @access public
  247.      */
  248.     function templateExists($template)
  249.     {
  250.         if (substr($this->template_dir-1!= '/'{
  251.             $this->template_dir .= '/';
  252.         }
  253.  
  254.         return (is_readable($this->template_dir $template));
  255.     }
  256.  
  257.     /**
  258.      *  プラグインをセットする
  259.      * 
  260.      *  @param string $name プラグイン名 
  261.      *  @param string $type プラグインタイプ
  262.      *  @param string $plugin プラグイン本体
  263.      * 
  264.      *  @access public
  265.      */
  266.     function setPlugin($name$type$plugin)
  267.     {
  268.         $this->plugin_registry[$type][$name$plugin;
  269.     }
  270.  
  271.     // {{{ proxy methods (for B.C.)
  272.     /**
  273.      *  テンプレート変数を割り当てる(後方互換)
  274.      *
  275.      *  @access public
  276.      */
  277.     function assign($name$value)
  278.     {
  279.         $this->setProp($name$value);
  280.     }
  281.  
  282.     /**
  283.      *  テンプレート変数に参照を割り当てる(後方互換)
  284.      *
  285.      *  @access public
  286.      */
  287.     function assign_by_ref($name&$value)
  288.     {
  289.         $this->setPropByRef($name$value);
  290.     }
  291.  
  292.     /**
  293.      *  ビューを出力する
  294.      *
  295.      *  @access public
  296.      */
  297.     function display($template null)
  298.     {
  299.         return $this->perform($template);
  300.     }
  301.     // }}}
  302. }
  303. // }}}
  304. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:47 +0900 by phpDocumentor 1.4.3