export() public method

Exports the properties that make up the route to an array, for debugging, caching or introspection purposes.
public export ( ) : array
return array An array containing the properties of the route object, such as URL templates and parameter lists.
コード例 #1
0
ファイル: RouteTest.php プロジェクト: niel/lithium
	/**
	 * Tests that route templates with elements containing repetition patterns are correctly parsed.
	 */
	public function testPatternsWithRepetition() {
		$route = new Route(array('template' => '/{:id:[0-9a-f]{24}}.{:type}'));
		$data = $route->export();
		$this->assertEqual('@^(?:/(?P<id>[0-9a-f]{24}))\.(?P<type>[^\/]+)$@', $data['pattern']);

		$this->assertEqual(array('id' => 'id', 'type' => 'type'), $data['keys']);
		$this->assertEqual(array('id' => '[0-9a-f]{24}'), $data['subPatterns']);

		$route = new Route(array('template' => '/{:key:[a-z]{5}[0-9]{2,3}}'));
		$data = $route->export();
		$this->assertEqual('@^(?:/(?P<key>[a-z]{5}[0-9]{2,3}))$@', $data['pattern']);
		$this->assertEqual(array('key' => '[a-z]{5}[0-9]{2,3}'), $data['subPatterns']);

		$this->assertEqual('/abcde13', $route->match(array('key' => 'abcde13')));
		$this->assertFalse($route->match(array('key' => 'abcdef13')));

		$route = new Route(array('template' => '/{:key:z[a-z]{5}[0-9]{2,3}0}/{:val:[0-9]{2}}'));
		$data = $route->export();

		$expected = '@^(?:/(?P<key>z[a-z]{5}[0-9]{2,3}0))(?:/(?P<val>[0-9]{2}))$@';
		$this->assertEqual($expected, $data['pattern']);

		$expected = array('key' => 'z[a-z]{5}[0-9]{2,3}0', 'val' => '[0-9]{2}');
		$this->assertEqual($expected, $data['subPatterns']);

		$result = $route->match(array('key' => 'zgheug910', 'val' => '13'));
		$this->assertEqual('/zgheug910/13', $result);
		$this->assertFalse($route->match(array('key' => 'zgheu910', 'val' => '13')));

		$result = $route->match(array('key' => 'zgheug9410', 'val' => '13'));
		$this->assertEqual('/zgheug9410/13', $result);
		$this->assertFalse($route->match(array('key' => 'zgheug941', 'val' => '13')));
	}
コード例 #2
0
ファイル: RouteTest.php プロジェクト: roopesh90/BlogN
 /**
  * Tests fix for route parameter matching.
  */
 public function testTwoParameterRoutes()
 {
     $route = new Route(array('template' => '/personnel/{:personnel_id}/position/{:position_id}/actions/create', 'params' => array('controller' => 'actions', 'action' => 'create')));
     $route->compile();
     $data = $route->export();
     $actual = $data['pattern'];
     $expected = '@^/personnel(?:/(?P<personnel_id>[^\\/]+))/position(?:/';
     $expected .= '(?P<position_id>[^\\/]+))/actions/create$@u';
     $this->assertEqual($expected, $actual);
 }
コード例 #3
0
ファイル: RouteTest.php プロジェクト: EHER/chegamos
 /**
  * Tests that route templates with elements containing repetition patterns are correctly parsed.
  *
  * @return void
  */
 public function testPatternsWithRepetition()
 {
     $route = new Route(array('template' => '/{:id:[0-9a-f]{24}}.{:type}'));
     $data = $route->export();
     $this->assertEqual('@^(?:/(?P<id>[0-9a-f]{24}))\\.(?P<type>[^\\/]+)$@', $data['pattern']);
     $this->assertEqual(array('id' => 'id', 'type' => 'type'), $data['keys']);
     $this->assertEqual(array('id' => '[0-9a-f]{24}'), $data['subPatterns']);
 }