Source for file View.php

Documentation is available at View.php

  1. <?php
  2. // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 fdm=marker encoding=utf8 :
  3. /**
  4.  * Pxxo - build self-supported and interoperable Web graphical components
  5.  * 
  6.  * Copyright (c) 2008, Nicolas Thouvenin
  7.  *
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions are met:
  12.  *
  13.  *     * Redistributions of source code must retain the above copyright
  14.  *       notice, this list of conditions and the following disclaimer.
  15.  *     * Redistributions in binary form must reproduce the above copyright
  16.  *       notice, this list of conditions and the following disclaimer in the
  17.  *       documentation and/or other materials provided with the distribution.
  18.  *     * Neither the name of the author nor the names of its contributors may be
  19.  *       used to endorse or promote products derived from this software without
  20.  *       specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25.  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
  26.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  
  33.  * @package    Pxxo
  34.  * @copyright  Copyright (c) 2008 Nicolas Thouvenin
  35.  * @license    http://opensource.org/licenses/bsd-license.php
  36.  * @version    $Id$
  37.  */
  38.  
  39. if (!defined('PXXO_ZEND_PATH')) {
  40.     define('PXXO_ZEND_PATH'realpath(rtrim(dirname(__FILE__),DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ZendFramework'));
  41.     $include_path ini_get('include_path');
  42.     if ((PXXO_ZEND_PATH !== false&& (strpos($include_pathPXXO_ZEND_PATH=== false))
  43.         ini_set('include_path'$include_path.PATH_SEPARATOR.PXXO_ZEND_PATH);
  44. }
  45.  
  46. require_once 'Zend/View/Abstract.php';
  47. require_once 'Pxxo/Buffer.php';
  48.  
  49. /**
  50.  * Moteur de template pour les différentes "VUE" d'un composants
  51.  *
  52.  * @package    Pxxo
  53.  * @copyright  Copyright (c) 2008 Nicolas Thouvenin
  54.  * @license    http://opensource.org/licenses/bsd-license.php
  55.  */
  56. class Pxxo_View extends Zend_View_Abstract
  57. {
  58.     /**
  59.      * @var Pxxo_Buffer Input buffer
  60.      */
  61.     private $_input;
  62.  
  63.     /**
  64.      * @var Pxxo_Buffer Output buffer
  65.      */
  66.     private $_output;
  67.  
  68.     /**
  69.      * Simaultion héritage multiple
  70.      * @var Pxxo_Widget 
  71.      */
  72.     private $Pxxo = null;
  73.  
  74.     /**
  75.      * Constructor.
  76.      *
  77.      * @param array $config Configuration key-value pairs.
  78.      */
  79.     public function __construct($config array())
  80.     {
  81.         parent::__construct($config);
  82.         $this->Pxxo = new Pxxo;
  83.     }
  84.  
  85.     /**
  86.      * Finds a view script from the available directories.
  87.      *
  88.      * @param $name string The base name of the script.
  89.      * @return void 
  90.      */
  91.     protected function _script($name)
  92.     {
  93.         return null;
  94.     }
  95.     /**
  96.      * Processes a view script and returns the output.
  97.      *
  98.      * @param string $name The script script name to process.
  99.      * @param string $type The type of the output buffer
  100.      * @return Pxxo_Buffer 
  101.      */
  102.     public function render($name$type '')
  103.     {
  104.         if ($type === ''{
  105.             if (preg_match(',\.php\.(.+)$,'$name$m)) {
  106.                 $type $m[1];
  107.             }
  108.             else trigger_error("View error : invalid type `".$name."`"E_USER_ERROR);
  109.         }
  110.         $this->_input  = Pxxo_Buffer::factory($type$name)
  111.         $this->_output = Pxxo_Buffer::factory($typeparent::render(null));
  112.         return $this->_output;
  113.     }
  114.  
  115.     /**
  116.      * On récupére le flux de sortie
  117.      *
  118.      * @return    Pxxo_Buffer 
  119.      */
  120.     public function getOutputBuffer()
  121.     
  122.         return $this->_output;
  123.     }
  124.  
  125.     /**
  126.      * On choisit un flux d'entrée
  127.      *
  128.      * @param Pxxo_Buffer 
  129.      * @access   public
  130.      */
  131.     public function setInputBuffer($o)
  132.     {
  133.         $this->_input = $o;
  134.     }
  135.  
  136.     /**
  137.      * Transformation Du buffer d'entrée en buffer de Sortie
  138.      *
  139.      * @param string $type The type of the output buffer
  140.      */
  141.     public function transform($type)
  142.     {
  143.         $this->_input->copyto($this->Pxxo);
  144.  
  145.         $this->Pxxo->resetCacheID();
  146.         $this->Pxxo->addCacheID($type);
  147.         $this->Pxxo->addCacheID($this->_input->getCacheID());
  148.  
  149.         $out $this->Pxxo->getinCache($this->Pxxo->getCacheID()P_C_TEMPLATE);
  150.  
  151.         if ($out === false{
  152.             $this->Pxxo->traceDebug("VIEW\t[executed]\tinput(uri:".$this->_input->uri.")\toutput(type:".$type.')');
  153.  
  154.             // Transformation
  155.             $out parent::render(null);
  156.             if (!empty($out)) $this->Pxxo->setinCache($out$this->Pxxo->getCacheID()P_C_TEMPLATE);
  157.         }
  158.         else {
  159.             $this->Pxxo->traceDebug("VIEW\t[cached]\tinput(uri:".$this->_input->uri.")\toutput(type:".$type.')');
  160.         }
  161.         $this->_output = Pxxo_Buffer::factory($type$out);
  162.         $this->Pxxo->copyto($this->_output);
  163.     }
  164.  
  165.     /**
  166.      * Includes the view script in a scope with only public $this variables.
  167.      *
  168.      * @param string The view script to execute.
  169.      */
  170.     protected function _run()
  171.     {
  172.         extract($this->getVars());
  173.         if ($this->_input->scheme == 'file')
  174.             include($this->_input->uri);
  175.         else {
  176.             eval('?'.'>'.$this->_input->get());
  177.         }
  178.     }
  179.  
  180.     /**
  181.      * Directly assigns a variable to the view script.
  182.      *
  183.      * Checks first to ensure that the caller is not attempting to set a
  184.      * protected or private member (by checking for a prefixed underscore); if
  185.      * not, the public member is set; otherwise, an exception is raised.
  186.      *
  187.      * @param string $key The variable name.
  188.      * @param mixed $val The variable value.
  189.      * @return void 
  190.      * @throws Zend_View_Exception if an attempt to set a private or protected
  191.      *  member is detected
  192.      */
  193.     public function __set($key$val)
  194.     {
  195.         $this->Pxxo->addCacheID($val);
  196.         return parent::__set($key$val);
  197.     }
  198.  
  199. }

Documentation generated on Thu, 13 Mar 2008 22:03:23 +0100 by phpDocumentor 1.4.1