当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getController方法代码示例

本文整理汇总了PHP中Bluz\Proxy\Request::getController方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getController方法的具体用法?PHP Request::getController怎么用?PHP Request::getController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bluz\Proxy\Request的用法示例。


在下文中一共展示了Request::getController方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dispatchUri

 /**
  * dispatch URI
  *
  * @param string $uri in format "module/controllers"
  * @param array $params of request
  * @param string $method HTTP
  * @param bool $ajax
  * @return void
  */
 protected function dispatchUri($uri, array $params = null, $method = Http\Request::METHOD_GET, $ajax = false)
 {
     $this->prepareRequest($uri, $params, $method, $ajax);
     $uri = trim($uri, '/ ');
     list($module, $controller) = explode('/', $uri);
     // set default controllers
     if (!$controller) {
         $controller = Request::getController();
     }
     Request::setModule($module);
     Request::setController($controller);
     Request::setRequestUri($uri);
     $this->getApp()->process();
 }
开发者ID:Kit-kat1,项目名称:bluz,代码行数:23,代码来源:TestCase.php

示例2: 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);
     }
 }
开发者ID:Kit-kat1,项目名称:custom-bluz-app,代码行数:25,代码来源:Router.php

示例3: 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);
 }
开发者ID:Kit-kat1,项目名称:custom-bluz-app,代码行数:97,代码来源:Application.php

示例4: 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
 }
开发者ID:dezvell,项目名称:mm.local,代码行数:31,代码来源:Rest.php

示例5: 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;
 }
开发者ID:bluzphp,项目名称:framework,代码行数:55,代码来源:Grid.php

示例6: 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);
};
开发者ID:bluzphp,项目名称:framework,代码行数:31,代码来源:Url.php

示例7: 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 ($controller = null) {
    if (is_null($controller)) {
        return Request::getController();
    } else {
        return Request::getController() == $controller;
    }
};
开发者ID:dezvell,项目名称:mm.local,代码行数:22,代码来源:Controller.php

示例8: 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();
 }
开发者ID:bashmach,项目名称:bluz-skeleton-parse,代码行数:18,代码来源:Bootstrap.php

示例9: 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);
     }
 }
开发者ID:bluzphp,项目名称:framework,代码行数:32,代码来源:Application.php

示例10: 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);
};
开发者ID:bluzphp,项目名称:skeleton,代码行数:31,代码来源:post.php


注:本文中的Bluz\Proxy\Request::getController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。