/**
  * Configuration method.
  *
  * In addition to configuring the settings (see $__defaults above for settings explanation),
  * this function also loops through the installed plugins and 'registers' those that have a
  * PluginNameCallback class.
  *
  * @param object $controller    Controller object
  * @param array $settings       Component settings
  * @access public
  * @return void
  */
 public function initialize(&$controller, $settings = array())
 {
     $this->__controller =& $controller;
     $this->settings = array_merge($this->__defaults, $settings);
     if (empty($this->settings['priority'])) {
         $this->settings['priority'] = Configure::listobjects('plugin');
     } else {
         foreach (Configure::listobjects('plugin') as $plugin) {
             if (!in_array($plugin, $this->settings['priority'])) {
                 array_push($this->settings['priority'], $plugin);
             }
         }
     }
     foreach ($this->settings['priority'] as $plugin) {
         $file = Inflector::underscore($plugin) . '_callback';
         $className = $plugin . 'Callback';
         if (App::import('File', $className, true, array(APP . 'plugins' . DS . Inflector::underscore($plugin)), $file . '.php')) {
             if (class_exists($className)) {
                 $class = new $className();
                 ClassRegistry::addObject($className, $class);
                 $this->__registered[] = $className;
             }
         }
     }
     /**
      * Called before the controller's beforeFilter method.
      */
     $this->executeCallbacks('initialize');
 }
Ejemplo n.º 2
0
 /**
  * Initializes component by loading all configuration files from 
  * all plugins found in application. Configuration files should be
  * placed in \app\plugins\your_plugin\config\ directory. Be careful,
  * it will overwrite all settings loaded from \app\config if the 
  * setting name matches.
  * At the end it will execute an 'initialize' callback method loaded
  * from \plugins\your_plugin\{your_plugin}_auto_loader.php file
  * 
  * @param object $controller - reference to the controller
  * @param array $settings - component settings, list of autoload files
  * @return void
  * @access public
  */
 function initialize(&$controller, $settings = array())
 {
     $this->__controller =& $controller;
     $this->__settings = Set::merge($this->__settings, $this->__settingsUnique((array) $settings));
     if (empty($this->__settings['priority'])) {
         $this->__settings['priority'] = Configure::listobjects('plugin');
     } else {
         foreach (Configure::listobjects('plugin') as $plugin) {
             if (!in_array($plugin, $this->__settings['priority'])) {
                 array_push($this->__settings['priority'], $plugin);
             }
         }
     }
     foreach ($this->__settings['priority'] as $plugin) {
         $is_parent_class = strpos(get_parent_class($controller), Inflector::classify($plugin)) !== false;
         if ($this->__settings['permanently'] || !$this->__settings['permanently'] && $is_parent_class) {
             foreach ($this->__settings['autoload'] as $type) {
                 App::import('Plugin', Inflector::classify("{$plugin}_{$type}"), array('file' => Inflector::underscore($plugin) . DS . 'config' . DS . $type . '.php'));
             }
         }
     }
     if ($this->__settings['primary']) {
         $ordering = $this->__controller->Component->_primary;
         $new_ordering[] = 'PluginHandler';
         foreach ($ordering as $component_name) {
             if (!in_array($component_name, $new_ordering)) {
                 $new_ordering[] = $component_name;
             }
         }
         $this->__controller->Component->_primary = $new_ordering;
     }
     $this->loaderExecute('initialize');
 }