コード例 #1
0
ファイル: Plugin.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  */
 function invoke()
 {
     $this->_setPluginDirectories();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $this->_setPluginPrefixes();
 }
コード例 #2
0
 /**
  * Invokes the plugin specific code.
  *
  * @return boolean
  */
 function invoke()
 {
     $session =& $this->_context->getSession();
     $session->start();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     return true;
 }
コード例 #3
0
ファイル: Session.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  *
  * @return boolean
  */
 function invoke()
 {
     $session =& $this->_context->getSession();
     $session->start();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     if (!$this->_getConfiguration('enableExpiration')) {
         return true;
     }
     if ($session->hasAttribute('_sessionUpdatedAt') && !$this->_handleExpiration()) {
         return false;
     }
     $session->setAttribute('_sessionUpdatedAt', time());
     return true;
 }
コード例 #4
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;
 }
コード例 #5
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;
         }
     }
 }
コード例 #6
0
ファイル: Validation.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  */
 function invoke()
 {
     $validation =& $this->_context->getValidation();
     $validation->setConfigDirectory($this->_getConfiguration('configDirectory'));
     $validation->setCacheDirectory($this->_getConfiguration('cacheDirectory'));
     $validation->setTemplate($this->_getConfiguration('template'));
     $validation->setUseUnderscoreAsDirectorySeparator($this->_getConfiguration('useUnderscoreAsDirectorySeparator'));
     $this->_setValidatorDirectories();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $this->_setFilterDirectories();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $this->_setValidatorPrefixes();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $this->_setFilterPrefixes();
 }
コード例 #7
0
 function testDetectCicularReferenceInObject()
 {
     $context =& Piece_Unity_Context::singleton();
     $foo =& new stdClass();
     $bar =& new stdClass();
     $baz =& new stdClass();
     $foo->bar =& $bar;
     $bar->baz =& $baz;
     $baz->foo =& $foo;
     $viewElement =& $context->getViewElement();
     $viewElement->setElementByRef('foo', $foo);
     $config =& new Piece_Unity_Config();
     $config->setConfiguration('Renderer_JSON', 'contentType', 'text/javascript');
     $config->setConfiguration('Renderer_JSON', 'include', array());
     $config->setConfiguration('Renderer_JSON', 'exclude', array());
     $config->setConfiguration('Renderer_JSON', 'useJSONP', true);
     $config->setConfiguration('Renderer_JSON', 'callbackKey', 'callback');
     $context =& Piece_Unity_Context::singleton();
     $context->setConfiguration($config);
     $renderer =& Piece_Unity_Plugin_Factory::factory('Renderer_JSON');
     Piece_Unity_Error::disableCallback();
     $renderer->invoke();
     Piece_Unity_Error::enableCallback();
     $this->assertTrue(Piece_Unity_Error::hasErrors());
     $error = Piece_Unity_Error::pop();
     $this->assertEquals(PIECE_UNITY_ERROR_UNEXPECTED_VALUE, $error['code']);
     $this->assertEquals(strtolower('_visitObject'), strtolower($error['context']['function']));
 }
コード例 #8
0
 function testExceptionShouldBeRaisedIfControllerClassIsNotSpecified()
 {
     $context =& Piece_Unity_Context::singleton();
     $context->setView("{$this->_target}ControllerShouldBeUsedIfUseControllerIsTrue");
     $viewElement =& $context->getViewElement();
     $viewElement->setElement('foo', 'BAR');
     $config =& $this->_getConfig();
     $config->setConfiguration('Renderer_Flexy', 'useController', true);
     $config->setConfiguration('Renderer_Flexy', 'controllerClass', 'Piece_Unity_Plugin_Renderer_FlexyTestCase_Controller');
     $context->setConfiguration($config);
     Piece_Unity_Error::disableCallback();
     $this->_render();
     Piece_Unity_Error::enableCallback();
     $this->assertTrue(Piece_Unity_Error::hasErrors());
     $error = Piece_Unity_Error::pop();
     $this->assertEquals(PIECE_UNITY_ERROR_INVOCATION_FAILED, $error['code']);
 }
コード例 #9
0
ファイル: PHP.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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);
     }
 }
コード例 #10
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);
         }
     }
 }
コード例 #11
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);
     }
 }
コード例 #12
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;
         }
     }
 }
コード例 #13
0
ファイル: Context.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Sends a HTTP status line like "HTTP/1.1 404 Not Found".
  *
  * @param integer $statusCode
  * @since Method available since Release 1.5.0
  */
 function sendHTTPStatus($statusCode)
 {
     $httpStatus =& new Piece_Unity_HTTPStatus($statusCode);
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $httpStatus->send();
 }
コード例 #14
0
ファイル: Factory.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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];
 }
コード例 #15
0
ファイル: Common.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Sets a single instance of Piece_Unity_Context class to a plugin, and
  * defines extension points and configuration points for the plugin.
  * And also the plug-in name is set.
  *
  * @param string $prefix
  */
 function Piece_Unity_Plugin_Common($prefix = 'Piece_Unity_Plugin')
 {
     if (strlen($prefix)) {
         $this->_name = str_replace(strtolower("{$prefix}_"), '', strtolower(get_class($this)));
     } else {
         $this->_name = strtolower(get_class($this));
     }
     $this->_context =& Piece_Unity_Context::singleton();
     $this->_initialize();
     $config =& $this->_context->getConfiguration();
     $config->validateExtensionPoints($this->_name, array_keys($this->_extensionPoints));
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $config->validateConfigurationPoints($this->_name, array_keys($this->_configurationPoints));
 }
コード例 #16
0
ファイル: Root.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  */
 function invoke()
 {
     $configurator =& $this->_getExtension('configurator');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $configurator->invoke();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $outputFilter =& $this->_getExtension('outputFilter');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $outputFilter->invoke();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $interceptor =& $this->_getExtension('interceptor');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $interceptor->invoke();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $controller =& $this->_getExtension('controller');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $controller->invoke();
 }
コード例 #17
0
ファイル: View.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  */
 function invoke()
 {
     /*
      * Sets the Piece_Unity_Request object and the
      * Piece_Unity_Session object as built-in view elements.
      */
     $viewElement =& $this->_context->getViewElement();
     $request =& $this->_context->getRequest();
     $viewElement->setElementByRef('__request', $request);
     $session =& $this->_context->getSession();
     $viewElement->setElementByRef('__session', $session);
     $viewElement->setElement('__eventNameKey', $this->_context->getEventNameKey());
     $viewElement->setElement('__scriptName', $this->_context->getScriptName());
     $viewElement->setElement('__basePath', $this->_context->getBasePath());
     $viewElement->setElement('__sessionName', session_name());
     $viewElement->setElement('__sessionID', session_id());
     $viewElement->setElement('__appRootPath', $this->_context->getAppRootPath());
     $uri =& new Piece_Unity_URI();
     $viewElement->setElementByRef('__url', $uri);
     // deprecated
     $viewElement->setElementByRef('__uri', $uri);
     /*
      * Overwrites the current view with another one which is specified by
      * forcedView configuration.
      */
     $forcedView = $this->_getConfiguration('forcedView');
     if (!is_null($forcedView)) {
         $this->_context->setView($forcedView);
     }
     $config =& $this->_context->getConfiguration();
     $rendererExtension = $config->getExtension('View', 'renderer');
     if (strlen($rendererExtension)) {
         $config->setConfiguration('ViewSchemeHandler', 'html', $rendererExtension);
     }
     $viewSchemeHandler =& $this->_getExtension('viewSchemeHandler');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $rendererExtension = $viewSchemeHandler->invoke();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $config->setExtension('View', 'renderer', $rendererExtension);
     $renderer =& $this->_getExtension('renderer');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $renderer->invoke();
 }
コード例 #18
0
ファイル: Session.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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);
     }
 }
コード例 #19
0
 /**
  * Visit an object.
  *
  * @param mixed &$value   the value to be visited.
  * @param array &$visited the array of objects which have been visited.
  * @return boolean
  * @throws PIECE_UNITY_ERROR_UNEXPECTED_VALUE
  */
 function _visitObject(&$value, &$visited)
 {
     $keys = array_keys(get_object_vars($value));
     foreach ($keys as $key) {
         $next =& $value->{$key};
         if ($this->_wasVisited($next, $visited)) {
             $class = get_class($value);
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_UNEXPECTED_VALUE, "A circular refrence detected at the property {$key}, class {$class}.");
             return;
         }
         $this->_visit($next, $visited);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
     }
 }
コード例 #20
0
 /**
  * Sets the Piece_Flow_Continuation_Service object to $_continuation
  * property and the context.
  *
  * @since Method available since Release 0.9.0
  */
 function _prepareContinuation()
 {
     $session =& $this->_context->getSession();
     $continuationServer =& $session->getAttribute(PIECE_UNITY_CONTINUATION_SESSIONKEY);
     if (is_null($continuationServer)) {
         $continuationServer =& $this->_createContinuationServer();
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $session->setAttributeByRef(PIECE_UNITY_CONTINUATION_SESSIONKEY, $continuationServer);
         $session->setPreloadCallback('_Dispatcher_Continuation', array('Piece_Unity_Plugin_Factory', 'factory'));
         $session->addPreloadClass('_Dispatcher_Continuation', 'Dispatcher_Continuation');
     }
     $continuationService =& $continuationServer->createService();
     $this->_context->setContinuation($continuationService);
     $this->_continuationServer =& $continuationServer;
 }
コード例 #21
0
ファイル: Env.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $proxyPath = $this->_getConfiguration('proxyPath');
     if (!is_null($proxyPath)) {
         $this->_context->setProxyPath($proxyPath);
     }
     $this->_setNonSSLableServers();
     $envHandlers =& $this->_getExtension('envHandlers');
     if (!is_array($envHandlers)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ envHandlers ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach (array_merge($this->_requiredEnvHandlers, $envHandlers) as $extension) {
         $envHandler =& Piece_Unity_Plugin_Factory::factory($extension);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $envHandler->invoke(Piece_Unity_Env::isProduction());
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
     }
 }
コード例 #22
0
ファイル: Controller.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Invokes the plugin specific code.
  */
 function invoke()
 {
     if (is_null($this->_context->getView())) {
         $dispatcher =& $this->_getExtension('dispatcher');
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $viewString = $dispatcher->invoke();
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         if (is_null($this->_context->getView())) {
             $this->_context->setView($viewString);
         }
     }
     $dispatcherContinuation =& Piece_Unity_Plugin_Factory::factory('Dispatcher_Continuation');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $dispatcherContinuation->publish();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $view =& $this->_getExtension('view');
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $view->invoke();
 }
コード例 #23
0
ファイル: Simple.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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
ファイル: HTML.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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);
     }
 }
コード例 #25
0
ファイル: Flexy.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * 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;
 }
 function testShouldAuthenticatePermissions()
 {
     $_SERVER['REQUEST_URI'] = '/wiki/delete.php';
     $config =& new Piece_Unity_Config();
     $config->setConfiguration('Authorization', 'permissions', array('^/wiki/.*' => 'WIKI_ADMIN'));
     $context =& Piece_Unity_Context::singleton();
     $context->setConfiguration($config);
     $authorization =& Piece_Unity_Plugin_Factory::factory('Authorization');
     $GLOBALS['PIECE_UNITY_Plugin_Interceptor_AuthorizationTestCase_hasPermission'] = true;
     $this->assertTrue($authorization->invoke());
     $GLOBALS['PIECE_UNITY_Plugin_Interceptor_AuthorizationTestCase_hasPermission'] = false;
     Piece_Unity_Error::disableCallback();
     $authorization->invoke();
     Piece_Unity_Error::enableCallback();
     $this->assertTrue(Piece_Unity_Error::hasErrors());
     $error = Piece_Unity_Error::pop();
     $this->assertEquals(PIECE_UNITY_ERROR_INVOCATION_FAILED, $error['code']);
 }
コード例 #27
0
ファイル: Unity.php プロジェクト: nyarla/fluxflex-rep2ex
 /**
  * Dispatches a request.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_OPERATION
  */
 function dispatch()
 {
     if (is_null($this->_config)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_OPERATION, __FUNCTION__ . ' method must be called after calling configure().');
         return;
     }
     $root =& Piece_Unity_Plugin_Factory::factory($GLOBALS['PIECE_UNITY_Root_Plugin']);
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     $root->invoke();
 }
コード例 #28
0
 /**
  * Restores field values from the given validation set and container.
  *
  * @param string $validationSet
  * @param mixed  &$container
  * @since Method available since Release 1.1.0
  */
 function restoreValues($validationSet, &$container)
 {
     $validation =& $this->_context->getValidation();
     $fieldNames = $validation->getFieldNames($validationSet);
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     foreach ($fieldNames as $field) {
         $this->setValue($field, @$container->{$field});
     }
 }
コード例 #29
0
    function testFallback()
    {
        $context =& Piece_Unity_Context::singleton();
        $context->setView('NonExistingView');
        $viewElement =& $context->getViewElement();
        $viewElement->setElement('content', 'This is a dynamic content.');
        $config =& $this->_getConfig();
        $config->setConfiguration("Renderer_{$this->_target}", 'useFallback', true);
        $config->setConfiguration("Renderer_{$this->_target}", 'fallbackView', 'Fallback');
        $config->setConfiguration("Renderer_{$this->_target}", 'fallbackDirectory', "{$this->_cacheDirectory}/templates/Fallback");
        $config->setConfiguration("Renderer_{$this->_target}", 'fallbackCompileDirectory', "{$this->_cacheDirectory}/compiled-templates/Fallback");
        $context->setConfiguration($config);
        set_error_handler(create_function('$code, $message, $file, $line', "\nif (\$code == E_USER_WARNING) {\n    \$GLOBALS['PIECE_UNITY_Plugin_Renderer_HTML_CompatibilityTests_hasWarnings'] = true;\n}\n"));
        $output = $this->_render();
        restore_error_handler();
        $this->assertEquals('<html>
  <body>
    <p>This is a test for fallback.</p>
  </body>
</html>', rtrim($output));
        $this->assertFalse(Piece_Unity_Error::hasErrors());
        $this->assertTrue($GLOBALS['PIECE_UNITY_Plugin_Renderer_HTML_CompatibilityTests_hasWarnings']);
        $GLOBALS['PIECE_UNITY_Plugin_Renderer_HTML_CompatibilityTests_hasWarnings'] = false;
    }
コード例 #30
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_INVOCATION_FAILED
  */
 function render($file, &$viewElement)
 {
     $this->_loadSmarty();
     $smarty =& new Smarty();
     foreach ($this->_smartyClassVariables as $key => $value) {
         if ($key == 'plugins_dir' && is_array($value)) {
             $oldPluginDirectories = $smarty->plugins_dir;
             $smarty->plugins_dir = array_merge($value, $oldPluginDirectories);
             continue;
         }
         if (!is_null($value)) {
             $smarty->{$key} = $this->_adjustEndingSlash($value);
         } else {
             $smarty->{$key} = null;
         }
     }
     $viewElements = $viewElement->getElements();
     foreach (array_keys($viewElements) as $elementName) {
         $smarty->assign_by_ref($elementName, $viewElements[$elementName]);
     }
     set_error_handler(array(__CLASS__, 'pushPHPError'));
     Piece_Unity_Error::disableCallback();
     $smarty->display($file);
     Piece_Unity_Error::enableCallback();
     restore_error_handler();
     if (Piece_Unity_Error::hasErrors()) {
         $error = Piece_Unity_Error::pop();
         if ($error['code'] == PIECE_UNITY_ERROR_PHP_ERROR && array_key_exists('repackage', $error) && preg_match('/^Smarty error: unable to read resource:/', $error['repackage']['message'])) {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The HTML template file [ {$file} ] is not found or not readable.", 'exception', array(), $error);
         } else {
             Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke Smarty::display() for any reasons.', $error['level'], array(), $error);
         }
     }
 }