예제 #1
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $filters =& $this->_getExtension('filters');
     if (!is_array($filters)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ filters ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     while (ob_get_level()) {
         ob_end_clean();
     }
     foreach ($filters as $extension) {
         /*
          * All output filters must have the signature as follows.
          *
          * @param string $buffer
          * @return string
          */
         if (!function_exists($extension)) {
             $filter =& Piece_Unity_Plugin_Factory::factory($extension);
             if (Piece_Unity_Error::hasErrors()) {
                 return;
             }
             ob_start(array(&$filter, 'invoke'));
         } else {
             ob_start($extension);
         }
     }
 }
예제 #2
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $interceptors =& $this->_getExtension('interceptors');
     if (!is_array($interceptors)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ interceptors ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach ($interceptors as $extension) {
         $interceptor =& Piece_Unity_Plugin_Factory::factory($extension);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         /*
          * Stops the invocation of the interceptors if an interceptor
          * returns false.
          *
          * @return boolean
          */
         $doContinue = $interceptor->invoke();
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         if (!$doContinue) {
             break;
         }
     }
 }
예제 #3
0
 /**
  * Sets a status code.
  *
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @param integer $statusCode
  */
 function Piece_Unity_HTTPStatus($statusCode)
 {
     if (!array_key_exists($statusCode, $this->_statusCodes)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "Unknown status code [ {$statusCode} ], be sure the status code is correct.");
         return;
     }
     $this->_statusCode = $statusCode;
 }
 /**
  * @param string $requiredPermission
  * @return boolean
  */
 function _authenticate($requiredPermission)
 {
     if (!$GLOBALS['PIECE_UNITY_Plugin_Interceptor_AuthorizationTestCase_hasPermission']) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED);
         return;
     }
     return true;
 }
예제 #5
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function invoke()
 {
     $appRoot = $this->_getConfiguration('appRoot');
     if (!is_null($appRoot)) {
         $result = chdir($appRoot);
         if (!$result) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed calling chdir() for the configuration point [ appRoot ] on the plugin [ {$this->_name} ].");
             return;
         }
     }
     $appRootPath = $this->_getConfiguration('appRootPath');
     if (!is_null($appRootPath)) {
         $this->_context->setAppRootPath($appRootPath);
     }
 }
예제 #6
0
 /**
  * Determines appropriate renderer extension by the view scheme in the current
  * view string such like "http:", "json:", "html:", etc.
  *
  * @return string
  * @throws PIECE_UNITY_ERROR_UNEXPECTED_VALUE
  */
 function invoke()
 {
     $viewString = $this->_context->getView();
     $positionOfColon = strpos($viewString, ':');
     if ($positionOfColon === 0) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_UNEXPECTED_VALUE, "The view string [ {$viewString} ] should not start with colon.");
         return;
     }
     $viewScheme = !$positionOfColon ? 'html' : substr($viewString, 0, $positionOfColon);
     $rendererExtension = $this->_getConfiguration($viewScheme);
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $this->_context->setView(preg_replace('/^html:/', '', $viewString));
     return $rendererExtension;
 }
예제 #7
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $configurators =& $this->_getExtension('configurators');
     if (!is_array($configurators)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ configurators ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach (array_merge($this->_requiredConfigurators, $configurators) as $extension) {
         $configurator =& Piece_Unity_Plugin_Factory::factory($extension);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $configurator->invoke();
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
     }
 }
예제 #8
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;
 }
예제 #9
0
 /**
  * Renders a HTML or HTML fragment.
  *
  * @param string                  $file
  * @param Piece_Unity_ViewElement &$viewElement
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @throws PIECE_UNITY_ERROR_CANNOT_READ
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function render($file, &$viewElement)
 {
     if (!file_exists($file)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The HTML template file [ {$file} ] is not found.");
         return;
     }
     if (!is_readable($file)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_CANNOT_READ, "The HTML template file [ {$file} ] is not readable.");
         return;
     }
     $this->_fileForRender = $file;
     $this->_viewElementForRender =& $viewElement;
     extract($this->_viewElementForRender->getElements(), EXTR_OVERWRITE | EXTR_REFS);
     if (!(include $this->_fileForRender)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "The HTML template file [ {$this->_fileForRender} ] is not found or is not readable.");
     }
 }
예제 #10
0
 /**
  * Creates a new Piece_Flow_Continuation_Server object and configure it.
  *
  * @return Piece_Flow_Continuation_Server
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function &_createContinuationServer()
 {
     $continuationServer =& new Piece_Flow_Continuation_Server($this->_getConfiguration('enableSingleFlowMode'), $this->_getConfiguration('enableGC'), $this->_getConfiguration('gcExpirationTime'));
     $continuationServer->setCacheDirectory($this->_getConfiguration('cacheDirectory'));
     $continuationServer->setEventNameCallback(array(__CLASS__, 'getEventName'));
     $continuationServer->setFlowExecutionTicketCallback(array(__CLASS__, 'getFlowExecutionTicket'));
     $continuationServer->setFlowIDCallback(array(__CLASS__, 'getFlowID'));
     if ($this->_getConfiguration('useFlowMappings')) {
         $continuationServer->setConfigDirectory($this->_getConfiguration('configDirectory'));
         $continuationServer->setConfigExtension($this->_getConfiguration('configExtension'));
         foreach ($this->_getConfiguration('flowMappings') as $flowMapping) {
             if (array_key_exists('url', $flowMapping)) {
                 $flowMapping['uri'] = $flowMapping['url'];
             }
             Piece_Flow_Error::disableCallback();
             $continuationServer->addFlow($flowMapping['uri'], $flowMapping['flowName'], $flowMapping['isExclusive']);
             Piece_Flow_Error::enableCallback();
             if (Piece_Flow_Error::hasErrors()) {
                 Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "Failed to configure the plugin [ {$this->_name}.", 'exception', array(), Piece_Flow_Error::pop());
                 $return = null;
                 return $return;
             }
         }
     } else {
         foreach ($this->_getConfiguration('flowDefinitions') as $flowDefinition) {
             Piece_Flow_Error::disableCallback();
             $continuationServer->addFlow($flowDefinition['name'], $flowDefinition['file'], $flowDefinition['isExclusive']);
             Piece_Flow_Error::enableCallback();
             if (Piece_Flow_Error::hasErrors()) {
                 Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "Failed to configure the plugin [ {$this->_name}.", 'exception', array(), Piece_Flow_Error::pop());
                 $return = null;
                 return $return;
             }
         }
     }
     return $continuationServer;
 }
예제 #11
0
 /**
  * Merges the given validation set into the Piece_Right_Config object for
  * the current validation.
  *
  * @param string $validationSetName
  * @param string $configDirectory
  * @param string $cacheDirectory
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  * @since Method available since Release 1.3.0
  */
 function mergeValidationSet($validationSetName, $configDirectory = null, $cacheDirectory = null)
 {
     if (is_null($configDirectory)) {
         $configDirectory = $this->_configDirectory;
     }
     if (is_null($cacheDirectory)) {
         $cacheDirectory = $this->_cacheDirectory;
     }
     Piece_Right_Error::disableCallback();
     $config =& Piece_Right_Config_Factory::factory($validationSetName, $configDirectory, $cacheDirectory, $this->_template);
     Piece_Right_Error::enableCallback();
     if (Piece_Right_Error::hasErrors()) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke Piece_Right_Validation_Script::mergeValidationSet() for any reasons.', 'exception', array(), Piece_Right_Error::pop());
         return;
     }
     if (is_null($this->_config)) {
         $this->_config =& new Piece_Right_Config();
     }
     $this->_config->merge($config);
 }
예제 #12
0
 /**
  * Invokes the plugin specific code.
  *
  * @return boolean
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $this->_prepareAuthenticationState();
     $uri = $this->_getConfiguration('uri');
     if (!$uri) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ uri ] on the plug-in [ {$this->_name} ] is required.");
         return;
     }
     if ($this->_isAuthenticationURI($uri)) {
         return true;
     }
     $excludes = $this->_getConfiguration('excludes');
     if ($excludes) {
         if (!is_array($excludes)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ excludes ] on the plug-in [ {$this->_name} ] should be an array.");
             return;
         }
         foreach ($excludes as $exclude) {
             if (preg_match("!{$exclude}!", $this->_scriptName)) {
                 return true;
             }
         }
     }
     $isProtectedResource = false;
     $includes = $this->_getConfiguration('includes');
     if ($includes) {
         if (!is_array($includes)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ includes ] on the plug-in [ {$this->_name} ] should be an array.");
             return;
         }
         foreach ($includes as $include) {
             if (preg_match("!{$include}!", $this->_scriptName)) {
                 $isProtectedResource = true;
                 break;
             }
         }
     }
     if (!$isProtectedResource) {
         $resources = $this->_getConfiguration('resources');
         if ($resources) {
             if (!is_array($resources)) {
                 Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ resources ] on the plug-in [ {$this->_name} ] should be an array.");
                 return;
             }
             $isProtectedResource = in_array($this->_scriptName, $resources);
         }
     }
     $session =& $this->_context->getSession();
     $session->setPreloadCallback('_Interceptor_Authentication_StateLoader', array(__CLASS__, 'loadAuthenticationState'));
     $session->addPreloadClass('_Interceptor_Authentication_StateLoader', 'Piece_Unity_Service_Autentication_State');
     if (!$isProtectedResource) {
         return true;
     }
     $realm = $this->_getConfiguration('realm');
     if ($this->_authenticationState->isAuthenticated($realm)) {
         if ($this->_authenticationState->hasCallbackURI($realm)) {
             $this->_authenticationState->removeCallbackURI($realm);
         }
         return true;
     } else {
         $this->_storeRequestedURI($realm);
         $this->_context->setView($uri);
         return false;
     }
 }
예제 #13
0
 /**
  * Adds a PHP error to the stack for the package.
  *
  * @param integer $code
  * @param string  $message
  * @param string  $file
  * @param integer $line
  * @throws PIECE_UNITY_ERROR_PHP_ERROR
  * @deprecated Method deprecated in Release 1.5.0
  */
 function pushPHPError($code, $message, $file, $line)
 {
     $errorReporting = error_reporting();
     if (!($errorReporting & $code)) {
         return;
     }
     switch ($code) {
         case E_STRICT:
         case E_WARNING:
         case E_USER_WARNING:
         case E_NOTICE:
         case E_USER_NOTICE:
             return;
         case E_USER_ERROR:
         default:
             break;
     }
     $time = explode(' ', microtime());
     $time = $time[1] + $time[0];
     Piece_Unity_Error::push(PIECE_UNITY_ERROR_PHP_ERROR, 'A PHP error raised.', 'exception', array(), array('code' => $code, 'message' => $message, 'params' => array(), 'package' => 'PHP', 'level' => 'exception', 'time' => $time, 'context' => array('file' => $file, 'line' => $line)), debug_backtrace());
 }
예제 #14
0
 /**
  * Removes a name/value pair from the query string.
  *
  * @param string $name
  * @since Method available since Release 0.11.0
  * @throws PIECE_UNITY_ERROR_INVALID_OPERATION
  */
 function removeQueryString($name)
 {
     if (is_null($this->_url)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_OPERATION, __FUNCTION__ . ' method must be called after initializing.');
         return;
     }
     $this->_url->removeQueryString($name);
 }
예제 #15
0
 /**
  * Sets filter prefixes.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function _setFilterPrefixes()
 {
     $filterPrefixes = $this->_getConfiguration('filterPrefixes');
     if (!is_array($filterPrefixes)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ filterPrefixes ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach (array_reverse($filterPrefixes) as $filterPrefix) {
         Piece_Unity_Validation::addFilterPrefix($filterPrefix);
     }
 }
예제 #16
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $configDirectory = $this->_getConfiguration('configDirectory');
     if (is_null($configDirectory)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ configDirectory ] on the plug-in [ {$this->_name} ] is required.");
         return;
     }
     $cacheDirectory = $this->_getConfiguration('cacheDirectory');
     if (is_null($cacheDirectory)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ cacheDirectory ] on the plug-in [ {$this->_name} ] is required.");
         return;
     }
     $mapperConfigDirectory = $this->_getConfiguration('mapperConfigDirectory');
     if (is_null($mapperConfigDirectory)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ mapperConfigDirectory ] on the plug-in [ {$this->_name} ] is required.");
         return;
     }
     Piece_ORM::configure($configDirectory, $cacheDirectory, $mapperConfigDirectory);
 }
예제 #17
0
 /**
  * Renders a HTML.
  *
  * @param boolean $isLayout
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function _doRender($isLayout)
 {
     if (!defined('SMARTY_DIR')) {
         $SMARTY_DIR = $this->_getConfiguration('SMARTY_DIR');
         if (!is_null($SMARTY_DIR)) {
             define('SMARTY_DIR', Piece_Unity_Service_Rendering_Smarty::_adjustEndingSlash($SMARTY_DIR));
         }
     }
     foreach (array_keys($this->_smartyClassVariables) as $smartyClassVariable) {
         $this->_smartyClassVariables[$smartyClassVariable] = $this->_getConfiguration($smartyClassVariable);
     }
     if (!$isLayout) {
         $view = $this->_context->getView();
     } else {
         $layoutDirectory = $this->_getConfiguration('layoutDirectory');
         if (!is_null($layoutDirectory)) {
             $this->_smartyClassVariables['template_dir'] = $layoutDirectory;
         }
         $layoutCompileDirectory = $this->_getConfiguration('layoutCompileDirectory');
         if (!is_null($layoutCompileDirectory)) {
             $this->_smartyClassVariables['compile_dir'] = $layoutCompileDirectory;
         }
         $view = $this->_getConfiguration('layoutView');
     }
     $file = str_replace('_', '/', str_replace('.', '', $view)) . $this->_getConfiguration('templateExtension');
     $viewElement =& $this->_context->getViewElement();
     $rendering =& new Piece_Unity_Service_Rendering_Smarty($this->_smartyClassVariables);
     $rendering->render($file, $viewElement);
     if (Piece_Unity_Error::hasErrors()) {
         $error = Piece_Unity_Error::pop();
         if ($error['code'] == PIECE_UNITY_ERROR_NOT_FOUND) {
             Piece_Unity_Error::push('PIECE_UNITY_PLUGIN_RENDERER_HTML_ERROR_NOT_FOUND', $error['message'], 'exception', array(), $error);
             return;
         }
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed to invoke the plugin [ {$this->_name} ].", 'exception', array(), $error);
     }
 }
예제 #18
0
 /**
  * Invokes the plugin specific code.
  *
  * @return boolean
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $excludes = $this->_getConfiguration('excludes');
     if (!is_array($excludes)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ excludes ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     $scriptName = $this->_context->removeProxyPath($this->_context->getScriptName());
     foreach ($excludes as $exclude) {
         if (preg_match("!{$exclude}!", $scriptName)) {
             return true;
         }
     }
     $permissions = $this->_getConfiguration('permissions');
     if (!is_array($permissions)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ permissions ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     $requiredPermission = null;
     foreach ($permissions as $uri => $permission) {
         if (preg_match("!{$uri}!", $scriptName)) {
             $requiredPermission = $permission;
             break;
         }
     }
     if (is_null($requiredPermission)) {
         return true;
     }
     return $this->_authenticate($requiredPermission);
 }
예제 #19
0
 /**
  * Renders a HTML.
  *
  * @param boolean $isLayout
  */
 function _doRender($isLayout)
 {
     $templateDirectory = $this->_getConfiguration('templateDirectory');
     if (!$isLayout) {
         $view = $this->_context->getView();
     } else {
         $layoutDirectory = $this->_getConfiguration('layoutDirectory');
         if (!is_null($layoutDirectory)) {
             $templateDirectory = $layoutDirectory;
         }
         $view = $this->_getConfiguration('layoutView');
     }
     if (is_null($templateDirectory)) {
         return;
     }
     $file = "{$templateDirectory}/" . str_replace('_', '/', str_replace('.', '', $view)) . $this->_getConfiguration('templateExtension');
     $viewElement =& $this->_context->getViewElement();
     $rendering =& new Piece_Unity_Service_Rendering_PHP();
     $rendering->render($file, $viewElement);
     if (Piece_Unity_Error::hasErrors()) {
         $error = Piece_Unity_Error::pop();
         Piece_Unity_Error::push('PIECE_UNITY_PLUGIN_RENDERER_HTML_ERROR_NOT_FOUND', $error['message'], 'exception', array(), $error);
     }
 }
예제 #20
0
 /**
  * Sets a callback as a JSON encoder.
  *
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  */
 function _setEncoderCallback()
 {
     if (!$this->_getConfiguration('useHTMLAJAX')) {
         if (!extension_loaded('json')) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, 'json extension not loaded. Please check PHP configuration.');
             return;
         }
         $this->_encoderCallback = 'json_encode';
     } else {
         if (!(include_once 'HTML/AJAX/JSON.php')) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, 'The file [ HTML/AJAX/JSON.php ] not found or is not readable.');
             return;
         }
         $this->_encoderCallback = array(__CLASS__, 'encodeWithHTMLAJAX');
     }
 }
예제 #21
0
 /**
  * Makes a list of non-SSLable servers.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function _setNonSSLableServers()
 {
     $nonSSLableServers = $this->_getConfiguration('nonSSLableServers');
     if (!is_array($nonSSLableServers)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ nonSSLableServers ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach ($nonSSLableServers as $nonSSLableServer) {
         Piece_Unity_URI::addNonSSLableServer($nonSSLableServer);
     }
 }
예제 #22
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);
     }
 }
예제 #23
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;
     }
 }
예제 #24
0
 /**
  * Validates whether all configuration points in the current
  * configuration can be found in the given plug-in.
  *
  * @param string $plugin
  * @param array  $configurationPoints
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @since Method available since Release 1.1.0
  */
 function validateConfigurationPoints($plugin, $configurationPoints)
 {
     $plugin = strtolower($plugin);
     if (!array_key_exists($plugin, $this->_configurations)) {
         return;
     }
     foreach (array_keys($this->_configurations[$plugin]) as $configurationPoint) {
         if (!in_array($configurationPoint, $configurationPoints)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The configuration point [ {$configurationPoint} ] is not found in the plug-in [ {$plugin} ].");
             return;
         }
     }
 }
예제 #25
0
 /**
  * Creates a Piece_Unity_Config object from a configuration file or
  * a cache.
  *
  * @param string $configDirectory
  * @param string $cacheDirectory
  * @return Piece_Unity_Config
  * @static
  */
 function &factory($configDirectory = null, $cacheDirectory = null)
 {
     if (is_null($configDirectory)) {
         $config =& new Piece_Unity_Config();
         return $config;
     }
     if (!file_exists($configDirectory)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The configuration directory [ {$configDirectory} ] is not found.");
         $return = null;
         return $return;
     }
     $configFile = "{$configDirectory}/piece-unity-config.yaml";
     if (!file_exists($configFile)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The configuration file [ {$configFile} ] is not found.");
         $return = null;
         return $return;
     }
     if (!is_readable($configFile)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_READABLE, "The configuration file [ {$configFile} ] is not readable.");
         $return = null;
         return $return;
     }
     if (is_null($cacheDirectory)) {
         return Piece_Unity_Config_Factory::_getConfigurationFromFile($configFile);
     }
     if (!file_exists($cacheDirectory)) {
         trigger_error("The cache directory [ {$cacheDirectory} ] is not found.", E_USER_WARNING);
         return Piece_Unity_Config_Factory::_getConfigurationFromFile($configFile);
     }
     if (!is_readable($cacheDirectory) || !is_writable($cacheDirectory)) {
         trigger_error("The cache directory [ {$cacheDirectory} ] is not readable or writable.", E_USER_WARNING);
         return Piece_Unity_Config_Factory::_getConfigurationFromFile($configFile);
     }
     return Piece_Unity_Config_Factory::_getConfiguration($configFile, $cacheDirectory);
 }
예제 #26
0
 /**
  * Loads a class.
  *
  * @param string $class
  * @param string $directory
  * @throws PIECE_UNITY_ERROR_NOT_READABLE
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @throws PIECE_UNITY_ERROR_CANNOT_READ
  * @static
  */
 function load($class, $directory = null)
 {
     $file = str_replace('_', '/', $class) . '.php';
     if (!is_null($directory)) {
         $file = "{$directory}/{$file}";
         if (!file_exists($file)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The class file [ {$file} ] for the class [ {$class} ] is not found.");
             return;
         }
         if (!is_readable($file)) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_READABLE, "The class file [ {$file} ] is not readable.");
             return;
         }
     }
     if (!(include_once $file)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_CANNOT_READ, "The class file [ {$file} ] is not found or is not readable.");
     }
 }
예제 #27
0
 /**
  * Gets the configuration of the given configuration point.
  *
  * @param string $configurationPoint
  * @return string
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @since Method available since Release 0.12.0
  */
 function _getConfiguration($configurationPoint)
 {
     $configurationPoint = strtolower($configurationPoint);
     if (!array_key_exists($configurationPoint, $this->_configurationPoints)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The configuration point  [ {$configurationPoint} ] is not found in the plug-in [ {$this->_name} ].", 'exception', false, false, debug_backtrace());
         return;
     }
     $config =& $this->_context->getConfiguration();
     $configuration = $config->getConfiguration($this->_name, $configurationPoint);
     if (is_null($configuration)) {
         $configuration = $this->_configurationPoints[$configurationPoint];
     }
     return $configuration;
 }
예제 #28
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];
 }
예제 #29
0
 /**
  * Sets the extension to the extension point of the plugin.
  *
  * @param string $plugin
  * @param string $extensionPoint
  * @param string $extension
  * @throws PIECE_UNITY_ERROR_INVALID_OPERATION
  * @since Method available since Release 1.1.0
  */
 function setExtension($plugin, $extensionPoint, $extension)
 {
     if (is_null($this->_config)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_OPERATION, __FUNCTION__ . ' method must be called after calling configure().');
         return;
     }
     $this->_config->setExtension($plugin, $extensionPoint, $extension);
 }
예제 #30
0
 /**
  * Renders a HTML.
  * If an error occured while rendering with a specified view and
  * useFallback is true, a fallback view will be rendered.
  *
  * @param boolean $isLayout
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function _render($isLayout)
 {
     Piece_Unity_Error::disableCallback();
     $this->_doRender($isLayout);
     Piece_Unity_Error::enableCallback();
     if (!Piece_Unity_Error::hasErrors()) {
         return;
     }
     $error = Piece_Unity_Error::pop();
     if ($error['code'] == 'PIECE_UNITY_PLUGIN_RENDERER_HTML_ERROR_NOT_FOUND') {
         trigger_error("Failed to render a HTML template with the plugin [ {$this->_name} ].", E_USER_WARNING);
         var_dump($this->_context->getView());
         if ($this->_getConfiguration('useFallback')) {
             $this->_context->setView($this->_getConfiguration('fallbackView'));
             $this->_prepareFallback();
             $this->_doRender($isLayout);
             return;
         }
     } else {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed to render a HTML template with the plugin [ {$this->_name} ].", 'exception', array(), $error);
     }
 }