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


PHP Route::defaults方法代码示例

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


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

示例1: test_cache_miss

 /**
  * Tests that the client attempts to load a cached response from the
  * cache library, but fails.
  *
  * @return void
  */
 public function test_cache_miss()
 {
     $route = new Route('welcome/index');
     $route->defaults(array('controller' => 'Kohana_Request_CacheTest_Dummy', 'action' => 'index'));
     $request = new Request('welcome/index', NULL, array($route));
     $cache_mock = $this->_get_cache_mock();
     $request->client()->cache(HTTP_Cache::factory($cache_mock));
     $cache_mock->expects($this->once())->method('get')->with($request->client()->cache()->create_cache_key($request))->will($this->returnValue(FALSE));
     $response = $request->client()->execute($request);
     $this->assertSame(HTTP_Cache::CACHE_STATUS_MISS, $response->headers(HTTP_Cache::CACHE_STATUS_KEY));
 }
开发者ID:lz1988,项目名称:stourwebcms,代码行数:17,代码来源:CacheTest.php

示例2: Route

 /**
  * Defaults specified with defaults() should be used if their values aren't
  * present in the uri
  *
  * @test
  * @covers Route
  */
 function testDefaultsAreUsedIfParamsArentSpecified()
 {
     $route = new Route('(<controller>(/<action>(/<id>)))');
     $route->defaults(array('controller' => 'welcome', 'action' => 'index'));
     $matches = $route->matches('');
     $this->assertType('array', $matches);
     $this->assertArrayHasKey('controller', $matches);
     $this->assertArrayHasKey('action', $matches);
     $this->assertArrayNotHasKey('id', $matches);
     $this->assertSame(2, count($matches));
     $this->assertSame('welcome', $matches['controller']);
     $this->assertSame('index', $matches['action']);
 }
开发者ID:pcraciunoiu,项目名称:unittest,代码行数:20,代码来源:RouteTest.php

示例3: fromArray

 /**
  * Create a Route from an array.
  *
  * @param array $data
  * @return Route
  */
 public static function fromArray(array $data) : self
 {
     $methods = ['*'];
     if (isset($data['methods'])) {
         $methods = preg_split('/\\W+/', strtoupper($data['methods']));
     }
     $path = '/' . ltrim($data['path'], '/');
     $route = new Route();
     $route->path($path)->methods(...$methods)->handler($data['handler']);
     if (isset($data['defaults'])) {
         $route->defaults($data['defaults']);
     }
     if (isset($dat['filters'])) {
         $route->filters(...$data['filters']);
     }
     return $route;
 }
开发者ID:ifcanduela,项目名称:pew,代码行数:23,代码来源:Route.php

示例4: test_param

 /**
  * Ensure that parameters can be read
  *
  * @test
  */
 public function test_param()
 {
     $uri = 'foo/bar/id';
     $request = Request::factory($uri);
     $this->assertArrayHasKey('id', $request->param());
     $this->assertArrayNotHasKey('foo', $request->param());
     $this->assertEquals($request->uri(), $uri);
     // Ensure the params do not contain contamination from controller, action, route, uri etc etc
     $params = $request->param();
     // Test for illegal components
     $this->assertArrayNotHasKey('controller', $params);
     $this->assertArrayNotHasKey('action', $params);
     $this->assertArrayNotHasKey('directory', $params);
     $this->assertArrayNotHasKey('uri', $params);
     $this->assertArrayNotHasKey('route', $params);
     $route = new Route('(<uri>)', array('uri' => '.+'));
     $route->defaults(array('controller' => 'foobar', 'action' => 'index'));
     $request = Request::factory('foobar', NULL, array($route));
     $this->assertSame('foobar', $request->param('uri'));
 }
开发者ID:ricasiano,项目名称:sapakan,代码行数:25,代码来源:RequestTest.php

示例5: uri

 public static function uri($page_id, $name, array $params = NULL, $region = TRUE)
 {
     if (empty(self::$dynamic_routes)) {
         foreach (Kohana::list_files('config' . DIRECTORY_SEPARATOR . 'routes') as $file_key => $file) {
             $_tmp = explode(DIRECTORY_SEPARATOR, $file_key);
             $config_file_name = array_pop($_tmp);
             $routes_config = Kohana::$config->load('routes/' . str_replace('.php', '', $config_file_name))->as_array();
             foreach ($routes_config as $key => $value) {
                 $route = new Route(Arr::get($value, 'uri_callback'), Arr::get($value, 'regex'));
                 $route->defaults(Arr::get($value, 'defaults'));
                 self::$dynamic_routes[$key] = $route;
             }
         }
     }
     if (isset(self::$dynamic_routes[$name])) {
         $base_uri = $page_id !== FALSE ? Page_Route::dynamic_base_uri($page_id) : '_module/' . $name;
         $route_uri = self::$dynamic_routes[$name]->uri($params, $region);
         return $base_uri . $route_uri;
     }
     return NULL;
 }
开发者ID:greor,项目名称:satin-spb,代码行数:21,代码来源:route.php

示例6: test_route_filter_modify_params

 /**
  * Tests that route filters can modify parameters
  *
  * @covers Route::filter
  * @dataProvider provider_route_filter_modify_params
  */
 public function test_route_filter_modify_params($route, $defaults, $filter, $uri, $expected_params)
 {
     $route = new Route($route);
     // Mock a request class
     $request = $this->get_request_mock($uri);
     $params = $route->defaults($defaults)->filter($filter)->matches($request);
     $this->assertSame($expected_params, $params);
 }
开发者ID:robert-kampas,项目名称:games-collection-manager,代码行数:14,代码来源:RouteTest.php

示例7: test_defaults_are_used_if_params_arent_specified

 /**
  * Defaults specified with defaults() should be used if their values aren't
  * present in the uri
  *
  * @dataProvider provider_defaults_are_used_if_params_arent_specified
  *
  * @test
  * @covers Route::matches
  */
 public function test_defaults_are_used_if_params_arent_specified($uri, $regex, $defaults, $c, $a, $test_uri, $test_uri_array, $default_uri)
 {
     $route = new Route($uri, $regex);
     $route->defaults($defaults);
     $matches = $route->matches($default_uri);
     $this->assertInternalType('array', $matches);
     $this->assertArrayHasKey('controller', $matches);
     $this->assertArrayHasKey('action', $matches);
     $this->assertArrayNotHasKey('id', $matches);
     // $this->assertSame(4, count($matches));
     $this->assertSame($c, $matches['controller']);
     $this->assertSame($a, $matches['action']);
     $this->assertSame($test_uri, $route->uri($test_uri_array));
     $this->assertSame($default_uri, $route->uri());
 }
开发者ID:laiello,项目名称:ko3,代码行数:24,代码来源:RouteTest.php

示例8: test_set_routes

 /**
  * @covers ::set_routes
  */
 public function test_set_routes()
 {
     $this->env->backup_and_set(array('site-versions.versions' => array('test' => array())));
     $this->assertCount(1, Route::all());
     $version = new Site_Version('test');
     $version->set_routes(array('homepage' => array('home(/<id>)', array('action' => '\\d+'), array('controller' => 'test', 'action' => 'index'))));
     $this->assertCount(2, Route::all());
     $expected = new Route('home(/<id>)', array('action' => '\\d+'));
     $expected->defaults(array('controller' => 'test', 'action' => 'index'));
     $this->assertEquals($expected, Route::get('homepage'));
 }
开发者ID:openbuildings,项目名称:site-versions,代码行数:14,代码来源:VersionTest.php

示例9: test_defaults_are_used_if_params_arent_specified

 /**
  * Defaults specified with defaults() should be used if their values aren't
  * present in the uri
  *
  * @test
  * @covers Route::matches
  */
 public function test_defaults_are_used_if_params_arent_specified()
 {
     $route = new Route('(<controller>(/<action>(/<id>)))');
     $route->defaults(array('controller' => 'welcome', 'action' => 'index'));
     $matches = $route->matches('');
     $this->assertType('array', $matches);
     $this->assertArrayHasKey('controller', $matches);
     $this->assertArrayHasKey('action', $matches);
     $this->assertArrayNotHasKey('id', $matches);
     $this->assertSame(2, count($matches));
     $this->assertSame('welcome', $matches['controller']);
     $this->assertSame('index', $matches['action']);
     $this->assertSame('unit/test/1', $route->uri(array('controller' => 'unit', 'action' => 'test', 'id' => '1')));
     $this->assertSame('welcome/index', $route->uri());
 }
开发者ID:joelpittet,项目名称:core,代码行数:22,代码来源:RouteTest.php

示例10: provider_uri_only_trimed_on_internal

 /**
  * Provides data for test_uri_only_trimed_on_internal()
  *
  * @return  array
  */
 public function provider_uri_only_trimed_on_internal()
 {
     // issue #3967: inject the route so that we don't conflict with the application's default route
     $route = new Route('(<controller>(/<action>))');
     $route->defaults(array('controller' => 'welcome', 'action' => 'index'));
     $old_request = Request::$initial;
     Request::$initial = new Request(TRUE, array(), TRUE, array($route));
     $result = array(array(new Request('http://www.google.com'), 'http://www.google.com'), array(new Request('http://www.google.com/'), 'http://www.google.com/'), array(new Request('foo/bar/'), 'foo/bar'), array(new Request('foo/bar'), 'foo/bar'), array(new Request('/'), '/'), array(new Request(''), '/'));
     Request::$initial = $old_request;
     return $result;
 }
开发者ID:rens1110,项目名称:website,代码行数:16,代码来源:RequestTest.php

示例11: test_route_filter_modify_params

 /**
  * Tests that route filters can modify parameters
  *
  * @covers Route::filter
  * @dataProvider provider_route_filter_modify_params
  */
 public function test_route_filter_modify_params($route, $defaults, $filter, $uri, $expected_params)
 {
     $route = new Route($route);
     // Mock a request class
     $request = $this->getMock('Request', array('uri'), array($uri));
     $request->expects($this->any())->method('uri')->will($this->returnValue($uri));
     $params = $route->defaults($defaults)->filter($filter)->matches($request);
     $this->assertSame($expected_params, $params);
 }
开发者ID:ortodesign,项目名称:cms,代码行数:15,代码来源:routetest.php

示例12: test_param

 /**
  * Ensure that parameters can be read
  *
  * @test
  */
 public function test_param()
 {
     $route = new Route('(<controller>(/<action>(/<id>)))');
     $uri = 'foo/bar/id';
     $request = Request::factory($uri, NULL, TRUE, array($route));
     // We need to execute the request before it has matched a route
     try {
         $request->execute();
     } catch (Exception $e) {
     }
     $this->assertArrayHasKey('id', $request->param());
     $this->assertArrayNotHasKey('foo', $request->param());
     $this->assertEquals($request->uri(), $uri);
     // Ensure the params do not contain contamination from controller, action, route, uri etc etc
     $params = $request->param();
     // Test for illegal components
     $this->assertArrayNotHasKey('controller', $params);
     $this->assertArrayNotHasKey('action', $params);
     $this->assertArrayNotHasKey('directory', $params);
     $this->assertArrayNotHasKey('uri', $params);
     $this->assertArrayNotHasKey('route', $params);
     $route = new Route('(<uri>)', array('uri' => '.+'));
     $route->defaults(array('controller' => 'foobar', 'action' => 'index'));
     $request = Request::factory('foobar', NULL, TRUE, array($route));
     // We need to execute the request before it has matched a route
     try {
         $request->execute();
     } catch (Exception $e) {
     }
     $this->assertSame('foobar', $request->param('uri'));
 }
开发者ID:EhteshamMehmood,项目名称:BlogMVC,代码行数:36,代码来源:RequestTest.php

示例13: set_module_routes

 public function set_module_routes($routes_config, $uri_base, $prefix, $cache)
 {
     $routes = array();
     foreach ($routes_config as $name => $route) {
         $name = $prefix . '<->' . $name;
         $uri_callback = Arr::get($route, 'uri_callback');
         if (is_string($uri_callback)) {
             $uri_callback = $uri_base . $uri_callback;
         }
         $regex = Arr::get($route, 'regex');
         $defaults = Arr::get($route, 'defaults');
         $route = new Route($uri_callback, $regex, $name);
         $route->defaults($defaults);
         $routes[$name] = $route;
         Route::set($name, $uri_callback, $regex)->defaults($defaults);
     }
     $processed_uri = Request::process_uri($this->uri(), $routes);
     if ($processed_uri !== NULL) {
         $this->set_dinamic_route($processed_uri, $cache);
     }
 }
开发者ID:greor,项目名称:satin-spb,代码行数:21,代码来源:request.php


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