HTML_Template_Flexy
[ class tree: HTML_Template_Flexy ] [ index: HTML_Template_Flexy ] [ all elements ]

Source for file Plugin.php

Documentation is available at Plugin.php

  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 334846 2014-09-12 04:50:56Z alan_k $
  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.     /**
  32.     * reference to main engine..
  33.     *
  34.     * @var object HTML_Template_Flexy 
  35.     * @access public
  36.     */
  37.     var $flexy// reference to flexy.
  38.     var $pluginCache = array()// store of instanced plugins..
  39.     
  40.     /**
  41.     * Call a Plugin method.
  42.     *
  43.     * Look up in all the plugins to see if the method exists, if it does, call it.
  44.     * 
  45.     * 
  46.     * @param   array        name of method, arguments.
  47.     * 
  48.     *
  49.     * @return   string      hopefully
  50.     * @access   public
  51.     */
  52.   
  53.     function call($args)
  54.     {
  55.         
  56.         
  57.         $method $args[0];
  58.         // attempt to load the plugin on-the-fly
  59.         $class $this->_loadPlugins($method);
  60.          
  61.         if (is_object($class&& is_a($class,'PEAR_Error')) {
  62.             //echo $class->toString();
  63.             return $class->toString();
  64.         }
  65.         
  66.          
  67.         // first argument is always the plugin name; shift the first
  68.         // argument off the front of the array and reduce the number of
  69.         // array elements.
  70.         array_shift($args);
  71.         
  72.         return call_user_func_array(array(&$this->plugins[$class],$method)$args);
  73.     }
  74.     
  75.     /**
  76.     * Load the plugins, and lookup which one provides the required method
  77.     *
  78.     * 
  79.     * @param   string           Name
  80.     *
  81.     * @return   string|PEAR_Error  the class that provides it.
  82.     * @access   private
  83.     */
  84.     
  85.     function _loadPlugins($name
  86.     {
  87.         // name can be:
  88.         // ahref = maps to {class_prefix}_ahref::ahref
  89.         $this->plugins = array();
  90.         if (empty($this->plugins)) {
  91.           
  92.             foreach ($this->flexy->options['plugins'as $cname=>$file{
  93.                 if (!is_int($cname)) {
  94.                     include_once $file;
  95.                     $this->plugins[$cname= new $cname;
  96.                     $this->plugins[$cname]->flexy = &$this->flexy;
  97.                     continue;
  98.                 }
  99.                 $cname $file;
  100.                 require_once 'HTML/Template/Flexy/Plugin/'$cname '.php';
  101.                 $class = "HTML_Template_Flexy_Plugin_{$cname}";
  102.                 $this->plugins[$class= new $class;
  103.                 $this->plugins[$class]->flexy = &$this->flexy;
  104.             }
  105.         }
  106.                 
  107.         
  108.         foreach ($this->plugins as $class=>$o{
  109.             //echo "checking :". get_class($o). ":: $name\n";
  110.             if (is_callable(array($o,$name),true)) {
  111.                 return $class;
  112.             }
  113.         }
  114.         return HTML_Template_Flexy::staticRaiseError("could not find plugin with method: '$name'");
  115.     }
  116.     
  117.     
  118. }

Documentation generated on Mon, 11 Mar 2019 15:59:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.