/** * Test of params */ public function testParamManipulation() { Request::setParam('foo', 'bar'); Request::setParam('baz', 'qux'); $this->assertEquals('bar', Request::getParam('foo')); $this->assertEquals('qux', Request::getParam('baz')); $this->assertEquals('moo', Request::getParam('qux', 'moo')); $this->assertEqualsArray(['foo' => 'bar', 'baz' => 'qux'], Request::getParams()); $this->assertEqualsArray(['foo' => 'bar', 'baz' => 'qux'], Request::getAllParams()); }
<?php /** * * * @category Application * * @author dark * @created 18.12.13 18:39 */ namespace Application; use Bluz\Proxy\Request; return function ($alias) use($module, $controller, $view) { /** * @var Bootstrap $this * @var \Bluz\View\View $view */ var_dump($alias); var_dump(Request::getParams()); var_dump(Request::getAllParams()); var_dump(Request::getRawParams()); return false; };
/** * Do process * @return void */ protected function doProcess() { Logger::info("app:process:do"); $module = Request::getModule(); $controller = Request::getController(); $params = Request::getAllParams(); // try to dispatch controller try { // get reflection of requested controller $controllerFile = $this->getControllerFile($module, $controller); $reflection = $this->reflection($controllerFile); // check header "accept" for catch JSON(P) or XML requests, and switch presentation // it's some magic for AJAX and REST requests if ($produces = $reflection->getAccept() and $accept = $this->getRequest()->getAccept()) { // switch statement for $accept switch ($accept) { case Request::ACCEPT_HTML: // with layout // without additional presentation break; case Request::ACCEPT_JSON: $this->useJson(); break; case Request::ACCEPT_JSONP: $this->useJsonp(); break; case Request::ACCEPT_XML: $this->useXml(); break; default: // not acceptable MIME type throw new NotAcceptableException(); break; } } // check call method(s) if ($reflection->getMethod() && !in_array(Request::getMethod(), $reflection->getMethod())) { throw new NotAllowedException(join(',', $reflection->getMethod())); } // check HTML cache if ($reflection->getCacheHtml() && Request::getMethod() == Request::METHOD_GET) { $htmlKey = 'html:' . $module . ':' . $controller . ':' . http_build_query($params); if ($cachedHtml = Cache::get($htmlKey)) { Response::setBody($cachedHtml); return; } } // dispatch controller $dispatchResult = $this->dispatch($module, $controller, $params); } catch (RedirectException $e) { Response::setException($e); if (Request::isXmlHttpRequest()) { // 204 - No Content Response::setStatusCode(204); Response::setHeader('Bluz-Redirect', $e->getMessage()); } else { Response::setStatusCode($e->getCode()); Response::setHeader('Location', $e->getMessage()); } return null; } catch (ReloadException $e) { Response::setException($e); if (Request::isXmlHttpRequest()) { // 204 - No Content Response::setStatusCode(204); Response::setHeader('Bluz-Reload', 'true'); } else { Response::setStatusCode($e->getCode()); Response::setHeader('Refresh', '0; url=' . Request::getRequestUri()); } return null; } catch (\Exception $e) { Response::setException($e); // cast to valid HTTP error code // 500 - Internal Server Error $statusCode = 100 <= $e->getCode() && $e->getCode() <= 505 ? $e->getCode() : 500; Response::setStatusCode($statusCode); $dispatchResult = $this->dispatch(Router::getErrorModule(), Router::getErrorController(), array('code' => $e->getCode(), 'message' => $e->getMessage())); } if ($this->hasLayout()) { Layout::setContent($dispatchResult); $dispatchResult = Layout::getInstance(); } if (isset($htmlKey, $reflection)) { // @TODO: Added ETag header Cache::set($htmlKey, $dispatchResult(), $reflection->getCacheHtml()); Cache::addTag($htmlKey, $module); Cache::addTag($htmlKey, 'html'); Cache::addTag($htmlKey, 'html:' . $module); Cache::addTag($htmlKey, 'html:' . $module . ':' . $controller); } Response::setBody($dispatchResult); }
<?php /** * Example of forms handle * * @category Application * * @author dark * @created 13.12.13 18:12 */ namespace Application; use Bluz\Proxy\Layout; use Bluz\Proxy\Request; return function ($int, $string, $array, $optional = 0) use($view) { /** * @var Bootstrap $this * @var \Bluz\View\View $view */ Layout::breadCrumbs([$view->ahref('Test', ['test', 'index']), 'Form Example']); if (Request::isPost()) { ob_start(); var_dump($int, $string, $array, $optional); $view->inside = ob_get_contents(); ob_end_clean(); $view->params = Request::getAllParams(); } };