Source for file Plugin.php

Documentation is available at Plugin.php

  1. <?php
  2.  
  3. /**
  4.  * base plugin class
  5.  *
  6.  * you have to implement the <em>process()</em> method, it will receive the parameters that
  7.  * are in the template code
  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_Plugin
  26. {
  27.     /**
  28.      * the dwoo instance that runs this plugin
  29.      *
  30.      * @var Dwoo 
  31.      */
  32.     protected $dwoo;
  33.  
  34.     /**
  35.      * constructor, if you override it, call parent::__construct($dwoo); or assign
  36.      * the dwoo instance yourself if you need it
  37.      *
  38.      * @param Dwoo $dwoo the dwoo instance that runs this plugin
  39.      */
  40.     public function __construct(Dwoo $dwoo)
  41.     {
  42.         $this->dwoo = $dwoo;
  43.     }
  44.  
  45.     // plugins should always implement :
  46.     // public function process($arg, $arg, ...)
  47.     // or for block plugins :
  48.     // public function init($arg, $arg, ...)
  49.  
  50.     // this could be enforced with :
  51.     // abstract public function process(...);
  52.     // if my feature request gets enough interest one day
  53.     // see => http://bugs.php.net/bug.php?id=44043
  54.  
  55.     /**
  56.      * utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes
  57.      *
  58.      * this is to be used in preProcessing or postProcessing functions, example :
  59.      *  $p = $compiler->getCompiledParams($params);
  60.      *  // get only the rest array as attributes
  61.      *  $attributes = Dwoo_Plugin::paramsToAttributes($p['*']);
  62.      *  // get all the parameters as attributes (if there is a rest array, it will be included)
  63.      *  $attributes = Dwoo_Plugin::paramsToAttributes($p);
  64.      *
  65.      * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
  66.      * @param string $delim the string delimiter you want to use (defaults to ')
  67.      * @return string 
  68.      */
  69.     public static function paramsToAttributes(array $params$delim '\'')
  70.     {
  71.         if (isset($params['*'])) {
  72.             $params array_merge($params$params['*']);
  73.             unset($params['*']);
  74.         }
  75.  
  76.         $out '';
  77.         foreach ($params as $attr=>$val{
  78.             $out .= ' '.$attr.'=';
  79.             if (trim($val'"\'')=='' || $val=='null'{
  80.                 $out .= str_replace($delim'\\'.$delim'""');
  81.             elseif (substr($val01=== $delim && substr($val-1=== $delim{
  82.                 $out .= str_replace($delim'\\'.$delim'"'.substr($val1-1).'"');
  83.             else {
  84.                 $out .= str_replace($delim'\\'.$delim'"'$delim '.'.$val.'.' $delim str_replace($delim'\\'.$delim'"');
  85.             }
  86.         }
  87.  
  88.         return ltrim($out);
  89.     }
  90. }

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