Ejemplo n.º 1
0
 /**
  * Invokes the plugin specific code.
  *
  * @return string
  * @throws Piece_Unity_Exception
  */
 public function invoke()
 {
     $eventName = $this->context->getEventName();
     if ($this->useDefaultEvent) {
         if (is_null($eventName) || !strlen($eventName)) {
             $eventName = $this->defaultEventName;
             $this->context->setEventName($eventName);
         }
     }
     $class = str_replace('.', '', $eventName . 'Action');
     if (is_null($this->actionDirectory)) {
         return $eventName;
     }
     if (!Piece_Unity_ClassLoader::loaded($class)) {
         try {
             Piece_Unity_ClassLoader::load($class, $this->actionDirectory);
         } catch (Piece_Unity_ClassLoader_NotFoundException $e) {
             return $eventName;
         }
         if (!Piece_Unity_ClassLoader::loaded($class)) {
             throw new Piece_Unity_Exception('The class [ ' . $class . ' ] is not found in the loaded file');
         }
     }
     $action = new $class();
     if (!method_exists($action, 'invoke')) {
         throw new Piece_Unity_Exception('The method invoke() is not found in the class [ ' . $class . ' ]');
     }
     $viewString = $action->invoke($this->context);
     if (is_null($viewString)) {
         return $eventName;
     } else {
         return $viewString;
     }
 }
Ejemplo n.º 2
0
 /**
  * Invokes the plugin specific code.
  *
  * @return string
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @throws PIECE_UNITY_ERROR_CANNOT_READ
  */
 function invoke()
 {
     $eventName = $this->_context->getEventName();
     if ($this->_getConfiguration('useDefaultEvent')) {
         if (is_null($eventName) || !strlen($eventName)) {
             $eventName = $this->_getConfiguration('defaultEventName');
             $this->_context->setEventName($eventName);
         }
     }
     $class = str_replace('.', '', "{$eventName}Action");
     $actionDirectory = $this->_getConfiguration('actionDirectory');
     if (is_null($actionDirectory)) {
         return $eventName;
     }
     if (!Piece_Unity_ClassLoader::loaded($class)) {
         Piece_Unity_Error::disableCallback();
         Piece_Unity_ClassLoader::load($class, $actionDirectory);
         Piece_Unity_Error::enableCallback();
         if (Piece_Unity_Error::hasErrors()) {
             $error = Piece_Unity_Error::pop();
             if ($error['code'] == PIECE_UNITY_ERROR_NOT_FOUND) {
                 return $eventName;
             }
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_CANNOT_READ, "Failed to read the action class [ {$class} ] for any reasons.", 'exception', array(), $error);
             return;
         }
         if (!Piece_Unity_ClassLoader::loaded($class)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The class [ {$class} ] is not found in the loaded file.");
             return;
         }
     }
     $action =& new $class();
     if (!method_exists($action, 'invoke')) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The method invoke() is not found in the class [ {$class} ].");
         return;
     }
     $viewString = $action->invoke($this->_context);
     if (is_null($viewString)) {
         return $eventName;
     } else {
         return $viewString;
     }
 }
Ejemplo n.º 3
0
 /**
  * Starts a new session or restores a session if it already exists, and
  * binds the attribute holder to the $_SESSION superglobal array.
  *
  * @throws Piece_Unity_Exception
  */
 public function start()
 {
     foreach (self::$_autoloadClasses as $class) {
         if (Piece_Unity_ClassLoader::loaded($class)) {
             continue;
         }
         Piece_Unity_ClassLoader::load($class);
         if (!Piece_Unity_ClassLoader::loaded($class)) {
             throw new Piece_Unity_Exception('The class [ ' . $class . ' ] is not found in the loaded file');
         }
     }
     @session_start();
     $this->_attributes =& $_SESSION;
     if ($this->hasAttribute('_Piece_Unity_Session_Preload')) {
         $this->_preload = $this->getAttribute('_Piece_Unity_Session_Preload');
     } else {
         $this->_preload = new Piece_Unity_Session_Preload();
         $this->setAttribute('_Piece_Unity_Session_Preload', $this->_preload);
     }
 }
Ejemplo n.º 4
0
 /**
  * Creates a user-defined object used as a controller object by
  * HTML_Template_Flexy::outputObject().
  *
  * @return mixed
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  */
 function &_createController()
 {
     $controllerDirectory = $this->_getConfiguration('controllerDirectory');
     if (is_null($controllerDirectory)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ controllerDirectory ] on the plug-in [ {$this->_name} ] is required.");
         $return = null;
         return $return;
     }
     $controllerClass = $this->_getConfiguration('controllerClass');
     if (is_null($controllerClass)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ controllerClass ] on the plug-in [ {$this->_name} ] is required.");
         $return = null;
         return $return;
     }
     if (!Piece_Unity_ClassLoader::loaded($controllerClass)) {
         Piece_Unity_ClassLoader::load($controllerClass, $controllerDirectory);
         if (Piece_Unity_Error::hasErrors()) {
             $return = null;
             return $return;
         }
         if (!Piece_Unity_ClassLoader::loaded($controllerClass)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The class [ {$controllerClass} ] not found in the loaded file.");
             $return = null;
             return $return;
         }
     }
     $controller =& new $controllerClass();
     return $controller;
 }
Ejemplo n.º 5
0
 /**
  * Creates a plugin object from the plugin directories.
  *
  * @param string $pluginName
  * @return mixed
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @throws PIECE_UNITY_ERROR_INVALID_PLUGIN
  * @throws PIECE_UNITY_ERROR_CANNOT_READ
  */
 function &factory($pluginName)
 {
     if (!array_key_exists($pluginName, $GLOBALS['PIECE_UNITY_Plugin_Instances'])) {
         $found = false;
         foreach ($GLOBALS['PIECE_UNITY_Plugin_Prefixes'] as $prefixAlias) {
             $pluginClass = Piece_Unity_Plugin_Factory::_getPluginClass($pluginName, $prefixAlias);
             if (Piece_Unity_ClassLoader::loaded($pluginClass)) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             foreach ($GLOBALS['PIECE_UNITY_Plugin_Directories'] as $pluginDirectory) {
                 foreach ($GLOBALS['PIECE_UNITY_Plugin_Prefixes'] as $prefixAlias) {
                     $pluginClass = Piece_Unity_Plugin_Factory::_getPluginClass($pluginName, $prefixAlias);
                     Piece_Unity_Error::disableCallback();
                     Piece_Unity_ClassLoader::load($pluginClass, $pluginDirectory);
                     Piece_Unity_Error::enableCallback();
                     if (Piece_Unity_Error::hasErrors()) {
                         $error = Piece_Unity_Error::pop();
                         if ($error['code'] == PIECE_UNITY_ERROR_NOT_FOUND) {
                             continue;
                         }
                         Piece_Unity_Error::push(PIECE_UNITY_ERROR_CANNOT_READ, "Failed to read the plugin [ {$pluginName} ] for any reasons.", 'exception', array(), $error);
                         $return = null;
                         return $return;
                     }
                     if (Piece_Unity_ClassLoader::loaded($pluginClass)) {
                         $found = true;
                         break 2;
                     }
                 }
             }
             if (!$found) {
                 Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The plugin [ {$pluginName} ] is not found in the following directories:\n" . implode("\n", $GLOBALS['PIECE_UNITY_Plugin_Directories']));
                 $return = null;
                 return $return;
             }
         }
         $plugin =& new $pluginClass($prefixAlias);
         if (Piece_Unity_Error::hasErrors()) {
             $return = null;
             return $return;
         }
         if (!is_subclass_of($plugin, 'Piece_Unity_Plugin_Common')) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_PLUGIN, "The plugin [ {$pluginName} ] is invalid.");
             $return = null;
             return $return;
         }
         $GLOBALS['PIECE_UNITY_Plugin_Instances'][$pluginName] =& $plugin;
     }
     return $GLOBALS['PIECE_UNITY_Plugin_Instances'][$pluginName];
 }
Ejemplo n.º 6
0
 /**
  * Starts a new session or restores a session if it already exists, and
  * binds the attribute holder to the $_SESSION superglobal array.
  *
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  */
 function start()
 {
     foreach ($GLOBALS['PIECE_UNITY_Session_Autoload_Classes'] as $class) {
         if (Piece_Unity_ClassLoader::loaded($class)) {
             continue;
         }
         Piece_Unity_ClassLoader::load($class);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         if (!Piece_Unity_ClassLoader::loaded($class)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The class [ {$class} ] is not found in the loaded file.");
             return;
         }
     }
     session_start();
     $this->_attributes =& $_SESSION;
     if ($this->hasAttribute('_Piece_Unity_Session_Preload')) {
         $this->_preload =& $this->getAttribute('_Piece_Unity_Session_Preload');
     } else {
         $this->_preload =& new Piece_Unity_Session_Preload();
         $this->setAttributeByRef('_Piece_Unity_Session_Preload', $this->_preload);
     }
 }