Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,332 +0,0 @@
1
-<?php
2
-
3
-namespace Illuminate\View;
4
-
5
-use InvalidArgumentException;
6
-use Illuminate\Filesystem\Filesystem;
7
-
8
-class FileViewFinder implements ViewFinderInterface
9
-{
10
-    /**
11
-     * The filesystem instance.
12
-     *
13
-     * @var \Illuminate\Filesystem\Filesystem
14
-     */
15
-    protected $files;
16
-
17
-    /**
18
-     * The array of active view paths.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $paths;
23
-
24
-    /**
25
-     * The array of views that have been located.
26
-     *
27
-     * @var array
28
-     */
29
-    protected $views = [];
30
-
31
-    /**
32
-     * The namespace to file path hints.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $hints = [];
37
-
38
-    /**
39
-     * Register a view extension with the finder.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $extensions = ['blade.php', 'php', 'css', 'html'];
44
-
45
-    /**
46
-     * Create a new file view loader instance.
47
-     *
48
-     * @param  \Illuminate\Filesystem\Filesystem  $files
49
-     * @param  array  $paths
50
-     * @param  array|null  $extensions
51
-     * @return void
52
-     */
53
-    public function __construct(Filesystem $files, array $paths, array $extensions = null)
54
-    {
55
-        $this->files = $files;
56
-        $this->paths = array_map([$this, 'resolvePath'], $paths);
57
-
58
-        if (isset($extensions)) {
59
-            $this->extensions = $extensions;
60
-        }
61
-    }
62
-
63
-    /**
64
-     * Get the fully qualified location of the view.
65
-     *
66
-     * @param  string  $name
67
-     * @return string
68
-     */
69
-    public function find($name)
70
-    {
71
-        if (isset($this->views[$name])) {
72
-            return $this->views[$name];
73
-        }
74
-
75
-        if ($this->hasHintInformation($name = trim($name))) {
76
-            return $this->views[$name] = $this->findNamespacedView($name);
77
-        }
78
-
79
-        return $this->views[$name] = $this->findInPaths($name, $this->paths);
80
-    }
81
-
82
-    /**
83
-     * Get the path to a template with a named path.
84
-     *
85
-     * @param  string  $name
86
-     * @return string
87
-     */
88
-    protected function findNamespacedView($name)
89
-    {
90
-        [$namespace, $view] = $this->parseNamespaceSegments($name);
91
-
92
-        return $this->findInPaths($view, $this->hints[$namespace]);
93
-    }
94
-
95
-    /**
96
-     * Get the segments of a template with a named path.
97
-     *
98
-     * @param  string  $name
99
-     * @return array
100
-     *
101
-     * @throws \InvalidArgumentException
102
-     */
103
-    protected function parseNamespaceSegments($name)
104
-    {
105
-        $segments = explode(static::HINT_PATH_DELIMITER, $name);
106
-
107
-        if (count($segments) !== 2) {
108
-            throw new InvalidArgumentException("View [{$name}] has an invalid name.");
109
-        }
110
-
111
-        if (! isset($this->hints[$segments[0]])) {
112
-            throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");
113
-        }
114
-
115
-        return $segments;
116
-    }
117
-
118
-    /**
119
-     * Find the given view in the list of paths.
120
-     *
121
-     * @param  string  $name
122
-     * @param  array   $paths
123
-     * @return string
124
-     *
125
-     * @throws \InvalidArgumentException
126
-     */
127
-    protected function findInPaths($name, $paths)
128
-    {
129
-        foreach ((array) $paths as $path) {
130
-            foreach ($this->getPossibleViewFiles($name) as $file) {
131
-                if ($this->files->exists($viewPath = $path.'/'.$file)) {
132
-                    return $viewPath;
133
-                }
134
-            }
135
-        }
136
-
137
-        throw new InvalidArgumentException("View [{$name}] not found.");
138
-    }
139
-
140
-    /**
141
-     * Get an array of possible view files.
142
-     *
143
-     * @param  string  $name
144
-     * @return array
145
-     */
146
-    protected function getPossibleViewFiles($name)
147
-    {
148
-        return array_map(function ($extension) use ($name) {
149
-            return str_replace('.', '/', $name).'.'.$extension;
150
-        }, $this->extensions);
151
-    }
152
-
153
-    /**
154
-     * Add a location to the finder.
155
-     *
156
-     * @param  string  $location
157
-     * @return void
158
-     */
159
-    public function addLocation($location)
160
-    {
161
-        $this->paths[] = $this->resolvePath($location);
162
-    }
163
-
164
-    /**
165
-     * Prepend a location to the finder.
166
-     *
167
-     * @param  string  $location
168
-     * @return void
169
-     */
170
-    public function prependLocation($location)
171
-    {
172
-        array_unshift($this->paths, $this->resolvePath($location));
173
-    }
174
-
175
-    /**
176
-     * Resolve the path.
177
-     *
178
-     * @param  string  $path
179
-     * @return string
180
-     */
181
-    protected function resolvePath($path)
182
-    {
183
-        return realpath($path) ?: $path;
184
-    }
185
-
186
-    /**
187
-     * Add a namespace hint to the finder.
188
-     *
189
-     * @param  string  $namespace
190
-     * @param  string|array  $hints
191
-     * @return void
192
-     */
193
-    public function addNamespace($namespace, $hints)
194
-    {
195
-        $hints = (array) $hints;
196
-
197
-        if (isset($this->hints[$namespace])) {
198
-            $hints = array_merge($this->hints[$namespace], $hints);
199
-        }
200
-
201
-        $this->hints[$namespace] = $hints;
202
-    }
203
-
204
-    /**
205
-     * Prepend a namespace hint to the finder.
206
-     *
207
-     * @param  string  $namespace
208
-     * @param  string|array  $hints
209
-     * @return void
210
-     */
211
-    public function prependNamespace($namespace, $hints)
212
-    {
213
-        $hints = (array) $hints;
214
-
215
-        if (isset($this->hints[$namespace])) {
216
-            $hints = array_merge($hints, $this->hints[$namespace]);
217
-        }
218
-
219
-        $this->hints[$namespace] = $hints;
220
-    }
221
-
222
-    /**
223
-     * Replace the namespace hints for the given namespace.
224
-     *
225
-     * @param  string  $namespace
226
-     * @param  string|array  $hints
227
-     * @return void
228
-     */
229
-    public function replaceNamespace($namespace, $hints)
230
-    {
231
-        $this->hints[$namespace] = (array) $hints;
232
-    }
233
-
234
-    /**
235
-     * Register an extension with the view finder.
236
-     *
237
-     * @param  string  $extension
238
-     * @return void
239
-     */
240
-    public function addExtension($extension)
241
-    {
242
-        if (($index = array_search($extension, $this->extensions)) !== false) {
243
-            unset($this->extensions[$index]);
244
-        }
245
-
246
-        array_unshift($this->extensions, $extension);
247
-    }
248
-
249
-    /**
250
-     * Returns whether or not the view name has any hint information.
251
-     *
252
-     * @param  string  $name
253
-     * @return bool
254
-     */
255
-    public function hasHintInformation($name)
256
-    {
257
-        return strpos($name, static::HINT_PATH_DELIMITER) > 0;
258
-    }
259
-
260
-    /**
261
-     * Flush the cache of located views.
262
-     *
263
-     * @return void
264
-     */
265
-    public function flush()
266
-    {
267
-        $this->views = [];
268
-    }
269
-
270
-    /**
271
-     * Get the filesystem instance.
272
-     *
273
-     * @return \Illuminate\Filesystem\Filesystem
274
-     */
275
-    public function getFilesystem()
276
-    {
277
-        return $this->files;
278
-    }
279
-
280
-    /**
281
-     * Set the active view paths.
282
-     *
283
-     * @param  array  $paths
284
-     * @return $this
285
-     */
286
-    public function setPaths($paths)
287
-    {
288
-        $this->paths = $paths;
289
-
290
-        return $this;
291
-    }
292
-
293
-    /**
294
-     * Get the active view paths.
295
-     *
296
-     * @return array
297
-     */
298
-    public function getPaths()
299
-    {
300
-        return $this->paths;
301
-    }
302
-
303
-    /**
304
-     * Get the views that have been located.
305
-     *
306
-     * @return array
307
-     */
308
-    public function getViews()
309
-    {
310
-        return $this->views;
311
-    }
312
-
313
-    /**
314
-     * Get the namespace to file path hints.
315
-     *
316
-     * @return array
317
-     */
318
-    public function getHints()
319
-    {
320
-        return $this->hints;
321
-    }
322
-
323
-    /**
324
-     * Get registered extensions.
325
-     *
326
-     * @return array
327
-     */
328
-    public function getExtensions()
329
-    {
330
-        return $this->extensions;
331
-    }
332
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,332 @@
1
+<?php
2
+
3
+namespace Illuminate\View;
4
+
5
+use InvalidArgumentException;
6
+use Illuminate\Filesystem\Filesystem;
7
+
8
+class FileViewFinder implements ViewFinderInterface
9
+{
10
+    /**
11
+     * The filesystem instance.
12
+     *
13
+     * @var \Illuminate\Filesystem\Filesystem
14
+     */
15
+    protected $files;
16
+
17
+    /**
18
+     * The array of active view paths.
19
+     *
20
+     * @var array
21
+     */
22
+    protected $paths;
23
+
24
+    /**
25
+     * The array of views that have been located.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $views = [];
30
+
31
+    /**
32
+     * The namespace to file path hints.
33
+     *
34
+     * @var array
35
+     */
36
+    protected $hints = [];
37
+
38
+    /**
39
+     * Register a view extension with the finder.
40
+     *
41
+     * @var array
42
+     */
43
+    protected $extensions = ['blade.php', 'php', 'css', 'html'];
44
+
45
+    /**
46
+     * Create a new file view loader instance.
47
+     *
48
+     * @param  \Illuminate\Filesystem\Filesystem  $files
49
+     * @param  array  $paths
50
+     * @param  array|null  $extensions
51
+     * @return void
52
+     */
53
+    public function __construct(Filesystem $files, array $paths, array $extensions = null)
54
+    {
55
+        $this->files = $files;
56
+        $this->paths = array_map([$this, 'resolvePath'], $paths);
57
+
58
+        if (isset($extensions)) {
59
+            $this->extensions = $extensions;
60
+        }
61
+    }
62
+
63
+    /**
64
+     * Get the fully qualified location of the view.
65
+     *
66
+     * @param  string  $name
67
+     * @return string
68
+     */
69
+    public function find($name)
70
+    {
71
+        if (isset($this->views[$name])) {
72
+            return $this->views[$name];
73
+        }
74
+
75
+        if ($this->hasHintInformation($name = trim($name))) {
76
+            return $this->views[$name] = $this->findNamespacedView($name);
77
+        }
78
+
79
+        return $this->views[$name] = $this->findInPaths($name, $this->paths);
80
+    }
81
+
82
+    /**
83
+     * Get the path to a template with a named path.
84
+     *
85
+     * @param  string  $name
86
+     * @return string
87
+     */
88
+    protected function findNamespacedView($name)
89
+    {
90
+        [$namespace, $view] = $this->parseNamespaceSegments($name);
91
+
92
+        return $this->findInPaths($view, $this->hints[$namespace]);
93
+    }
94
+
95
+    /**
96
+     * Get the segments of a template with a named path.
97
+     *
98
+     * @param  string  $name
99
+     * @return array
100
+     *
101
+     * @throws \InvalidArgumentException
102
+     */
103
+    protected function parseNamespaceSegments($name)
104
+    {
105
+        $segments = explode(static::HINT_PATH_DELIMITER, $name);
106
+
107
+        if (count($segments) !== 2) {
108
+            throw new InvalidArgumentException("View [{$name}] has an invalid name.");
109
+        }
110
+
111
+        if (! isset($this->hints[$segments[0]])) {
112
+            throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");
113
+        }
114
+
115
+        return $segments;
116
+    }
117
+
118
+    /**
119
+     * Find the given view in the list of paths.
120
+     *
121
+     * @param  string  $name
122
+     * @param  array   $paths
123
+     * @return string
124
+     *
125
+     * @throws \InvalidArgumentException
126
+     */
127
+    protected function findInPaths($name, $paths)
128
+    {
129
+        foreach ((array) $paths as $path) {
130
+            foreach ($this->getPossibleViewFiles($name) as $file) {
131
+                if ($this->files->exists($viewPath = $path.'/'.$file)) {
132
+                    return $viewPath;
133
+                }
134
+            }
135
+        }
136
+
137
+        throw new InvalidArgumentException("View [{$name}] not found.");
138
+    }
139
+
140
+    /**
141
+     * Get an array of possible view files.
142
+     *
143
+     * @param  string  $name
144
+     * @return array
145
+     */
146
+    protected function getPossibleViewFiles($name)
147
+    {
148
+        return array_map(function ($extension) use ($name) {
149
+            return str_replace('.', '/', $name).'.'.$extension;
150
+        }, $this->extensions);
151
+    }
152
+
153
+    /**
154
+     * Add a location to the finder.
155
+     *
156
+     * @param  string  $location
157
+     * @return void
158
+     */
159
+    public function addLocation($location)
160
+    {
161
+        $this->paths[] = $this->resolvePath($location);
162
+    }
163
+
164
+    /**
165
+     * Prepend a location to the finder.
166
+     *
167
+     * @param  string  $location
168
+     * @return void
169
+     */
170
+    public function prependLocation($location)
171
+    {
172
+        array_unshift($this->paths, $this->resolvePath($location));
173
+    }
174
+
175
+    /**
176
+     * Resolve the path.
177
+     *
178
+     * @param  string  $path
179
+     * @return string
180
+     */
181
+    protected function resolvePath($path)
182
+    {
183
+        return realpath($path) ?: $path;
184
+    }
185
+
186
+    /**
187
+     * Add a namespace hint to the finder.
188
+     *
189
+     * @param  string  $namespace
190
+     * @param  string|array  $hints
191
+     * @return void
192
+     */
193
+    public function addNamespace($namespace, $hints)
194
+    {
195
+        $hints = (array) $hints;
196
+
197
+        if (isset($this->hints[$namespace])) {
198
+            $hints = array_merge($this->hints[$namespace], $hints);
199
+        }
200
+
201
+        $this->hints[$namespace] = $hints;
202
+    }
203
+
204
+    /**
205
+     * Prepend a namespace hint to the finder.
206
+     *
207
+     * @param  string  $namespace
208
+     * @param  string|array  $hints
209
+     * @return void
210
+     */
211
+    public function prependNamespace($namespace, $hints)
212
+    {
213
+        $hints = (array) $hints;
214
+
215
+        if (isset($this->hints[$namespace])) {
216
+            $hints = array_merge($hints, $this->hints[$namespace]);
217
+        }
218
+
219
+        $this->hints[$namespace] = $hints;
220
+    }
221
+
222
+    /**
223
+     * Replace the namespace hints for the given namespace.
224
+     *
225
+     * @param  string  $namespace
226
+     * @param  string|array  $hints
227
+     * @return void
228
+     */
229
+    public function replaceNamespace($namespace, $hints)
230
+    {
231
+        $this->hints[$namespace] = (array) $hints;
232
+    }
233
+
234
+    /**
235
+     * Register an extension with the view finder.
236
+     *
237
+     * @param  string  $extension
238
+     * @return void
239
+     */
240
+    public function addExtension($extension)
241
+    {
242
+        if (($index = array_search($extension, $this->extensions)) !== false) {
243
+            unset($this->extensions[$index]);
244
+        }
245
+
246
+        array_unshift($this->extensions, $extension);
247
+    }
248
+
249
+    /**
250
+     * Returns whether or not the view name has any hint information.
251
+     *
252
+     * @param  string  $name
253
+     * @return bool
254
+     */
255
+    public function hasHintInformation($name)
256
+    {
257
+        return strpos($name, static::HINT_PATH_DELIMITER) > 0;
258
+    }
259
+
260
+    /**
261
+     * Flush the cache of located views.
262
+     *
263
+     * @return void
264
+     */
265
+    public function flush()
266
+    {
267
+        $this->views = [];
268
+    }
269
+
270
+    /**
271
+     * Get the filesystem instance.
272
+     *
273
+     * @return \Illuminate\Filesystem\Filesystem
274
+     */
275
+    public function getFilesystem()
276
+    {
277
+        return $this->files;
278
+    }
279
+
280
+    /**
281
+     * Set the active view paths.
282
+     *
283
+     * @param  array  $paths
284
+     * @return $this
285
+     */
286
+    public function setPaths($paths)
287
+    {
288
+        $this->paths = $paths;
289
+
290
+        return $this;
291
+    }
292
+
293
+    /**
294
+     * Get the active view paths.
295
+     *
296
+     * @return array
297
+     */
298
+    public function getPaths()
299
+    {
300
+        return $this->paths;
301
+    }
302
+
303
+    /**
304
+     * Get the views that have been located.
305
+     *
306
+     * @return array
307
+     */
308
+    public function getViews()
309
+    {
310
+        return $this->views;
311
+    }
312
+
313
+    /**
314
+     * Get the namespace to file path hints.
315
+     *
316
+     * @return array
317
+     */
318
+    public function getHints()
319
+    {
320
+        return $this->hints;
321
+    }
322
+
323
+    /**
324
+     * Get registered extensions.
325
+     *
326
+     * @return array
327
+     */
328
+    public function getExtensions()
329
+    {
330
+        return $this->extensions;
331
+    }
332
+}