本文整理汇总了PHP中Route::matches方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::matches方法的具体用法?PHP Route::matches怎么用?PHP Route::matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::matches方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequiredParametersAreNeeded
/**
* This tests that routes with required parameters will not match uris without them present
*
* @test
* @covers Route
*/
function testRequiredParametersAreNeeded()
{
$route = new Route('admin(/<controller>(/<action>(/<id>)))');
$this->assertFalse($route->matches(''));
$matches = $route->matches('admin');
$this->assertType('array', $matches);
$matches = $route->matches('admin/users/add');
$this->assertType('array', $matches);
$this->assertSame(2, count($matches));
$this->assertArrayHasKey('controller', $matches);
$this->assertArrayHasKey('action', $matches);
}
示例2: matches
public function matches($data)
{
if (parent::matches($data)) {
if ($data->request->method() === $this->method) {
return true;
} else {
$data->available_methods[] = $this->method;
}
}
return false;
}
示例3: getParametersName
private static function getParametersName()
{
$arr = [];
preg_match_all('#{[\\w]+?}#', self::$route, $matches);
if (count($matches) == 0) {
return self::$matches = [];
}
foreach ($matches[0] as $match) {
$arr[] = str_replace(' ', '', trim(trim($match, '{'), '}'));
}
return self::$matches = $arr;
}
示例4: test_required_parameters_are_needed
/**
* This tests that routes with required parameters will not match uris without them present
*
* @dataProvider provider_required_parameters_are_needed
*
* @test
* @covers Route::matches
*/
public function test_required_parameters_are_needed($uri, $matches_route1, $matches_route2)
{
$route = new Route($uri);
// Mock a request class that will return empty uri
$request = $this->get_request_mock('');
$this->assertFalse($route->matches($request));
// Mock a request class that will return route1
$request = $this->get_request_mock($matches_route1);
$matches = $route->matches($request);
$this->assertInternalType('array', $matches);
// Mock a request class that will return route2 uri
$request = $this->get_request_mock($matches_route2);
$matches = $route->matches($request);
$this->assertInternalType('array', $matches);
// $this->assertSame(5, count($matches));
$this->assertArrayHasKey('controller', $matches);
$this->assertArrayHasKey('action', $matches);
}
示例5: addStaticRoute
/**
*
*/
private function addStaticRoute($routeData, Route $route)
{
$handler = $route->getHandler();
$routeStr = $routeData[0];
foreach ($route->getMethod() as $method) {
if (isset($this->staticRoutes[$method][$routeStr])) {
throw new Exception("Cannot register two routes matching \"{$routeStr}\" for method \"{$method}\"");
}
if (isset($this->dynamicRoutes[$method])) {
foreach ($this->dynamicRoutes[$method] as $route) {
if ($route->matches($routeStr)) {
throw new Exception("Static route \"{$routeStr}\" is shadowed by previously defined variable route \"{$route->getPath()}\" for method \"{$method}\"");
}
}
}
$this->staticRoutes[$method][$routeStr] = $handler;
}
}
示例6: test_required_parameters_are_needed
/**
* This tests that routes with required parameters will not match uris without them present
*
* @dataProvider provider_required_parameters_are_needed
*
* @test
* @covers Route::matches
*/
public function test_required_parameters_are_needed($uri, $matches_route1, $matches_route2)
{
$route = new Route($uri);
$this->assertFalse($route->matches(''));
$matches = $route->matches($matches_route1);
$this->assertInternalType('array', $matches);
$matches = $route->matches($matches_route2);
$this->assertInternalType('array', $matches);
// $this->assertSame(5, count($matches));
$this->assertArrayHasKey('controller', $matches);
$this->assertArrayHasKey('action', $matches);
}
示例7: testRouteMatchesResourceWithUnreservedMarks
public function testRouteMatchesResourceWithUnreservedMarks()
{
$marks = "-_.!~*'()";
$resource = 'marks/' . $marks;
$route = new Route('/marks/:marks', function () {
});
$result = $route->matches($resource);
$this->assertTrue($result);
$this->assertEquals($route->params(), array('marks' => $marks));
}
示例8: test_required_parameters_are_needed
/**
* This tests that routes with required parameters will not match uris without them present
*
* @dataProvider provider_required_parameters_are_needed
*
* @test
* @covers Route::matches
*/
public function test_required_parameters_are_needed($uri, $matches_route1, $matches_route2)
{
$route = new Route($uri);
// Mock a request class that will return empty uri
$request = $this->getMock('Request', array('uri'), array(''));
$request->expects($this->any())->method('uri')->will($this->returnValue(''));
$this->assertFalse($route->matches($request));
// Mock a request class that will return route1
$request = $this->getMock('Request', array('uri'), array($matches_route1));
$request->expects($this->any())->method('uri')->will($this->returnValue($matches_route1));
$matches = $route->matches($request);
$this->assertInternalType('array', $matches);
// Mock a request class that will return route2 uri
$request = $this->getMock('Request', array('uri'), array($matches_route2));
$request->expects($this->any())->method('uri')->will($this->returnValue($matches_route2));
$matches = $route->matches($request);
$this->assertInternalType('array', $matches);
// $this->assertSame(5, count($matches));
$this->assertArrayHasKey('controller', $matches);
$this->assertArrayHasKey('action', $matches);
}
示例9: testRouteDoesNotMatchResourceWithConditions
/**
* Route does not match URI with conditions
*/
public function testRouteDoesNotMatchResourceWithConditions()
{
$resource = 'hello/Josh/and/John';
$route = new Route('/hello/:first/and/:second', function () {
});
$route->conditions(array('first' => '[a-z]{3,}'));
$result = $route->matches($resource);
$this->assertFalse($result);
$this->assertEquals($route->params(), array());
}
示例10: testMatchesWithoutHttpMethodShouldReturnFalseForNonMatchingPaths
public function testMatchesWithoutHttpMethodShouldReturnFalseForNonMatchingPaths()
{
$route = new Route('GET', '/test', function () {
});
$request = Request::create(false, 'localhost', '/unknown-route', null, 'POST');
$this->assertFalse($route->matches($request));
$this->assertFalse($route->matchesWithoutHttpMethod($request));
}