home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Template / Flexy / Plugin.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  4.0 KB  |  118 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors:  nobody <nobody@localhost>                                  |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Plugin.php,v 1.10 2005/05/14 03:44:26 alan_k Exp $
  20. //
  21. // Plugin API provides support for  < ? = $this->plugin(".....",.....); ? >
  22. //  or {this.plugin(#xxxxx#,#xxxx#):h}
  23. //
  24. // BASICALLY THIS IS SAVANT'S PLUGIN PROVIDER.
  25. // @author Paul M. Jones <pmjones@ciaweb.net>
  26.  
  27.  
  28. class HTML_Template_Flexy_Plugin {
  29.     
  30.     /**
  31.     * reference to main engine..
  32.     *
  33.     * @var object HTML_Template_Flexy
  34.     * @access public
  35.     */
  36.     var $flexy; // reference to flexy.
  37.     var $pluginCache = array(); // store of instanced plugins..
  38.     
  39.     /**
  40.     * Call a Plugin method.
  41.     *
  42.     * Look up in all the plugins to see if the method exists, if it does, call it.
  43.     * 
  44.     * 
  45.     * @param   array        name of method, arguments.
  46.     * 
  47.     *
  48.     * @return   string      hopefully
  49.     * @access   public
  50.     */
  51.   
  52.     function call($args)
  53.     {
  54.         
  55.         
  56.         $method = $args[0];
  57.         // attempt to load the plugin on-the-fly
  58.         $class = $this->_loadPlugins($method);
  59.          
  60.         if (is_a($class,'PEAR_Error')) {
  61.             //echo $class->toString();
  62.             return $class->toString();
  63.         }
  64.         
  65.          
  66.         // first argument is always the plugin name; shift the first
  67.         // argument off the front of the array and reduce the number of
  68.         // array elements.
  69.         array_shift($args);
  70.         
  71.         return call_user_func_array(array(&$this->plugins[$class],$method), $args);
  72.     }
  73.     
  74.     /**
  75.     * Load the plugins, and lookup which one provides the required method 
  76.     *
  77.     * 
  78.     * @param   string           Name
  79.     *
  80.     * @return   string|PEAR_Error   the class that provides it.
  81.     * @access   private
  82.     */
  83.     
  84.     function _loadPlugins($name) 
  85.     {
  86.         // name can be:
  87.         // ahref = maps to {class_prefix}_ahref::ahref
  88.         $this->plugins = array();
  89.         if (empty($this->plugins)) {
  90.           
  91.             foreach ($this->flexy->options['plugins'] as $cname=>$file) {
  92.                 if (!is_int($cname)) {
  93.                     include_once $file;
  94.                     $this->plugins[$cname] = new $cname;
  95.                     $this->plugins[$cname]->flexy = &$this->flexy;
  96.                     continue;
  97.                 }
  98.                 $cname = $file;
  99.                 require_once 'HTML/Template/Flexy/Plugin/'. $cname . '.php';
  100.                 $class = "HTML_Template_Flexy_Plugin_{$cname}";
  101.                 $this->plugins[$class] = new $class;
  102.                 $this->plugins[$class]->flexy = &$this->flexy;
  103.             }
  104.         }
  105.                 
  106.         
  107.         foreach ($this->plugins as $class=>$o) {
  108.             //echo "checking :". get_class($o). ":: $name\n";
  109.             if (method_exists($o,$name)) {
  110.                 return $class;
  111.             }
  112.         }
  113.         return HTML_Template_Flexy::raiseError("could not find plugin with method: '$name'");
  114.     }
  115.     
  116.     
  117. }
  118.