@@ -54,16 +54,31 @@ public function __construct($route, $options = [])
5454 public function toArray ()
5555 {
5656 return array_merge ([
57- 'name ' => $ this ->route ->getName (),
58- 'methods ' => $ this ->route -> getMethods (),
59- 'domain ' => $ this ->route ->domain (),
60- 'path ' => $ this ->preparePath (),
61- 'action ' => $ this ->route ->getAction (),
62- 'wheres ' => $ this ->extractWheres (),
63- 'errors ' => $ this ->errors ,
57+ 'name ' => $ this ->route ->getName (),
58+ 'methods ' => $ this ->getMethods (),
59+ 'domain ' => $ this ->route ->domain (),
60+ 'path ' => $ this ->preparePath (),
61+ 'action ' => $ this ->route ->getAction (),
62+ 'wheres ' => $ this ->extractWheres (),
63+ 'errors ' => $ this ->errors ,
6464 ], $ this ->getMeta (), $ this ->options );
6565 }
6666
67+ /**
68+ * Cross version get methods.
69+ *
70+ * @return array
71+ */
72+ private function getMethods ()
73+ {
74+ // Laravel <5.4
75+ if (method_exists ($ this ->route , 'getMethods ' )) {
76+ $ this ->route ->getMethods ();
77+ }
78+ // Laravel 5.4+
79+ return $ this ->route ->methods ();
80+ }
81+
6782 protected function extractWheres ()
6883 {
6984 $ prop = $ this ->getRouteReflection ()->getProperty ('wheres ' );
@@ -73,7 +88,7 @@ protected function extractWheres()
7388
7489 // Хак, чтобы в json всегда был объект
7590 if (empty ($ wheres )) {
76- return (object )[];
91+ return (object ) [];
7792 }
7893
7994 return $ wheres ;
@@ -94,7 +109,7 @@ protected function extractAnnotation()
94109 {
95110 $ reflection = $ this ->getActionReflection ();
96111
97- if (!is_null ($ reflection )) {
112+ if (! is_null ($ reflection )) {
98113 return $ reflection ->getDocComment ();
99114 }
100115
@@ -114,7 +129,7 @@ protected function extractFormRequest()
114129 // TODO Write the reasoning behind following lines.
115130 try {
116131 $ class = $ parameter ->getClass ();
117- } catch (\ReflectionException $ e ){
132+ } catch (\ReflectionException $ e ) {
118133 break ;
119134 }
120135
@@ -170,18 +185,21 @@ protected function getActionReflection()
170185 list ($ controller , $ action ) = explode ('@ ' , $ uses );
171186
172187 // Если нет контроллера.
173- if (!class_exists ($ controller )) {
188+ if (! class_exists ($ controller )) {
174189 $ this ->setError ('uses ' , 'controller does not exists ' );
190+
175191 return null ;
176192 }
177193
178194 // Если нет метода в контроллере.
179- if (!method_exists ($ controller , $ action )) {
195+ if (! method_exists ($ controller , $ action )) {
180196 $ this ->setError ('uses ' , 'controller@method does not exists ' );
197+
181198 return null ;
182199 }
183200
184- return $ this ->actionReflection = new \ReflectionMethod ($ controller , $ action );
201+ return $ this ->actionReflection = new \ReflectionMethod ($ controller ,
202+ $ action );
185203 }
186204
187205 if (is_callable ($ uses )) {
@@ -195,14 +213,29 @@ protected function getActionReflection()
195213
196214 protected function preparePath ()
197215 {
198- $ path = $ this ->route -> getPath ();
216+ $ path = $ this ->getUri ();
199217 if ($ path === '/ ' ) {
200218 return $ path ;
201219 }
202220
203221 return trim ($ path , '/ ' );
204222 }
205223
224+ /**
225+ * Backwards compatible uri getter.
226+ *
227+ * @return string
228+ */
229+ protected function getUri (){
230+ if (method_exists ($ this ->route , 'getPath ' )){
231+ // Laravel <5.4
232+ return $ this ->route ->getPath ();
233+ }
234+
235+ // Laravel 5.4+
236+ return $ this ->route ->uri ();
237+ }
238+
206239 protected function setError ($ type , $ text , $ params = [])
207240 {
208241 $ this ->errors [$ type ] = trans ($ text , $ params );
@@ -215,9 +248,9 @@ protected function getMeta()
215248 {
216249 if ($ this ->addMeta ) {
217250 return [
218- 'annotation ' => $ this ->extractAnnotation (),
251+ 'annotation ' => $ this ->extractAnnotation (),
219252 'formRequest ' => $ this ->extractFormRequest (),
220- 'errors ' => $ this ->errors ,
253+ 'errors ' => $ this ->errors ,
221254 ];
222255 }
223256
0 commit comments