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


PHP Router::handle方法代码示例

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


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

示例1: match

 /**
  * {@inheritdoc}
  */
 public function match(Request $request)
 {
     $this->router->handle($request->getUri()->getPath());
     if (!$this->router->wasMatched()) {
         // TODO Is it worth to validate, if route matches but the method is incompatible?
         return RouteResult::fromRouteFailure();
     }
     $matchedRoute = $this->router->getMatchedRoute();
     return RouteResult::fromRouteMatch($matchedRoute->getName(), $this->router->getNamespaceName(), $this->collectParams($matchedRoute));
 }
开发者ID:theDisco,项目名称:phalcon-expressive,代码行数:13,代码来源:PhalconRouter.php

示例2: testRoutes

 /**
  * @dataProvider routesProvider
  *
  * @param $arRoute
  * @param $strUri
  * @param $strClassName
  */
 public function testRoutes($arRoute, $strUri, $strClassName)
 {
     $this->router->add($arRoute['route'], $arRoute['parameters'])->setName($arRoute['name']);
     $this->router->handle($strUri);
     $boolMatched = $this->router->wasMatched();
     $this->assertTrue($boolMatched, 'failed to match ' . $strUri);
     $strRouteName = $this->router->getMatchedRoute()->getName();
     $this->assertEquals($arRoute['name'], $strRouteName, 'matched wrong route');
     $this->setUpDispatcher();
     $this->dispatcher->dispatch();
     $strControllerClassName = $this->dispatcher->getControllerClass();
     $this->assertEquals($strClassName, $strControllerClassName, 'wrong controller class name');
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:20,代码来源:DefaultDispatcherTest.php

示例3: handle

 public function handle($path = null)
 {
     if ($path === null) {
         $path = $this->getRewriteUri();
     }
     // First attempt regular resolution.
     parent::handle($path);
     $router_route = $this->getMatchedRoute();
     if ($router_route !== NULL) {
         return $path;
     }
     $di = $this->getDI();
     $module_list = array_keys($di->get('phalcon_modules'));
     $path = trim($path, self::URI_DELIMITER);
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if (in_array($path[0], $module_list)) {
             $this->_module = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $this->_controller = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $this->_action = array_shift($path);
         }
         if (count($path)) {
             $this->_params = $path;
         }
     }
     return $path;
 }
开发者ID:einstein95,项目名称:FAOpen,代码行数:31,代码来源:Router.php

示例4: handle

 /**
  * registers module according to uri given
  *
  * @return bool true if module successfully loaded; <br />
  * 				false otherwise;
  */
 public function handle()
 {
     $boolReturn = false;
     $oLogger = $this->di->getFileLogger();
     $oPreRouter = new Router();
     $oPreRouter->add('/api(.*)', array('module' => 'api'));
     $oPreRouter->add('/regular(.*)', array('module' => 'regular'));
     $oPreRouter->add('/blind(.*)', array('module' => 'blind'));
     $oPreRouter->handle();
     $strModuleName = $oPreRouter->getModuleName();
     /**
      * @type Request $oRequest
      */
     $oRequest = $this->di->getRequest();
     if (array_key_exists($strModuleName, $this->knownModules)) {
         $this->app->registerModules(array($strModuleName => $this->knownModules[$strModuleName]));
         $this->app->setDefaultModule($strModuleName);
         $boolReturn = true;
         $oLogger->debug(__CLASS__ . ': ' . $oRequest->getURI() . ' leads to module: ' . $strModuleName);
     } else {
         if (!U::isLegacy()) {
             $strMsg = 'failed to load phalcon module';
         } else {
             $strMsg = 'loading old backend';
         }
         $oLogger->debug(__CLASS__ . ': ' . $strMsg . ' for "' . $oRequest->getUri() . '"');
     }
     return $boolReturn;
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:35,代码来源:ModuleRouter.php

示例5: handle

 public function handle($strUrl = null)
 {
     /**
      * @type \DiCustom $di
      */
     $di = Di::getDefault();
     $oLogger = $di->getFileLogger();
     $oLogger->debug('handle worked in api module for "' . $strUrl . '"');
     parent::handle($strUrl);
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:10,代码来源:CustomRouter.php

示例6: testAnnotations

 public function testAnnotations()
 {
     $di = new Di();
     $di['request'] = new \Phalcon\Http\Request();
     $router = new Router(false);
     $router->setDI($di);
     $loader = new ArrayRouteLoader($router);
     $loader->load(include __DIR__ . '/Fixtures/routes.php');
     $router->handle();
     $this->assertCount(3, $router->getRoutes());
     $routes = [['uri' => '/test4', 'method' => 'GET', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test4', 'method' => 'POST', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test5', 'method' => 'POST', 'controller' => 'test5', 'action' => 'test5'], ['uri' => '/test6', 'method' => 'GET', 'controller' => 'test6', 'action' => 'test6']];
     foreach ($routes as $route) {
         $_SERVER['REQUEST_METHOD'] = $route['method'];
         $router->handle($route['uri']);
         $this->assertEquals($router->getControllerName(), $route['controller']);
         $this->assertEquals($router->getActionName(), $route['action']);
         $this->assertEquals($router->isExactControllerName(), true);
     }
 }
开发者ID:ant-hill,项目名称:phalcon-kernel-module,代码行数:19,代码来源:ArrayRouterTest.php

示例7: handle

 /**
  * @param null $uri
  */
 public function handle($uri = null)
 {
     parent::handle($uri);
     if ($this->_wasMatched) {
         $afterMatch = $this->_matchedRoute->getAfterMatch();
         if (is_callable($afterMatch)) {
             call_user_func($afterMatch, $uri, $this->_matchedRoute);
         }
     }
 }
开发者ID:vegas-cmf,项目名称:mvc,代码行数:13,代码来源:Router.php

示例8: handle

 public function handle($uri = null)
 {
     if (empty($uri)) {
         $uri = $this->getRewriteUri();
     }
     $di = $this->getDI();
     $routeManager = $di->get('databaseRouteManager');
     $routes = $di->get('config')->get('routes', false);
     $route = $routeManager->findByUrl($uri);
     if ($route && $routes) {
         $routeParams = $routes->get($route->name, false);
         if ($routeParams) {
             $this->add($uri, ['module' => $routeParams->module, 'controller' => $routeParams->controller, 'action' => $routeParams->action, 0 => substr($uri, 1)]);
         } else {
             throw new \Exception('Database route not configured');
         }
     }
     return parent::handle($uri);
 }
开发者ID:sanderborgman,项目名称:database-router,代码行数:19,代码来源:Mongo.php

示例9: Router

<?php

/**
 * Created by PhpStorm.
 * User: vlad
 * Date: 8/28/15
 * Time: 10:34 PM
 */
use Phalcon\Mvc\Router;
$router = new Router();
$router->removeExtraSlashes(true);
$router->add("/", array("controller" => "projects", "action" => "index"));
$router->add("/projects(/?index)?", array("controller" => "static", "action" => "error"));
$router->add("/404", array("controller" => "static", "action" => "error404"));
$router->add("/403", array("controller" => "static", "action" => "error403"));
$router->notFound(array("controller" => "static", "action" => "error404"));
$router->handle();
开发者ID:vlad6085,项目名称:projectstorage,代码行数:17,代码来源:router.php

示例10: testEasyMismatched

 /**
  * @group excluded
  * @dataProvider easyMismatchedProvider
  *
  * @param $strUri
  */
 public function testEasyMismatched($strUri)
 {
     $this->router->handle($strUri);
     $boolMatched = $this->router->wasMatched();
     $this->assertFalse($boolMatched, 'matched when should not');
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:12,代码来源:RouterMatchesTest.php

示例11: handle

 /**
  * Produce the routing parameters from the rewrite information
  *
  * @param string|null $uri
  * @throws Exception
  */
 public function handle($uri = null)
 {
     if (is_null($uri) === true) {
         $uri = $this->getRewriteUri();
     } elseif (is_string($uri) === false) {
         throw new Exception('Invalid parameter type.');
     }
     $annotationsService = null;
     if ($this->_processed === false) {
         if (is_array($this->_handlers) === true) {
             foreach ($this->_handlers as $scope) {
                 if (is_array($scope) === true) {
                     //A prefix (if any) must be in position 0
                     if (is_string($scope[0]) === true) {
                         if (Text::startsWith($uri, $scope[0]) === false) {
                             continue;
                         }
                     }
                     if (is_object($annotationsService) === false) {
                         if (is_object($this->_dependencyInjector) === false) {
                             throw new Exception("A dependency injection container is required to access the 'annotations' service");
                         }
                         $annotationsService = $this->_dependencyInjector->getShared('annotations');
                         //@note no interface validation
                     }
                     //The controller must be in position 1
                     if (strpos($scope[1], '\\') !== false) {
                         //Extract the real class name from the namespaced class
                         $classWithNamespace = get_class($handler);
                         //Extract the real class name from the namespaced class
                         //Extract the namespace from the namespaced class
                         $pos = strrpos($classWithNamespace, '\\');
                         if ($pos !== false) {
                             $namespaceName = substr($classWithNamespace, 0, $pos);
                             $controllerName = substr($classWithNamespace, $pos);
                         } else {
                             $controllerName = $classWithNamespace;
                             $namespaceName = null;
                         }
                         $this->_routePrefix = null;
                         //Check if the scope has a module associated
                         if (isset($scope[2]) === true) {
                             $moduleName = $scope[2];
                         } else {
                             $moduleName = null;
                         }
                         //Get the annotations from the class
                         $handlerAnnotations = $annotationsService->get($handler . $this->_controllerSuffix);
                         //Process class annotations
                         $classAnnotations = $handlerAnnotations->getClassAnnotations();
                         if (is_object($classAnnotations) === true) {
                             //Process class annotaitons
                             $annotations = $classAnnotations->getAnnotations();
                             if (is_array($annotations) === true) {
                                 foreach ($annotations as $annotation) {
                                     $this->processControllerAnnotation($annotation);
                                 }
                             }
                         }
                         //Process method annotations
                         $methodAnnotations = $handlerAnnotations->getMethodsAnnotations();
                         if (is_array($methodAnnotations) === true) {
                             foreach ($methodAnnotations as $method => $collection) {
                                 if (is_object($collection) === true) {
                                     $annotations = $collection->getAnnotations();
                                     foreach ($annotations as $annotation) {
                                         $this->processActionAnnotation($moduleName, $namespaceName, $controllerName, $method, $annotation);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->_processed = true;
     }
     parent::handle($uri);
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:85,代码来源:Annotations.php

示例12: Router

<?php

/**
 * Created by PhpStorm.
 * User: rcmonitor
 * Date: 07.07.15
 * Time: 15:46
 */
use Phalcon\Di;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Router;
use Phalcon\Version;
$di = new Di\FactoryDefault();
$oRouter = new Router(false);
$oRouter->setDI($di);
$oRouter->add('/:controller', array('controller' => 1, 'action' => 'index'));
$oEventManager = new Manager();
$oEventManager->attach('dispatch:beforeDispatch', function () {
    return false;
});
$oDispatcher = new Dispatcher();
$oDispatcher->setDI($di);
$oDispatcher->setEventsManager($oEventManager);
$oRouter->handle('/test');
$oDispatcher->setControllerName($oRouter->getControllerName());
$oDispatcher->setActionName($oRouter->getActionName());
$oDispatcher->dispatch();
echo $oDispatcher->getControllerClass() . PHP_EOL;
echo Version::get() . PHP_EOL;
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:30,代码来源:discussion.php

示例13: handle

 public function handle($uri = null)
 {
     return parent::handle($uri);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Router.php


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