Source for file Plugin.php

Documentation is available at Plugin.php

  1. <?php
  2.  
  3. /**
  4.  * base class for block plugins
  5.  *
  6.  * you have to implement the <em>init()</em> method, it will receive the parameters that
  7.  * are in the template code and is called when the block starts
  8.  *
  9.  * This software is provided 'as-is', without any express or implied warranty.
  10.  * In no event will the authors be held liable for any damages arising from the use of this software.
  11.  *
  12.  * This file is released under the LGPL
  13.  * "GNU Lesser General Public License"
  14.  * More information can be found here:
  15.  * {@link http://www.gnu.org/copyleft/lesser.html}
  16.  *
  17.  * @author     Jordi Boggiano <[email protected]>
  18.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  19.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  20.  * @link       http://dwoo.org/
  21.  * @version    0.9.1
  22.  * @date       2008-05-30
  23.  * @package    Dwoo
  24.  */
  25. abstract class Dwoo_Block_Plugin extends Dwoo_Plugin
  26. {
  27.     /**
  28.      * stores the contents of the block while it runs
  29.      *
  30.      * @var string 
  31.      */
  32.     protected $buffer = '';
  33.  
  34.     /**
  35.      * buffers input, override only if necessary
  36.      *
  37.      * @var string $input the content that must be buffered
  38.      */
  39.     public function buffer($input)
  40.     {
  41.         $this->buffer .= $input;
  42.     }
  43.  
  44.     // initialization code, receives the parameters from {block param1 param2}
  45.     // public function init($arg, $arg, ...);
  46.  
  47.     /**
  48.      * called when the block ends, this is most of the time followed right away by a call
  49.      * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
  50.      * block object, if required.
  51.      */
  52.     public function end()
  53.     {
  54.     }
  55.  
  56.     /**
  57.      * called when the block output is required by a parent block
  58.      *
  59.      * this must read $this->buffer and return it processed
  60.      *
  61.      * @return string 
  62.      */
  63.     public function process()
  64.     {
  65.         return $this->buffer;
  66.     }
  67.  
  68.     /**
  69.      * called at compile time to define what the block should output in the compiled template code, happens when the block is declared
  70.      *
  71.      * basically this will replace the {block arg arg arg} tag in the template
  72.      *
  73.      * @param Dwoo_Compiler $compiler the compiler instance that calls this function
  74.      * @param array $params an array containing original and compiled parameters
  75.      * @param string $prepend that is just meant to allow a child class to call
  76.      *                            parent::postProcessing($compiler, $params, "foo();") to add a command before the
  77.      *                            default commands are executed
  78.      * @param string $append that is just meant to allow a child class to call
  79.      *                           parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
  80.      *                           default commands are executed
  81.      * @param string $type the type is the plugin class name used
  82.      */
  83.     public static function preProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$type)
  84.     {
  85.         return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.implode(', '$compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;
  86.     }
  87.  
  88.     /**
  89.      * called at compile time to define what the block should output in the compiled template code, happens when the block is ended
  90.      *
  91.      * basically this will replace the {/block} tag in the template
  92.      *
  93.      * @see preProcessing
  94.      * @param Dwoo_Compiler $compiler the compiler instance that calls this function
  95.      * @param array $params an array containing original and compiled parameters, see preProcessing() for more details
  96.      * @param string $prepend that is just meant to allow a child class to call
  97.      *                            parent::postProcessing($compiler, $params, "foo();") to add a command before the
  98.      *                            default commands are executed
  99.      * @param string $append that is just meant to allow a child class to call
  100.      *                           parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
  101.      *                           default commands are executed
  102.      * @param string $content the entire content of the block being closed
  103.      */
  104.     public static function postProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$content)
  105.     {
  106.         return $content Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;
  107.     }
  108. }

Documentation generated on Sun, 03 Aug 2008 15:12:42 +0200 by phpDocumentor 1.4.0