Source for file Abstract.php

Documentation is available at Abstract.php

  1. <?php
  2. /**
  3.  *  Abstract.php
  4.  *
  5.  *  @author     Sotaro Karasawa <sotaro.k /at/ gmail.com>
  6.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  7.  *  @package    Ethna
  8.  *  @version    $Id: 5bffc18836afafdcd8ae8bf27031130333b74c3f $
  9.  */
  10.  
  11. // {{{ Ethna_Plugin_Abstract
  12. /**
  13.  *  The abstract class of all plugins.
  14.  *
  15.  *  @author     Sotaro Karasawa <sotaro.k /at/ gmail.com>
  16.  *  @access     public
  17.  *  @package    Ethna
  18.  */
  19. // abstract class Ethna_Plugin_Abstract
  20. abstract class Ethna_Plugin_Abstract
  21. {
  22.     /**#@+
  23.      *  @access private
  24.      */
  25.  
  26.     /** @protected    string  plugin type */
  27.     protected $type = null;
  28.  
  29.     /** @protected    string  plugin name */
  30.     protected $name = null;
  31.  
  32.     /** @protected    object  Ethna_Controller    Controller Object */
  33.     protected $controller;
  34.     protected $ctl/* Alias */
  35.  
  36.     /** @protected    object  Ethna_Backend       Backend Object */
  37.     protected $backend;
  38.  
  39.     /** @protected    object  Ethna_ActionForm    ActionForm Object */
  40.     protected $action_form;
  41.     protected $af/* Alias */
  42.  
  43.     /** @protected    object  Ethna_Session       Session Object */
  44.     protected $session;
  45.  
  46.     /** @protected    array   plugin configure */
  47.     protected $config;
  48.  
  49.     /** @protected    array   plugin configure for default */
  50.     protected $config_default = array();
  51.  
  52.     /** @protected    object  Ethna_Logger        Logger Object */
  53.     protected $logger;
  54.  
  55.     /**
  56.      *  Constructor
  57.      *
  58.      *  @access public
  59.      *  @param  object  Ethna_Controller    $controller    Controller Object
  60.      */
  61.     public function __construct($controller$type null$name null)
  62.     {
  63.         $this->controller = $controller;
  64.         $this->ctl = $this->controller;
  65.  
  66.         $this->backend = $this->controller->getBackend();
  67.  
  68.         $this->logger = $controller->getLogger();
  69.  
  70.         $this->action_form = $controller->getActionForm();
  71.         $this->af = $this->action_form;
  72.  
  73.         $this->session = $controller->getSession();
  74.  
  75.         // if constractor called without parameter $type or $name, auto detect type and name of self.
  76.         if ($this->type === null{
  77.             $this->type = $this->_detectType($type);
  78.         }
  79.  
  80.         if ($this->name === null{
  81.             $this->name = $this->_detectName($name);
  82.         }
  83.  
  84.         // load config
  85.         $this->_loadConfig();
  86.  
  87.         // load plugin hook
  88.         $this->_load();
  89.     }
  90.  
  91.     /**
  92.      *  getType
  93.      *
  94.      *  @access public
  95.      */
  96.     public function getType()
  97.     {
  98.         return $this->type;
  99.     }
  100.  
  101.     /**
  102.      *  getType
  103.      *
  104.      *  @access public
  105.      */
  106.     public function getName()
  107.     {
  108.         return $this->name;
  109.     }
  110.  
  111.     /**
  112.      *  getConfig
  113.      *
  114.      *  @return array   $config
  115.      */
  116.     public function getConfig()
  117.     {
  118.         return $this->config;
  119.     }
  120.  
  121.     /**
  122.      *  _load
  123.      *
  124.      *  @access protected
  125.      */
  126.     protected function _load()
  127.     {
  128.     }
  129.  
  130.     /**
  131.      *  _loadConfig
  132.      *
  133.      *  @access protected
  134.      */
  135.     protected function _loadConfig()
  136.     {
  137.         $config $this->ctl->getConfig();
  138.         $plugin_config $config->get('plugin');
  139.  
  140.         if ($plugin_config === null || !isset($plugin_config[$this->type])
  141.             || ($this->name !== null && !isset($plugin_config[$this->type][$this->name]))) {
  142.             $this->config = $this->config_default;
  143.         }
  144.         else {
  145.             if ($this->name === null{
  146.                 $this->config = array_merge($this->config_default$plugin_config[$this->type]);
  147.             }
  148.             else {
  149.  
  150.                 $this->config = array_merge($this->config_default$plugin_config[$this->type][$this->name]);
  151.             }
  152.         }
  153.  
  154.         return true;
  155.     }
  156.  
  157.     /**
  158.      *  _detectType
  159.      *
  160.      *  @access protected
  161.      */
  162.     protected function _detectType($type null)
  163.     {
  164.         if ($type !== null{
  165.             return strtolower($type);
  166.         }
  167.  
  168.         $type array_shift(explode("_"str_replace("Ethna_Plugin_""",  get_class($this))));
  169.         if ($type !== ""{
  170.             return strtolower($type);
  171.         }
  172.         else {
  173.             return null;
  174.         }
  175.     }
  176.  
  177.     /**
  178.      *  _detectName
  179.      *
  180.      *  @access protected
  181.      */
  182.     protected function _detectName($name null)
  183.     {
  184.         if ($name !== null{
  185.             return strtolower($name);
  186.         }
  187.  
  188.         $name explode("_"str_replace("Ethna_Plugin_"""get_class($this)));
  189.         if (count($name=== 2{
  190.             return strtolower($name[1]);
  191.         }
  192.         else {
  193.             return null;
  194.         }
  195.     }
  196. }

Documentation generated on Fri, 11 Nov 2011 03:57:15 +0900 by phpDocumentor 1.4.3