function tearDown()
 {
     $cache =& new Cache_Lite_File(array('cacheDir' => "{$this->_cacheDirectory}/", 'masterFile' => '', 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true));
     $cache->clean();
     Piece_Unity_Context::clear();
     Piece_Unity_Error::clearErrors();
 }
Esempio n. 2
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;
 }
Esempio n. 4
0
 /**
  * Invokes the plugin specific code.
  *
  * @return boolean
  */
 function invoke()
 {
     $session =& $this->_context->getSession();
     $session->start();
     if (Piece_Unity_Error::hasErrors()) {
         return;
     }
     return true;
 }
Esempio n. 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);
     }
 }
Esempio n. 6
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
         }
     }
 }
 /**
  * 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;
         }
     }
 }
Esempio n. 10
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;
     }
 }
Esempio n. 11
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);
 }
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package    Piece_Unity
 * @copyright  Piece Project
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised)
 * @version    SVN: $Id$
 * @since      File available since Release 1.0.0
 */
error_reporting(E_ALL);
if (file_exists(dirname(__FILE__) . '/../../imports')) {
    set_include_path(dirname(__FILE__) . '/../../imports/pear' . PATH_SEPARATOR . dirname(__FILE__) . '/../../imports/spyc-0.2.5');
}
require_once 'Piece/Unity.php';
require_once 'Piece/Unity/Error.php';
Piece_Unity_Error::pushCallback(create_function('$error', 'var_dump($error); return ' . PEAR_ERRORSTACK_DIE . ';'));
$base = dirname(__FILE__) . '/../webapp';
ini_set('session.cookie_path', str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])));
session_save_path("{$base}/sessions");
$unity =& new Piece_Unity("{$base}/config", "{$base}/cache");
$unity->setConfiguration('Configurator_AppRoot', 'appRoot', dirname(__FILE__));
$unity->setConfiguration('Renderer_Flexy', 'turnOffLayoutByHTTPAccept', true);
$unity->dispatch();
/*
 * Local Variables:
 * mode: php
 * coding: iso-8859-1
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * indent-tabs-mode: nil
Esempio n. 13
0
 /**
  * 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();
 }
Esempio n. 14
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;
 }
 function tearDown()
 {
     Piece_Unity_Error::clearErrors();
 }
Esempio n. 16
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);
     }
 }
Esempio n. 17
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);
         }
     }
 }
 /**
  * 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});
     }
 }
Esempio n. 19
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;
 }
Esempio n. 20
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];
 }
Esempio n. 21
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);
 }
Esempio n. 22
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);
 }
Esempio n. 23
0
 /**
  * Enables the last callback.
  *
  * @since Method available since Release 1.5.0
  */
 function enableCallback()
 {
     Piece_Unity_Error::popCallback();
 }
Esempio n. 24
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)
 {
     $flexy =& new HTML_Template_Flexy($this->_options);
     $resultOfCompile = $flexy->compile($file);
     if (PEAR::isError($resultOfCompile)) {
         if ($flexy->currentTemplate === false) {
             Piece_Unity_Error::pushPEARError($resultOfCompile, PIECE_UNITY_ERROR_NOT_FOUND, "The HTML template file [ {$file} ] is not found or not readable.");
             return;
         }
         Piece_Unity_Error::pushPEARError($resultOfCompile, PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke HTML_Template_Flexy::compile() for any reasons.');
         return;
     }
     $viewElements = $viewElement->getElements();
     if (is_null($this->_controller)) {
         $this->_controller = (object) $viewElements;
     } else {
         foreach (array_keys($viewElements) as $element) {
             if (!is_object($viewElements[$element])) {
                 $this->_controller->{$element} = $viewElements[$element];
             } else {
                 $this->_controller->{$element} =& $viewElements[$element];
             }
         }
     }
     $flexyElement =& new Piece_Unity_Service_FlexyElement();
     $flexyElement->setViewElement($viewElement);
     $resultOfOutputObject = $flexy->outputObject($this->_controller, $flexyElement->createFormElements());
     if (PEAR::isError($resultOfOutputObject)) {
         Piece_Unity_Error::pushPEARError($resultOfOutputObject, PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke HTML_Template_Flexy::outputObject() for any reasons.');
     }
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
 /**
  * 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();
 }
 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']));
 }
Esempio n. 28
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);
     }
 }
    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;
    }
Esempio n. 30
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);
     }
 }