本文整理汇总了PHP中Bluz\Proxy\Request::getModule方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getModule方法的具体用法?PHP Request::getModule怎么用?PHP Request::getModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bluz\Proxy\Request
的用法示例。
在下文中一共展示了Request::getModule方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrl
/**
* Build URL to controller
*
* @param string $module
* @param string $controller
* @param array $params
* @return string
*/
public function getUrl($module = self::DEFAULT_MODULE, $controller = self::DEFAULT_CONTROLLER, $params = array())
{
if (is_null($module)) {
$module = Request::getModule();
}
if (is_null($controller)) {
$controller = Request::getController();
}
if (empty($this->routers)) {
return $this->urlRoute($module, $controller, $params);
} else {
if (isset($this->reverse[$module], $this->reverse[$module][$controller])) {
return $this->urlCustom($module, $controller, $params);
}
return $this->urlRoute($module, $controller, $params);
}
}
示例2: doProcess
/**
* 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);
}
示例3: methodPost
/**
* Method POST
*
* @return array|false
* @throws BadRequestException
* @throws NotImplementedException
*/
public function methodPost()
{
if (!empty($this->primary)) {
// POST + ID is incorrect behaviour
throw new NotImplementedException();
}
try {
$result = $this->createOne($this->data);
if (!$result) {
// system can't create record with this data
throw new BadRequestException();
}
if (is_array($result)) {
$result = join('-', array_values($result));
}
} catch (ValidatorException $e) {
Response::setStatusCode(400);
return ['errors' => $e->getErrors()];
}
Response::setStatusCode(201);
Response::setHeader('Location', Router::getUrl(Request::getModule(), Request::getController()) . '/' . $result);
return false;
// disable view
}
示例4: processRequest
/**
* Process request
*
* Example of request url
* - http://domain.com/pages/grid/
* - http://domain.com/pages/grid/page/2/
* - http://domain.com/pages/grid/page/2/order-alias/desc/
* - http://domain.com/pages/grid/page/2/order-created/desc/order-alias/asc/
*
* with prefix for support more than one grid on page
* - http://domain.com/users/grid/users-page/2/users-order-created/desc/
* - http://domain.com/users/grid/users-page/2/users-filter-status/active/
*
* hash support
* - http://domain.com/pages/grid/#/page/2/order-created/desc/order-alias/asc/
*
* @return Grid
*/
public function processRequest()
{
$this->module = Request::getModule();
$this->controller = Request::getController();
$page = Request::getParam($this->prefix . 'page', 1);
$this->setPage($page);
$limit = Request::getParam($this->prefix . 'limit', $this->limit);
$this->setLimit($limit);
foreach ($this->allowOrders as $column) {
$order = Request::getParam($this->prefix . 'order-' . $column);
if ($order) {
$this->addOrder($column, $order);
}
}
foreach ($this->allowFilters as $column) {
$filter = Request::getParam($this->prefix . 'filter-' . $column);
if ($filter) {
if (strpos($filter, '-')) {
$filter = trim($filter, ' -');
while ($pos = strpos($filter, '-')) {
$filterType = substr($filter, 0, $pos);
$filter = substr($filter, $pos + 1);
if (strpos($filter, '-')) {
$filterValue = substr($filter, 0, strpos($filter, '-'));
$filter = substr($filter, strpos($filter, '-') + 1);
} else {
$filterValue = $filter;
}
$this->addFilter($column, $filterType, $filterValue);
}
} else {
$this->addFilter($column, self::FILTER_EQ, $filter);
}
}
}
return $this;
}
示例5: function
* @param bool $checkAccess
* @return null|string
* @throws ViewException
*/
return function ($module, $controller, $params = [], $checkAccess = false) {
/**
* @var View $this
*/
try {
if ($checkAccess) {
try {
$controllerInstance = new Controller($module, $controller);
$controllerInstance->checkPrivilege();
} catch (ForbiddenException $e) {
return null;
}
}
} catch (\Exception $e) {
throw new ViewException('Url View Helper: ' . $e->getMessage());
}
if (null === $module) {
$module = Request::getModule();
}
if (null === $controller) {
$controller = Request::getController();
}
if (null === $params) {
$params = Request::getParams();
}
return Router::getUrl($module, $controller, $params);
};
示例6: function
<?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
/**
* @namespace
*/
namespace Bluz\View\Helper;
use Bluz\Proxy\Request;
use Bluz\View\View;
return function ($module = null) {
if (is_null($module)) {
return Request::getModule();
} else {
return Request::getModule() == $module;
}
};
示例7: render
/**
* Render with debug headers
* @return void
*/
public function render()
{
if ($this->debugFlag && !headers_sent()) {
$debugString = sprintf("%fsec; %skb", microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], ceil(memory_get_usage() / 1024));
$debugString .= '; ' . Request::getModule() . '/' . Request::getController();
Response::setHeader('Bluz-Debug', $debugString);
if ($info = Logger::get('info')) {
Response::setHeader('Bluz-Bar', json_encode($info));
} else {
Response::setHeader('Bluz-Bar', '{"!":"Logger is disabled"}');
}
}
parent::render();
}
示例8: doProcess
/**
* Do process
*
* @return void
*/
protected function doProcess()
{
$module = Request::getModule();
$controller = Request::getController();
$params = Request::getParams();
// try to dispatch controller
try {
// dispatch controller
$result = $this->dispatch($module, $controller, $params);
} catch (ForbiddenException $e) {
$result = $this->forbidden($e);
} catch (RedirectException $e) {
// redirect to URL
$result = $this->redirect($e->getUrl());
} catch (\Exception $e) {
$result = $this->error($e);
}
// setup layout, if needed
if ($this->useLayout()) {
// render view to layout
// needed for headScript and headStyle helpers
Layout::setContent($result->render());
Response::setBody(Layout::getInstance());
} else {
Response::setBody($result);
}
}
示例9: function
* @accept JSON
* @method POST
*
* @param \Bluz\Crud\Table $crud
* @param mixed $primary
* @param array $data
* @return void|array
* @throws BadRequestException
* @throws NotImplementedException
*/
return function ($crud, $primary, $data) {
if (!empty($primary)) {
// POST + ID is incorrect behaviour
throw new NotImplementedException();
}
try {
$result = $crud->createOne($data);
if (!$result) {
// system can't create record with this data
throw new BadRequestException();
}
if (is_array($result)) {
$result = join('-', array_values($result));
}
} catch (ValidatorException $e) {
Response::setStatusCode(400);
return ['errors' => $e->getErrors()];
}
Response::setStatusCode(201);
Response::setHeader('Location', Router::getUrl(Request::getModule(), Request::getController()) . '/' . $result);
};