Completed
Push — master ( 069441...8a02a6 )
by Aimeos
07:19
created
lib/custom/src/Slim/Router.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -22,68 +22,68 @@
 block discarded – undo
22 22
  */
23 23
 class Router extends \Slim\Router
24 24
 {
25
-    /**
26
-     * Build the path for a named route excluding the base path
27
-     *
28
-     * @param string $name        Route name
29
-     * @param array  $data        Named argument replacement data
30
-     * @param array  $queryParams Optional query string parameters
31
-     *
32
-     * @return string
33
-     *
34
-     * @throws RuntimeException         If named route does not exist
35
-     * @throws InvalidArgumentException If required data not provided
36
-     */
37
-    public function relativePathFor($name, array $data = [], array $queryParams = [])
38
-    {
39
-        $route = $this->getNamedRoute($name);
40
-        $pattern = $route->getPattern();
25
+	/**
26
+	 * Build the path for a named route excluding the base path
27
+	 *
28
+	 * @param string $name        Route name
29
+	 * @param array  $data        Named argument replacement data
30
+	 * @param array  $queryParams Optional query string parameters
31
+	 *
32
+	 * @return string
33
+	 *
34
+	 * @throws RuntimeException         If named route does not exist
35
+	 * @throws InvalidArgumentException If required data not provided
36
+	 */
37
+	public function relativePathFor($name, array $data = [], array $queryParams = [])
38
+	{
39
+		$route = $this->getNamedRoute($name);
40
+		$pattern = $route->getPattern();
41 41
 
42
-        $routeDatas = $this->routeParser->parse($pattern);
43
-        // $routeDatas is an array of all possible routes that can be made. There is
44
-        // one routedata for each optional parameter plus one for no optional parameters.
45
-        //
46
-        // The most specific is last, so we look for that first.
47
-        $routeDatas = array_reverse($routeDatas);
42
+		$routeDatas = $this->routeParser->parse($pattern);
43
+		// $routeDatas is an array of all possible routes that can be made. There is
44
+		// one routedata for each optional parameter plus one for no optional parameters.
45
+		//
46
+		// The most specific is last, so we look for that first.
47
+		$routeDatas = array_reverse($routeDatas);
48 48
 
49
-        $segments = $segmentKeys = [];
50
-        foreach ($routeDatas as $routeData) {
51
-            foreach ($routeData as $item) {
52
-                if (is_string($item)) {
53
-                    // this segment is a static string
54
-                    $segments[] = $item;
55
-                    continue;
56
-                }
49
+		$segments = $segmentKeys = [];
50
+		foreach ($routeDatas as $routeData) {
51
+			foreach ($routeData as $item) {
52
+				if (is_string($item)) {
53
+					// this segment is a static string
54
+					$segments[] = $item;
55
+					continue;
56
+				}
57 57
 
58
-                // This segment has a parameter: first element is the name
59
-                if (!array_key_exists($item[0], $data)) {
60
-                    // we don't have a data element for this segment: cancel
61
-                    // testing this routeData item, so that we can try a less
62
-                    // specific routeData item.
63
-                    $segments = [];
64
-                    $segmentName = $item[0];
65
-                    break;
66
-                }
67
-                $segments[] = $data[$item[0]];
68
-                $segmentKeys[$item[0]] = true;
69
-            }
70
-            if (!empty($segments)) {
71
-                // we found all the parameters for this route data, no need to check
72
-                // less specific ones
73
-                break;
74
-            }
75
-        }
58
+				// This segment has a parameter: first element is the name
59
+				if (!array_key_exists($item[0], $data)) {
60
+					// we don't have a data element for this segment: cancel
61
+					// testing this routeData item, so that we can try a less
62
+					// specific routeData item.
63
+					$segments = [];
64
+					$segmentName = $item[0];
65
+					break;
66
+				}
67
+				$segments[] = $data[$item[0]];
68
+				$segmentKeys[$item[0]] = true;
69
+			}
70
+			if (!empty($segments)) {
71
+				// we found all the parameters for this route data, no need to check
72
+				// less specific ones
73
+				break;
74
+			}
75
+		}
76 76
 
77
-        if (empty($segments)) {
78
-            throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
79
-        }
80
-        $url = implode('', $segments);
77
+		if (empty($segments)) {
78
+			throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
79
+		}
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);
85
-        }
82
+		$params = array_merge(array_diff_key($data, $segmentKeys), $queryParams);
83
+		if ($params) {
84
+			$url .= '?' . http_build_query($params);
85
+		}
86 86
 
87
-        return $url;
88
-    }
87
+		return $url;
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,13 +75,13 @@
 block discarded – undo
75 75
         }
76 76
 
77 77
         if (empty($segments)) {
78
-            throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
78
+            throw new InvalidArgumentException('Missing data for URL segment: '.$segmentName);
79 79
         }
80 80
         $url = implode('', $segments);
81 81
 
82 82
         $params = array_merge(array_diff_key($data, $segmentKeys), $queryParams);
83 83
         if ($params) {
84
-            $url .= '?' . http_build_query($params);
84
+            $url .= '?'.http_build_query($params);
85 85
         }
86 86
 
87 87
         return $url;
Please login to merge, or discard this patch.
lib/custom/src/MW/View/Helper/Url/Slim.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 * @param \Slim\Router $router Slim router object
33 33
 	 * @param array Associative list of fixed parameters that should be available for all routes
34 34
 	 */
35
-	public function __construct( \Aimeos\MW\View\Iface $view, \Slim\Router $router, array $fixed )
35
+	public function __construct(\Aimeos\MW\View\Iface $view, \Slim\Router $router, array $fixed)
36 36
 	{
37
-		parent::__construct( $view );
37
+		parent::__construct($view);
38 38
 
39 39
 		$this->router = $router;
40 40
 		$this->fixed = $fixed;
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 	 * @param array $config Additional configuration parameter per URL
53 53
 	 * @return string Complete URL that can be used in the template
54 54
 	 */
55
-	public function transform( $target = null, $controller = null, $action = null, array $params = array(), array $trailing = array(), array $config = array() )
55
+	public function transform($target = null, $controller = null, $action = null, array $params = array(), array $trailing = array(), array $config = array())
56 56
 	{
57
-		$params = $this->sanitize( $params );
57
+		$params = $this->sanitize($params);
58 58
 
59
-		if( isset( $config['absoluteUri'] ) && (bool) $config['absoluteUri'] === true ) {
60
-			return $this->router->pathFor( $target, $this->fixed + $params );
59
+		if (isset($config['absoluteUri']) && (bool) $config['absoluteUri'] === true) {
60
+			return $this->router->pathFor($target, $this->fixed + $params);
61 61
 		}
62 62
 
63
-		return $this->router->relativePathFor( $target, $this->fixed + $params );
63
+		return $this->router->relativePathFor($target, $this->fixed + $params);
64 64
 	}
65 65
 }
66 66
\ No newline at end of file
Please login to merge, or discard this patch.
lib/custom/tests/Slim/RouterTest.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -10,136 +10,136 @@
 block discarded – undo
10 10
 
11 11
 class RouterTest extends \PHPUnit_Framework_TestCase
12 12
 {
13
-    /** @var Router */
14
-    protected $router;
15
-
16
-    public function setUp()
17
-    {
18
-        $this->router = new \Aimeos\Slim\Router;
19
-    }
20
-
21
-    public function testRelativePathFor()
22
-    {
23
-        $this->router->setBasePath('/base/path');
24
-
25
-        $methods = ['GET'];
26
-        $pattern = '/hello/{first:\w+}/{last}';
27
-        $callable = function ($request, $response, $args) {
28
-            echo sprintf('Hello %s %s', $args['first'], $args['last']);
29
-        };
30
-        $route = $this->router->map($methods, $pattern, $callable);
31
-        $route->setName('foo');
32
-
33
-        $this->assertEquals(
34
-            '/hello/josh/lockhart',
35
-            $this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
36
-        );
37
-    }
38
-
39
-    public function testPathForWithNoBasePath()
40
-    {
41
-        $this->router->setBasePath('');
42
-
43
-        $methods = ['GET'];
44
-        $pattern = '/hello/{first:\w+}/{last}';
45
-        $callable = function ($request, $response, $args) {
46
-            echo sprintf('Hello %s %s', $args['first'], $args['last']);
47
-        };
48
-        $route = $this->router->map($methods, $pattern, $callable);
49
-        $route->setName('foo');
50
-
51
-        $this->assertEquals(
52
-            '/hello/josh/lockhart',
53
-            $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
54
-        );
55
-    }
56
-
57
-    public function testPathForWithBasePath()
58
-    {
59
-        $methods = ['GET'];
60
-        $pattern = '/hello/{first:\w+}/{last}';
61
-        $callable = function ($request, $response, $args) {
62
-            echo sprintf('Hello %s %s', $args['first'], $args['last']);
63
-        };
64
-        $this->router->setBasePath('/base/path');
65
-        $route = $this->router->map($methods, $pattern, $callable);
66
-        $route->setName('foo');
67
-
68
-        $this->assertEquals(
69
-            '/base/path/hello/josh/lockhart',
70
-            $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
71
-        );
72
-    }
73
-
74
-    public function testPathForWithOptionalParameters()
75
-    {
76
-        $methods = ['GET'];
77
-        $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]';
78
-        $callable = function ($request, $response, $args) {
79
-            return $response;
80
-        };
81
-        $route = $this->router->map($methods, $pattern, $callable);
82
-        $route->setName('foo');
83
-
84
-        $this->assertEquals(
85
-            '/archive/2015',
86
-            $this->router->pathFor('foo', ['year' => '2015'])
87
-        );
88
-        $this->assertEquals(
89
-            '/archive/2015/07',
90
-            $this->router->pathFor('foo', ['year' => '2015', 'month' => '07'])
91
-        );
92
-        $this->assertEquals(
93
-            '/archive/2015/07/d/19',
94
-            $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19'])
95
-        );
96
-    }
97
-
98
-    public function testPathForWithSurplusRouteParameters()
99
-    {
100
-        $methods = ['GET'];
101
-        $pattern = '/hello/{name}';
102
-        $callable = function ($request, $response, $args) {
103
-            echo sprintf('Hello %s', $args['name']);
104
-        };
105
-        $route = $this->router->map($methods, $pattern, $callable);
106
-        $route->setName('foo');
107
-
108
-        $this->assertEquals(
109
-            '/hello/josh?a=b',
110
-            $this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b'])
111
-        );
112
-    }
113
-
114
-    /**
115
-     * @expectedException \InvalidArgumentException
116
-     */
117
-    public function testPathForWithMissingSegmentData()
118
-    {
119
-        $methods = ['GET'];
120
-        $pattern = '/hello/{first}/{last}';
121
-        $callable = function ($request, $response, $args) {
122
-            echo sprintf('Hello %s %s', $args['first'], $args['last']);
123
-        };
124
-        $route = $this->router->map($methods, $pattern, $callable);
125
-        $route->setName('foo');
126
-
127
-        $this->router->pathFor('foo', ['last' => 'lockhart']);
128
-    }
129
-
130
-    /**
131
-     * @expectedException \RuntimeException
132
-     */
133
-    public function testPathForRouteNotExists()
134
-    {
135
-        $methods = ['GET'];
136
-        $pattern = '/hello/{first}/{last}';
137
-        $callable = function ($request, $response, $args) {
138
-            echo sprintf('Hello %s %s', $args['first'], $args['last']);
139
-        };
140
-        $route = $this->router->map($methods, $pattern, $callable);
141
-        $route->setName('foo');
142
-
143
-        $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']);
144
-    }
13
+	/** @var Router */
14
+	protected $router;
15
+
16
+	public function setUp()
17
+	{
18
+		$this->router = new \Aimeos\Slim\Router;
19
+	}
20
+
21
+	public function testRelativePathFor()
22
+	{
23
+		$this->router->setBasePath('/base/path');
24
+
25
+		$methods = ['GET'];
26
+		$pattern = '/hello/{first:\w+}/{last}';
27
+		$callable = function ($request, $response, $args) {
28
+			echo sprintf('Hello %s %s', $args['first'], $args['last']);
29
+		};
30
+		$route = $this->router->map($methods, $pattern, $callable);
31
+		$route->setName('foo');
32
+
33
+		$this->assertEquals(
34
+			'/hello/josh/lockhart',
35
+			$this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
36
+		);
37
+	}
38
+
39
+	public function testPathForWithNoBasePath()
40
+	{
41
+		$this->router->setBasePath('');
42
+
43
+		$methods = ['GET'];
44
+		$pattern = '/hello/{first:\w+}/{last}';
45
+		$callable = function ($request, $response, $args) {
46
+			echo sprintf('Hello %s %s', $args['first'], $args['last']);
47
+		};
48
+		$route = $this->router->map($methods, $pattern, $callable);
49
+		$route->setName('foo');
50
+
51
+		$this->assertEquals(
52
+			'/hello/josh/lockhart',
53
+			$this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
54
+		);
55
+	}
56
+
57
+	public function testPathForWithBasePath()
58
+	{
59
+		$methods = ['GET'];
60
+		$pattern = '/hello/{first:\w+}/{last}';
61
+		$callable = function ($request, $response, $args) {
62
+			echo sprintf('Hello %s %s', $args['first'], $args['last']);
63
+		};
64
+		$this->router->setBasePath('/base/path');
65
+		$route = $this->router->map($methods, $pattern, $callable);
66
+		$route->setName('foo');
67
+
68
+		$this->assertEquals(
69
+			'/base/path/hello/josh/lockhart',
70
+			$this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
71
+		);
72
+	}
73
+
74
+	public function testPathForWithOptionalParameters()
75
+	{
76
+		$methods = ['GET'];
77
+		$pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]';
78
+		$callable = function ($request, $response, $args) {
79
+			return $response;
80
+		};
81
+		$route = $this->router->map($methods, $pattern, $callable);
82
+		$route->setName('foo');
83
+
84
+		$this->assertEquals(
85
+			'/archive/2015',
86
+			$this->router->pathFor('foo', ['year' => '2015'])
87
+		);
88
+		$this->assertEquals(
89
+			'/archive/2015/07',
90
+			$this->router->pathFor('foo', ['year' => '2015', 'month' => '07'])
91
+		);
92
+		$this->assertEquals(
93
+			'/archive/2015/07/d/19',
94
+			$this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19'])
95
+		);
96
+	}
97
+
98
+	public function testPathForWithSurplusRouteParameters()
99
+	{
100
+		$methods = ['GET'];
101
+		$pattern = '/hello/{name}';
102
+		$callable = function ($request, $response, $args) {
103
+			echo sprintf('Hello %s', $args['name']);
104
+		};
105
+		$route = $this->router->map($methods, $pattern, $callable);
106
+		$route->setName('foo');
107
+
108
+		$this->assertEquals(
109
+			'/hello/josh?a=b',
110
+			$this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b'])
111
+		);
112
+	}
113
+
114
+	/**
115
+	 * @expectedException \InvalidArgumentException
116
+	 */
117
+	public function testPathForWithMissingSegmentData()
118
+	{
119
+		$methods = ['GET'];
120
+		$pattern = '/hello/{first}/{last}';
121
+		$callable = function ($request, $response, $args) {
122
+			echo sprintf('Hello %s %s', $args['first'], $args['last']);
123
+		};
124
+		$route = $this->router->map($methods, $pattern, $callable);
125
+		$route->setName('foo');
126
+
127
+		$this->router->pathFor('foo', ['last' => 'lockhart']);
128
+	}
129
+
130
+	/**
131
+	 * @expectedException \RuntimeException
132
+	 */
133
+	public function testPathForRouteNotExists()
134
+	{
135
+		$methods = ['GET'];
136
+		$pattern = '/hello/{first}/{last}';
137
+		$callable = function ($request, $response, $args) {
138
+			echo sprintf('Hello %s %s', $args['first'], $args['last']);
139
+		};
140
+		$route = $this->router->map($methods, $pattern, $callable);
141
+		$route->setName('foo');
142
+
143
+		$this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']);
144
+	}
145 145
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
         $methods = ['GET'];
26 26
         $pattern = '/hello/{first:\w+}/{last}';
27
-        $callable = function ($request, $response, $args) {
27
+        $callable = function($request, $response, $args) {
28 28
             echo sprintf('Hello %s %s', $args['first'], $args['last']);
29 29
         };
30 30
         $route = $this->router->map($methods, $pattern, $callable);
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
         $methods = ['GET'];
44 44
         $pattern = '/hello/{first:\w+}/{last}';
45
-        $callable = function ($request, $response, $args) {
45
+        $callable = function($request, $response, $args) {
46 46
             echo sprintf('Hello %s %s', $args['first'], $args['last']);
47 47
         };
48 48
         $route = $this->router->map($methods, $pattern, $callable);
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $methods = ['GET'];
60 60
         $pattern = '/hello/{first:\w+}/{last}';
61
-        $callable = function ($request, $response, $args) {
61
+        $callable = function($request, $response, $args) {
62 62
             echo sprintf('Hello %s %s', $args['first'], $args['last']);
63 63
         };
64 64
         $this->router->setBasePath('/base/path');
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     {
76 76
         $methods = ['GET'];
77 77
         $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]';
78
-        $callable = function ($request, $response, $args) {
78
+        $callable = function($request, $response, $args) {
79 79
             return $response;
80 80
         };
81 81
         $route = $this->router->map($methods, $pattern, $callable);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     {
100 100
         $methods = ['GET'];
101 101
         $pattern = '/hello/{name}';
102
-        $callable = function ($request, $response, $args) {
102
+        $callable = function($request, $response, $args) {
103 103
             echo sprintf('Hello %s', $args['name']);
104 104
         };
105 105
         $route = $this->router->map($methods, $pattern, $callable);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $methods = ['GET'];
120 120
         $pattern = '/hello/{first}/{last}';
121
-        $callable = function ($request, $response, $args) {
121
+        $callable = function($request, $response, $args) {
122 122
             echo sprintf('Hello %s %s', $args['first'], $args['last']);
123 123
         };
124 124
         $route = $this->router->map($methods, $pattern, $callable);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     {
135 135
         $methods = ['GET'];
136 136
         $pattern = '/hello/{first}/{last}';
137
-        $callable = function ($request, $response, $args) {
137
+        $callable = function($request, $response, $args) {
138 138
             echo sprintf('Hello %s %s', $args['first'], $args['last']);
139 139
         };
140 140
         $route = $this->router->map($methods, $pattern, $callable);
Please login to merge, or discard this patch.