/**
  * 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();
 }
 /**
  * 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;
         }
     }
 }
 /**
  * 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;
         }
     }
 }
Exemple #4
0
 /**
  * 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;
         }
     }
 }
 /**
  * @since Method available since Release 1.0.0
  */
 function _render()
 {
     $renderer =& Piece_Unity_Plugin_Factory::factory("Renderer_{$this->_target}");
     ob_start();
     $renderer->invoke();
     $buffer = ob_get_contents();
     ob_end_clean();
     return $buffer;
 }
Exemple #6
0
 /**
  * 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();
 }
Exemple #7
0
 /**
  * Removed a single instance safely.
  *
  * @static
  */
 function clear()
 {
     Piece_Unity_Plugin_Factory::clearInstances();
     unset($GLOBALS['PIECE_UNITY_Context_Instance']);
     $GLOBALS['PIECE_UNITY_Context_Instance'] = null;
 }
 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']));
 }
Exemple #9
0
 /**
  * Sets plug-in prefixes.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function _setPluginPrefixes()
 {
     $pluginPrefixes = $this->_getConfiguration('pluginPrefixes');
     if (!is_array($pluginPrefixes)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the configuration point [ pluginPrefixes ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach (array_reverse($pluginPrefixes) as $pluginPrefix) {
         Piece_Unity_Plugin_Factory::addPluginPrefix($pluginPrefix);
     }
 }
 /**
  * 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);
         }
     }
 }
Exemple #11
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];
 }
Exemple #12
0
 /**
  * Gets the extension of the given extension point.
  *
  * @param string $extensionPoint
  * @return mixed
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @since Method available since Release 0.12.0
  */
 function &_getExtension($extensionPoint)
 {
     $extensionPoint = strtolower($extensionPoint);
     if (!array_key_exists($extensionPoint, $this->_extensionPoints)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_NOT_FOUND, "The configuration point  [ {$extensionPoint} ] is not found in the plug-in [ {$this->_name} ].", 'exception', false, false, debug_backtrace());
         $return = null;
         return $return;
     }
     $config =& $this->_context->getConfiguration();
     $extension = $config->getExtension($this->_name, $extensionPoint);
     if (is_null($extension)) {
         $extension = $this->_extensionPoints[$extensionPoint];
     }
     if (!$extension || is_array($extension)) {
         return $extension;
     }
     return Piece_Unity_Plugin_Factory::factory($extension);
 }
 /**
  * Sets plug-in directories.
  */
 function _setPluginDirectories()
 {
     $pluginDirectories = $this->_getConfiguration('pluginDirectories');
     if (!is_array($pluginDirectories)) {
         trigger_error('Failed to configure the configuration point [ pluginDirectories ] at the plugin [ ' . __CLASS__ . ' ].', E_USER_WARNING);
         return;
     }
     foreach (array_reverse($pluginDirectories) as $pluginDirectory) {
         Piece_Unity_Plugin_Factory::addPluginDirectory($pluginDirectory);
     }
 }
 function testShouldAlwaysAuthenticateIfTheScriptNameIsListedInExcludes()
 {
     $_SERVER['REQUEST_URI'] = '/wiki/show.php';
     $config =& new Piece_Unity_Config();
     $config->setConfiguration('Authorization', 'permissions', array('^/wiki/.*' => 'WIKI_ADMIN'));
     $config->setConfiguration('Authorization', 'excludes', array('^/wiki/show\\.php'));
     $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;
     $this->assertTrue($authorization->invoke());
 }
 function testPluginPrefixes()
 {
     $oldPluginPrefixes = $GLOBALS['PIECE_UNITY_Plugin_Prefixes'];
     $oldPluginDirectories = $GLOBALS['PIECE_UNITY_Plugin_Directories'];
     $config =& new Piece_Unity_Config();
     $config->setConfiguration('KernelConfigurator', 'pluginPrefixes', array('KernelConfiguratorTestCaseAlias'));
     $config->setConfiguration('KernelConfigurator', 'pluginDirectories', array(dirname(__FILE__) . '/KernelConfiguratorTestCase'));
     $context =& Piece_Unity_Context::singleton();
     $context->setConfiguration($config);
     $configurator =& new Piece_Unity_Plugin_KernelConfigurator();
     $configurator->invoke();
     $foo =& Piece_Unity_Plugin_Factory::factory('FooPlugin');
     $this->assertTrue(is_object($foo));
     $this->assertTrue(is_a($foo, 'KernelConfiguratorTestCaseAlias_FooPlugin'));
     $GLOBALS['PIECE_UNITY_Plugin_Directories'] = $oldPluginDirectories;
     $GLOBALS['PIECE_UNITY_Plugin_Prefixes'] = $oldPluginPrefixes;
 }
Exemple #16
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $useLayout = $this->_getConfiguration('useLayout');
     if ($this->_getConfiguration('turnOffLayoutByHTTPAccept')) {
         if (array_key_exists('HTTP_ACCEPT', $_SERVER)) {
             if ($_SERVER['HTTP_ACCEPT'] == 'application/x-piece-html-fragment') {
                 $useLayout = false;
             }
         }
     }
     $components =& $this->_getExtension('components');
     if (!is_array($components)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ components ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach ($components as $extension) {
         $component =& Piece_Unity_Plugin_Factory::factory($extension);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $component->invoke();
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
     }
     if (!$useLayout) {
         $this->_render(false);
     } else {
         $viewElement =& $this->_context->getViewElement();
         ob_start();
         $this->_render(false);
         if (Piece_Unity_Error::hasErrors()) {
             ob_end_clean();
             return;
         }
         $content = ob_get_contents();
         ob_end_clean();
         $viewElement->setElement('__content', $content);
         $this->_render(true);
     }
 }