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


PHP Router::process方法代码示例

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


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

示例1: show

 /**
  * Returns the corresponding params for a given URL and an optional request
  * method.
  *
  * Examples:
  * ```
  * 1: li3 route show /foo
  * 2: li3 route show post /foo/bar/1
  * 3: li3 route show /test
  * 4: li3 route show /test --env=production
  * ```
  *
  * Will return outputs similar to:
  *
  * ```
  * 1: {"controller":"foo","action":"index"	}
  * 2: {"controller":"foo","action":"bar","args":["1"]}
  * 3: {"controller":"lithium\\test\\Controller","action":"index"}
  * 4: {"controller":"test","action":"index"}
  * ```
  *
  * @return void
  */
 public function show()
 {
     $url = join(" ", $this->request->params['args']);
     $method = 'GET';
     if (!$url) {
         $this->error('Please provide a valid URL');
     }
     if (preg_match('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS) (.+)/i', $url, $matches)) {
         $method = strtoupper($matches[1]);
         $url = $matches[2];
     }
     $request = new Request(compact('url') + array('env' => array('REQUEST_METHOD' => $method)));
     $result = Router::process($request);
     $this->out($result->params ? json_encode($result->params) : "No route found.");
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:38,代码来源:Route.php

示例2: testStackedContinuationRoutes

 /**
  * Tests that multiple continuation routes can be applied to the same URL.
  */
 public function testStackedContinuationRoutes()
 {
     Router::connect('/admin/{:args}', array('admin' => true), array('continue' => true));
     Router::connect('/{:locale:en|de|it|jp}/{:args}', array(), array('continue' => true));
     Router::connect('/{:controller}/{:action}/{:id:[0-9]+}', array('id' => null));
     $request = new Request(array('url' => '/en/foo/bar/5'));
     $expected = array('controller' => 'foo', 'action' => 'bar', 'id' => '5', 'locale' => 'en');
     $this->assertEqual($expected, Router::process($request)->params);
     $request = new Request(array('url' => '/admin/foo/bar/5'));
     $expected = array('controller' => 'foo', 'action' => 'bar', 'id' => '5', 'admin' => true);
     $this->assertEqual($expected, Router::process($request)->params);
     $request = new Request(array('url' => '/admin/de/foo/bar/5'));
     $expected = array('controller' => 'foo', 'action' => 'bar', 'id' => '5', 'locale' => 'de', 'admin' => true);
     $this->assertEqual($expected, Router::process($request)->params);
     $request = new Request(array('url' => '/en/admin/foo/bar/5'));
     $this->assertFalse(Router::process($request)->params);
     $result = Router::match(array('Foo::bar', 'id' => 5));
     $this->assertEqual('/foo/bar/5', $result);
     $result = Router::match(array('Foo::bar', 'id' => 5, 'admin' => true));
     $this->assertEqual('/admin/foo/bar/5', $result);
     $result = Router::match(array('Foo::bar', 'id' => 5, 'admin' => true, 'locale' => 'jp'));
     $this->assertEqual('/admin/jp/foo/bar/5', $result);
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:26,代码来源:RouterTest.php

示例3: testMatchWithAbsoluteScope

 public function testMatchWithAbsoluteScope()
 {
     Router::attach('app', array('absolute' => true, 'host' => '{:domain}'));
     Router::scope('app', function () {
         Router::connect('/hello', 'Posts::index');
     });
     $request = new Request(array('url' => '/hello', 'base' => ''));
     $result = Router::process($request);
     $expected = 'http://' . $result->params['domain'] . '/hello';
     $result = Router::match($result->params, $request);
     $this->assertEqual($expected, $result);
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:12,代码来源:RouterTest.php

示例4: testMatchOverRequestParamsWithScope

 public function testMatchOverRequestParamsWithScope()
 {
     Router::scope('app1', function () {
         Router::connect('/hello/world1', 'HelloApp1::index');
     });
     Router::scope('app2', function () {
         Router::connect('/hello/world2', 'HelloApp2::index');
     });
     $request = new Request(array('url' => '/hello/world1'));
     $result = Router::process($request);
     $expected = array('controller' => 'HelloApp1', 'action' => 'index', 'library' => 'app1');
     $this->assertEqual($expected, $result->params);
     $result = Router::match($result->params);
     $this->assertEqual('/hello/world1', $result);
     $request = new Request(array('url' => '/hello/world2'));
     $result = Router::process($request);
     $expected = array('controller' => 'HelloApp2', 'action' => 'index', 'library' => 'app2');
     $this->assertEqual($expected, $result->params);
     $result = Router::match($result->params);
     $this->assertEqual('/hello/world2', $result);
 }
开发者ID:rapzo,项目名称:lithium,代码行数:21,代码来源:RouterTest.php

示例5: testHttpMethodBasedRouting

 /**
  * Tests that routes can be connected and correctly match based on HTTP headers or method verbs.
  *
  * @return void
  */
 public function testHttpMethodBasedRouting()
 {
     Router::connect('/{:controller}/{:id:[0-9]+}', array('http:method' => 'GET', 'action' => 'view'));
     Router::connect('/{:controller}/{:id:[0-9]+}', array('http:method' => 'PUT', 'action' => 'edit'));
     $request = new Request(array('url' => '/posts/13', 'env' => array('REQUEST_METHOD' => 'GET')));
     $params = Router::process($request)->params;
     $expected = array('controller' => 'posts', 'action' => 'view', 'id' => '13');
     $this->assertEqual($expected, $params);
     $this->assertEqual('/posts/13', Router::match($params));
     $request = new Request(array('url' => '/posts/13', 'env' => array('REQUEST_METHOD' => 'PUT')));
     $params = Router::process($request)->params;
     $expected = array('controller' => 'posts', 'action' => 'edit', 'id' => '13');
     $this->assertEqual($expected, $params);
     $request = new Request(array('url' => '/posts/13', 'env' => array('REQUEST_METHOD' => 'POST')));
     $params = Router::process($request)->params;
     $this->assertFalse($params);
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:22,代码来源:RouterTest.php

示例6: testProcessWithAbsoluteAttachmentAndLibrary

 public function testProcessWithAbsoluteAttachmentAndLibrary()
 {
     $request = new Request(array('url' => '/hello_world/index', 'env' => array('HTTP_HOST' => 'bob.amiga.com', 'HTTPS' => false)));
     Router::attach('app', array('absolute' => true, 'host' => '{:subdomain}.amiga.{:tld}', 'scheme' => 'http', 'library' => 'other'));
     Router::scope('app', function () {
         Router::connect('/hello_world/index', array('HelloWorld::index'));
         Router::connect('/{:controller}/{:action}');
     });
     Router::process($request);
     $expected = array('library' => 'other', 'controller' => 'HelloWorld', 'action' => 'index', 'subdomain' => 'bob', 'tld' => 'com');
     $this->assertEqual($expected, $request->params);
     $result = Router::attached('app');
     $this->assertEqual($expected, $result['values']);
     $request = new Request(array('url' => '/posts/index', 'env' => array('HTTP_HOST' => 'bob.amiga.com', 'HTTPS' => false)));
     Router::process($request);
     $expected = array('library' => 'other', 'controller' => 'Posts', 'action' => 'index', 'subdomain' => 'bob', 'tld' => 'com');
     $this->assertEqual($expected, $request->params);
     $result = Router::attached('app');
     $this->assertEqual($expected, $result['values']);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:20,代码来源:RouterTest.php


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