Example #1
0
 public function testIsXmlHttpRequest()
 {
     $request = new Request('baseUrl', 'basePath', 'controller', 'action');
     $this->assertFalse($request->isXmlHttpRequest());
     $_SERVER[Request::HEADER_REQUEST] = Request::XML_HTTP_REQUEST;
     $this->assertTrue($request->isXmlHttpRequest());
 }
 /**
  * Prepares the controller
  * @param Controller $controller The controller to prepare
  * @param Request $request The request for the controller
  * @param Response $response The response for the controller
  * @param string $actionName The method which will be invoked
  * @param array $parameters The parameters for that method
  * @return null
  */
 protected function prepareController(Controller $controller, Request $request, Response $response, $actionName, array $parameters)
 {
     if (!$this->passRequestParameters) {
         $request = new Request($request->getBaseUrl(), $request->getBasePath(), $request->getControllerName(), Dispatcher::ACTION_INDEX);
     }
     $this->widget->setRequest($request);
     $this->widget->setResponse($response);
 }
Example #3
0
 public function overrideRequest()
 {
     $request = $this->zibo->getRequest();
     $route = $request->getRoute();
     if (substr($route, 0, 4) == '/web') {
         return;
     }
     $request = new Request($request->getBaseUrl(), $request->getBaseUrl() . '/install', self::CONTROLLER_INSTALL, Dispatcher::ACTION_ASTERIX, $request->getParameters());
     $this->zibo->setRequest($request);
 }
 /**
  * Gets a request from the provided path for request chaining
  * @param string $path The path to route
  * @return zibo\core\Request|null A request if the path was found, null otherwise
  */
 protected function route($path)
 {
     $router = $this->zibo->getRouter();
     if (!$router) {
         return null;
     }
     return $router->getRequest($this->request->getBaseUrl(), $path);
 }
Example #5
0
 /**
  * Get a error report of an exception
  * @param Exception $exception
  * @param zibo\core\Request $request
  * @return string
  */
 private function getReport(Exception $exception, Request $request = null)
 {
     $report = 'Date: ' . date('d/m/Y H:i:s', time()) . "\n";
     if ($request) {
         $url = $request->getBasePath() . '/';
         $url .= implode('/', $request->getParameters());
         $report .= 'Request: ' . $url . "\n";
     }
     $user = SecurityManager::getInstance()->getUser();
     if ($user) {
         $report .= 'User: '******'User: anonymous';
     }
     $report .= "\n\nTrace:\n" . $this->getTrace($exception);
     return $report;
 }
 /**
  * Gets the controller of a request. If the controller class name is the same as the clasa name
  * of the controller which is set through setController, the set controller will be used instead
  * of creating a new one.
  * @param Request $request
  * @return Controller
  * @throws zibo\ZiboException when no object factory has been set
  * @throws zibo\ZiboException when the controller could not be created
  */
 protected function getController(Request $request)
 {
     try {
         $controller = $this->objectFactory->create($request->getControllerName(), self::INTERFACE_CONTROLLER);
     } catch (ZiboException $exception) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName(), 0, $exception);
     }
     return $controller;
 }
Example #7
0
 public function testIsXmlHttpRequest()
 {
     $_SERVER = array();
     $_SERVER['HTTP_X_REQUESTED_WITH'] = Request::XML_HTTP_REQUEST;
     $request = new Request('baseUrl', 'basePath', 'controller');
     $this->assertTrue($request->isXmlHttpRequest());
 }
Example #8
0
 /**
  * Invokes the wizard
  * @param zibo\core\Request $request The request
  * @param zibo\core\Response $response The response
  * @return null
  * @throws zibo\ZiboException when there are no steps in this wizard
  */
 public function invoke(Request $request, Response $response)
 {
     if (!$this->steps) {
         throw new ZiboException('This wizard does not contain any steps');
     }
     $this->request = $request;
     $this->response = $response;
     $this->currentStep = $this->getVariable(self::VARIABLE_CURRENT_STEP, $this->defaultStep);
     $step = $this->steps[$this->currentStep];
     $step->prepareForm();
     if ($this->isSubmitted()) {
         if ($this->getValue(self::BUTTON_CANCEL)) {
             $this->reset();
             if ($this->cancelUrl) {
                 $this->response->setRedirect($this->cancelUrl);
             } else {
                 $this->response->setRedirect($this->request->getBaseUrl());
             }
             return;
         }
         $nextStep = null;
         if ($this->getValue(self::BUTTON_PREVIOUS)) {
             $nextStep = $step->previous();
         } elseif ($this->getValue(self::BUTTON_NEXT)) {
             $nextStep = $step->next();
         } elseif ($this->getValue(self::BUTTON_FINISH)) {
             $nextStep = $step->finish();
         }
         if ($nextStep) {
             if (!$this->hasStep($nextStep)) {
                 throw new ZiboException('Cannot set the next step, invalid return value of step ' . $this->currentStep);
             }
             $this->setVariable(self::VARIABLE_CURRENT_STEP, $nextStep);
             $response->setRedirect($this->action);
         }
         if ($response->willRedirect()) {
             return;
         }
     }
     if (!$step->hasPrevious()) {
         $this->setIsDisabled(true, self::BUTTON_PREVIOUS);
     }
     if (!$step->hasNext()) {
         $this->setIsDisabled(true, self::BUTTON_NEXT);
     }
     if (!$step->hasFinish()) {
         $this->setIsDisabled(true, self::BUTTON_FINISH);
     }
     if (!$step->hasCancel()) {
         $this->setIsDisabled(true, self::BUTTON_CANCEL);
     }
     $view = $this->getView($step);
     if ($response->willRedirect()) {
         return;
     }
     $response->setView($view);
 }
Example #9
0
 /**
  * Construct a new Joppa request
  * @param string $baseUrl the base url of the request
  * @param joppa\model\Node $node The node of this request
  * @param string $controllerName the full name of the controller class (including namespace)
  * @param string $actionName the action method in the controller class
  * @param array $parameters an array containing the parameters for the action method
  * @return null
  */
 public function __construct($baseUrl, Node $node, $controllerName, $actionName, array $parameters)
 {
     $basePath = $baseUrl . Request::QUERY_SEPARATOR . $node->getRoute();
     parent::__construct($baseUrl, $basePath, $controllerName, $actionName, $parameters);
     $this->setNode($node);
 }
Example #10
0
 /**
  * Gets the controller of a request. If the controller class name is the same as the clasa name
  * of the controller which is set through setController, the set controller will be used instead
  * of creating a new one.
  * @param Request $request
  * @return Controller
  * @throws zibo\ZiboException when no object factory has been set
  * @throws zibo\ZiboException when the controller could not be created
  */
 protected function getController(Request $request)
 {
     if ($this->controller && $request->getControllerName() == get_class($this->controller)) {
         return $this->controller;
     }
     if ($this->objectFactory === null) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName() . ': no ObjectFactory set');
     }
     try {
         $controller = $this->objectFactory->create($request->getControllerName(), self::INTERFACE_CONTROLLER);
     } catch (ZiboException $e) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName(), 0, $e);
     }
     return $controller;
 }
 /**
  * Dispatch the node
  * @param zibo\core\Request $request
  * @param zibo\core\Response $response
  * @return array Array with the region name as key and a view array as value. The view array has the widget id as key and the dispatched widget view as value
  */
 public function dispatch(Request $request, Response $response)
 {
     $cache = Module::getCache();
     if (!$this->breadcrumbs) {
         $this->breadcrumbs = new Breadcrumbs();
     }
     $parameters = str_replace(Request::QUERY_SEPARATOR, '-', $request->getParametersAsString());
     $views = array();
     foreach ($this->regions as $regionName => $widgets) {
         foreach ($widgets as $widgetId => $widget) {
             $isJoppaWidget = $widget instanceof JoppaWidget;
             $cacheKey = $this->node->id . '#' . $regionName . '#' . $widgetId . '#' . $this->node->dataLocale . '#' . $parameters;
             if ($isJoppaWidget) {
                 if (!$_POST) {
                     $view = $cache->get(Module::CACHE_TYPE_NODE_WIDGET_VIEW, $cacheKey);
                     if ($view) {
                         $views[$regionName][$widgetId] = $view;
                         continue;
                     }
                 }
                 $widget->setBreadcrumbs($this->breadcrumbs);
                 $widget->setNode($this->node);
             }
             $this->dispatchWidget($request, $response, $widgetId, $widget);
             if ($response->willRedirect()) {
                 return;
             }
             $view = $response->getView();
             $response->setView(null);
             if ($view instanceof FileView) {
                 return $view;
             }
             if ($isJoppaWidget && $widget->isContent()) {
                 if ($request->isXmlHttpRequest()) {
                     return $view;
                 }
                 $views[$regionName] = array($widgetId => $view);
                 break;
             }
             if ($isJoppaWidget && $widget->isCacheable()) {
                 $cache->set(Module::CACHE_TYPE_NODE_WIDGET_VIEW, $cacheKey, $view);
             }
             $views[$regionName][$widgetId] = $view;
         }
     }
     return $views;
 }
Example #12
0
 /**
  * Checks if the current status is not modified. If the status code is set
  * @param zibo\core\Request $request
  * @return boolean True if the content is not modified, false otherwise
  */
 public function isNotModified(Request $request)
 {
     $noneMatch = $request->getIfNoneMatch();
     $modifiedSince = $request->getIfModifiedSince();
     $eTag = $this->getETag();
     $isNoneMatch = !$noneMatch || isset($noneMatch['*']) || $eTag && isset($noneMatch[$eTag]);
     $isModifiedSince = !$modifiedSince || $this->getLastModified() == $modifiedSince;
     $isNotModified = false;
     if ($noneMatch && $modifiedSince) {
         $isNotModified = $isNoneMatch && $isModifiedSince;
     } elseif ($noneMatch) {
         $isNotModified = $isNoneMatch;
     } elseif ($modifiedSince) {
         $isNotModified = $isModifiedSince;
     }
     return $isNotModified;
 }