@@ -4,16 +4,16 @@ |
||
| 4 | 4 | * Set error reporting to maximum |
| 5 | 5 | */ |
| 6 | 6 | error_reporting( -1 ); |
| 7 | -ini_set('display_errors', '1'); |
|
| 7 | +ini_set( 'display_errors', '1' ); |
|
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | /* |
| 11 | 11 | * Set locale settings to reasonable defaults |
| 12 | 12 | */ |
| 13 | -setlocale(LC_ALL, 'en_US.UTF-8'); |
|
| 14 | -setlocale(LC_NUMERIC, 'POSIX'); |
|
| 15 | -setlocale(LC_CTYPE, 'en_US.UTF-8'); |
|
| 16 | -setlocale(LC_TIME, 'POSIX'); |
|
| 13 | +setlocale( LC_ALL, 'en_US.UTF-8' ); |
|
| 14 | +setlocale( LC_NUMERIC, 'POSIX' ); |
|
| 15 | +setlocale( LC_CTYPE, 'en_US.UTF-8' ); |
|
| 16 | +setlocale( LC_TIME, 'POSIX' ); |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | require_once 'TestHelper.php'; |
@@ -24,37 +24,37 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function testRelativePathFor() |
| 26 | 26 | { |
| 27 | - $this->router->setBasePath('/base/path'); |
|
| 27 | + $this->router->setBasePath( '/base/path' ); |
|
| 28 | 28 | |
| 29 | 29 | $methods = ['GET']; |
| 30 | 30 | $pattern = '/hello/{first:\w+}/{last}'; |
| 31 | - $callable = function ( $request, $response, $args ) { |
|
| 32 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
| 31 | + $callable = function( $request, $response, $args ) { |
|
| 32 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
| 33 | 33 | }; |
| 34 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 35 | - $route->setName('foo'); |
|
| 34 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 35 | + $route->setName( 'foo' ); |
|
| 36 | 36 | |
| 37 | 37 | $this->assertEquals( |
| 38 | 38 | '/hello/josh/lockhart', |
| 39 | - $this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
| 39 | + $this->router->relativePathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function testPathForWithNoBasePath() |
| 44 | 44 | { |
| 45 | - $this->router->setBasePath(''); |
|
| 45 | + $this->router->setBasePath( '' ); |
|
| 46 | 46 | |
| 47 | 47 | $methods = ['GET']; |
| 48 | 48 | $pattern = '/hello/{first:\w+}/{last}'; |
| 49 | - $callable = function ( $request, $response, $args ) { |
|
| 50 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
| 49 | + $callable = function( $request, $response, $args ) { |
|
| 50 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
| 51 | 51 | }; |
| 52 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 53 | - $route->setName('foo'); |
|
| 52 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 53 | + $route->setName( 'foo' ); |
|
| 54 | 54 | |
| 55 | 55 | $this->assertEquals( |
| 56 | 56 | '/hello/josh/lockhart', |
| 57 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
| 57 | + $this->router->pathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
| 58 | 58 | ); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -62,16 +62,16 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $methods = ['GET']; |
| 64 | 64 | $pattern = '/hello/{first:\w+}/{last}'; |
| 65 | - $callable = function ( $request, $response, $args ) { |
|
| 66 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
| 65 | + $callable = function( $request, $response, $args ) { |
|
| 66 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
| 67 | 67 | }; |
| 68 | - $this->router->setBasePath('/base/path'); |
|
| 69 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 70 | - $route->setName('foo'); |
|
| 68 | + $this->router->setBasePath( '/base/path' ); |
|
| 69 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 70 | + $route->setName( 'foo' ); |
|
| 71 | 71 | |
| 72 | 72 | $this->assertEquals( |
| 73 | 73 | '/base/path/hello/josh/lockhart', |
| 74 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
| 74 | + $this->router->pathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,23 +79,23 @@ discard block |
||
| 79 | 79 | { |
| 80 | 80 | $methods = ['GET']; |
| 81 | 81 | $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]'; |
| 82 | - $callable = function ( $request, $response, $args ) { |
|
| 82 | + $callable = function( $request, $response, $args ) { |
|
| 83 | 83 | return $response; |
| 84 | 84 | }; |
| 85 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 86 | - $route->setName('foo'); |
|
| 85 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 86 | + $route->setName( 'foo' ); |
|
| 87 | 87 | |
| 88 | 88 | $this->assertEquals( |
| 89 | 89 | '/archive/2015', |
| 90 | - $this->router->pathFor('foo', ['year' => '2015']) |
|
| 90 | + $this->router->pathFor( 'foo', ['year' => '2015'] ) |
|
| 91 | 91 | ); |
| 92 | 92 | $this->assertEquals( |
| 93 | 93 | '/archive/2015/07', |
| 94 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07']) |
|
| 94 | + $this->router->pathFor( 'foo', ['year' => '2015', 'month' => '07'] ) |
|
| 95 | 95 | ); |
| 96 | 96 | $this->assertEquals( |
| 97 | 97 | '/archive/2015/07/d/19', |
| 98 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19']) |
|
| 98 | + $this->router->pathFor( 'foo', ['year' => '2015', 'month' => '07', 'day' => '19'] ) |
|
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | $methods = ['GET']; |
| 105 | 105 | $pattern = '/hello/{name}'; |
| 106 | - $callable = function ( $request, $response, $args ) { |
|
| 107 | - echo sprintf('Hello %s', $args['name']); |
|
| 106 | + $callable = function( $request, $response, $args ) { |
|
| 107 | + echo sprintf( 'Hello %s', $args['name'] ); |
|
| 108 | 108 | }; |
| 109 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 110 | - $route->setName('foo'); |
|
| 109 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 110 | + $route->setName( 'foo' ); |
|
| 111 | 111 | |
| 112 | 112 | $this->assertEquals( |
| 113 | 113 | '/hello/josh?a=b', |
| 114 | - $this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b']) |
|
| 114 | + $this->router->pathFor( 'foo', ['name' => 'josh', 'a' => 'b'] ) |
|
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $methods = ['GET']; |
| 124 | 124 | $pattern = '/hello/{first}/{last}'; |
| 125 | - $callable = function ( $request, $response, $args ) { |
|
| 126 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
| 125 | + $callable = function( $request, $response, $args ) { |
|
| 126 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
| 127 | 127 | }; |
| 128 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 129 | - $route->setName('foo'); |
|
| 128 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 129 | + $route->setName( 'foo' ); |
|
| 130 | 130 | |
| 131 | - $this->router->pathFor('foo', ['last' => 'lockhart']); |
|
| 131 | + $this->router->pathFor( 'foo', ['last' => 'lockhart'] ); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | $methods = ['GET']; |
| 140 | 140 | $pattern = '/hello/{first}/{last}'; |
| 141 | - $callable = function ( $request, $response, $args ) { |
|
| 142 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
| 141 | + $callable = function( $request, $response, $args ) { |
|
| 142 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
| 143 | 143 | }; |
| 144 | - $route = $this->router->map($methods, $pattern, $callable); |
|
| 145 | - $route->setName('foo'); |
|
| 144 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
| 145 | + $route->setName( 'foo' ); |
|
| 146 | 146 | |
| 147 | - $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']); |
|
| 147 | + $this->router->pathFor( 'bar', ['first' => 'josh', 'last' => 'lockhart'] ); |
|
| 148 | 148 | } |
| 149 | 149 | } |
@@ -36,27 +36,27 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function relativePathFor( $name, array $data = [], array $queryParams = [] ) |
| 38 | 38 | { |
| 39 | - $route = $this->getNamedRoute($name); |
|
| 39 | + $route = $this->getNamedRoute( $name ); |
|
| 40 | 40 | $pattern = $route->getPattern(); |
| 41 | 41 | |
| 42 | - $routeDatas = $this->routeParser->parse($pattern); |
|
| 42 | + $routeDatas = $this->routeParser->parse( $pattern ); |
|
| 43 | 43 | // $routeDatas is an array of all possible routes that can be made. There is |
| 44 | 44 | // one routedata for each optional parameter plus one for no optional parameters. |
| 45 | 45 | // |
| 46 | 46 | // The most specific is last, so we look for that first. |
| 47 | - $routeDatas = array_reverse($routeDatas); |
|
| 47 | + $routeDatas = array_reverse( $routeDatas ); |
|
| 48 | 48 | |
| 49 | 49 | $segments = $segmentKeys = []; |
| 50 | - foreach ( $routeDatas as $routeData ) { |
|
| 51 | - foreach ( $routeData as $item ) { |
|
| 52 | - if ( is_string($item) ) { |
|
| 50 | + foreach( $routeDatas as $routeData ) { |
|
| 51 | + foreach( $routeData as $item ) { |
|
| 52 | + if( is_string( $item ) ) { |
|
| 53 | 53 | // this segment is a static string |
| 54 | 54 | $segments[] = $item; |
| 55 | 55 | continue; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // This segment has a parameter: first element is the name |
| 59 | - if ( !array_key_exists($item[0], $data) ) { |
|
| 59 | + if( !array_key_exists( $item[0], $data ) ) { |
|
| 60 | 60 | // we don't have a data element for this segment: cancel |
| 61 | 61 | // testing this routeData item, so that we can try a less |
| 62 | 62 | // specific routeData item. |
@@ -67,21 +67,21 @@ discard block |
||
| 67 | 67 | $segments[] = $data[$item[0]]; |
| 68 | 68 | $segmentKeys[$item[0]] = true; |
| 69 | 69 | } |
| 70 | - if ( !empty($segments) ) { |
|
| 70 | + if( !empty( $segments ) ) { |
|
| 71 | 71 | // we found all the parameters for this route data, no need to check |
| 72 | 72 | // less specific ones |
| 73 | 73 | break; |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( empty($segments) ) { |
|
| 78 | - throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName); |
|
| 77 | + if( empty( $segments ) ) { |
|
| 78 | + throw new InvalidArgumentException( 'Missing data for URL segment: ' . $segmentName ); |
|
| 79 | 79 | } |
| 80 | - $url = implode('', $segments); |
|
| 80 | + $url = implode( '', $segments ); |
|
| 81 | 81 | |
| 82 | - $params = array_merge(array_diff_key($data, $segmentKeys), $queryParams); |
|
| 83 | - if ( $params ) { |
|
| 84 | - $url .= '?' . http_build_query($params); |
|
| 82 | + $params = array_merge( array_diff_key( $data, $segmentKeys ), $queryParams ); |
|
| 83 | + if( $params ) { |
|
| 84 | + $url .= '?' . http_build_query( $params ); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | return $url; |