コード例 #1
0
ファイル: Plugin.php プロジェクト: robzienert/Drake
 /**
  * Initialize the resource
  *
  * @return Drake_Event_Dispatcher
  */
 public function init()
 {
     $dispatcher = new Drake_Event_Dispatcher();
     Drake_Plugin::setDefaultDispatcher($dispatcher);
     $options = $this->getOptions();
     if (!isset($options['path'])) {
         throw new Drake_Application_Resource_InvalidArgumentException('Plugin path must be provided');
     }
     $namespace = 'Plugin';
     if (isset($options['namespace'])) {
         $namespace = $options['namespace'];
     }
     $dir = new DirectoryIterator($options['path']);
     foreach ($dir as $file) {
         if ($file->isFile() && substr($file->getFilename(), -4, 4) == '.php') {
             $class = $namespace . '_' . $this->_formatPluginName(substr($file->getFilename(), 0, -4));
             include_once $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
             if (!class_exists($class)) {
                 throw new Drake_Appication_Resource_RuntimeException("Plugin file '{$file->getFilename()}' is found, but '{$class}' does not exist.");
             }
             // Initialize the plugin
             new $class();
         }
     }
     return $dispatcher;
 }
コード例 #2
0
ファイル: Plugin.php プロジェクト: robzienert/Drake
 /**
  * Set the default event dispatcher
  *
  * @param Drake_Event_Dispatcher $dispatcher
  */
 public static function setDefaultDispatcher(Drake_Event_Dispatcher $dispatcher)
 {
     self::$_defaultDispatcher = $dispatcher;
 }