Ejemplo n.º 1
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;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * 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.
  */
 function invoke()
 {
     $this->_context->setEventNameKey($this->_getConfiguration('eventNameKey'));
     $this->_context->setProxyPath($this->_getConfiguration('proxyPath'));
     /*
      * Preloads Dispatcher_Continuation plug-in for restoring
      * action instances in session.
      */
     Piece_Unity_Plugin_Factory::factory('Dispatcher_Continuation');
     $this->_setAutoloadClasses();
     $this->_setEventName();
     $this->_importPathInfo();
     $this->_setPluginDirectories();
     $this->_configureValidation();
     $this->_setNonSSLableServers();
     $this->_setPluginPrefixes();
 }
Ejemplo n.º 4
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;
         }
     }
 }
Ejemplo n.º 5
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;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @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;
 }
Ejemplo n.º 7
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();
 }
 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']));
 }
Ejemplo n.º 9
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);
         }
     }
 }
Ejemplo n.º 10
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);
 }
 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;
 }
Ejemplo n.º 13
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);
     }
 }