File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ class FileViewFinder implements ViewFinderInterface
53
53
public function __construct (Filesystem $ files , array $ paths , array $ extensions = null )
54
54
{
55
55
$ this ->files = $ files ;
56
- $ this ->paths = $ paths ;
56
+ $ this ->paths = array_map ([ $ this , ' normalizePath ' ], $ paths) ;
57
57
58
58
if (isset ($ extensions )) {
59
59
$ this ->extensions = $ extensions ;
@@ -158,7 +158,7 @@ protected function getPossibleViewFiles($name)
158
158
*/
159
159
public function addLocation ($ location )
160
160
{
161
- $ this ->paths [] = $ location ;
161
+ $ this ->paths [] = $ this -> normalizePath ( $ location) ;
162
162
}
163
163
164
164
/**
@@ -169,7 +169,7 @@ public function addLocation($location)
169
169
*/
170
170
public function prependLocation ($ location )
171
171
{
172
- array_unshift ($ this ->paths , $ location );
172
+ array_unshift ($ this ->paths , $ this -> normalizePath ( $ location) );
173
173
}
174
174
175
175
/**
@@ -295,4 +295,15 @@ public function getExtensions()
295
295
{
296
296
return $ this ->extensions ;
297
297
}
298
+
299
+ /**
300
+ * Replace unnecessary relative fragments from the absolute view path.
301
+ *
302
+ * @param string $path
303
+ * @return string
304
+ */
305
+ protected function normalizePath ($ path )
306
+ {
307
+ return realpath ($ path ) ?: $ path ;
308
+ }
298
309
}
Original file line number Diff line number Diff line change @@ -145,6 +145,24 @@ public function testPassingViewWithFalseHintReturnsFalse()
145
145
$ this ->assertFalse ($ finder ->hasHintInformation ('::foo.bar ' ));
146
146
}
147
147
148
+ public function pathsProvider ()
149
+ {
150
+ return [
151
+ ['incorrect_path ' , 'incorrect_path ' ],
152
+ ];
153
+ }
154
+
155
+ /**
156
+ * @dataProvider pathsProvider
157
+ */
158
+ public function testNormalizedPaths ($ originalPath , $ exceptedPath )
159
+ {
160
+ $ finder = $ this ->getFinder ();
161
+ $ finder ->prependLocation ($ originalPath );
162
+ $ normalizedPath = $ finder ->getPaths ()[0 ];
163
+ $ this ->assertSame ($ exceptedPath , $ normalizedPath );
164
+ }
165
+
148
166
protected function getFinder ()
149
167
{
150
168
return new FileViewFinder (m::mock (Filesystem::class), [__DIR__ ]);
You can’t perform that action at this time.
0 commit comments