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,429 +0,0 @@
1
-<?php
2
-
3
-namespace Illuminate\View;
4
-
5
-use Exception;
6
-use Throwable;
7
-use ArrayAccess;
8
-use BadMethodCallException;
9
-use Illuminate\Support\Str;
10
-use Illuminate\Support\MessageBag;
11
-use Illuminate\Contracts\View\Engine;
12
-use Illuminate\Support\Traits\Macroable;
13
-use Illuminate\Contracts\Support\Arrayable;
14
-use Illuminate\Contracts\Support\Renderable;
15
-use Illuminate\Contracts\Support\MessageProvider;
16
-use Illuminate\Contracts\View\View as ViewContract;
17
-
18
-class View implements ArrayAccess, ViewContract
19
-{
20
-    use Macroable {
21
-        __call as macroCall;
22
-    }
23
-
24
-    /**
25
-     * The view factory instance.
26
-     *
27
-     * @var \Illuminate\View\Factory
28
-     */
29
-    protected $factory;
30
-
31
-    /**
32
-     * The engine implementation.
33
-     *
34
-     * @var \Illuminate\Contracts\View\Engine
35
-     */
36
-    protected $engine;
37
-
38
-    /**
39
-     * The name of the view.
40
-     *
41
-     * @var string
42
-     */
43
-    protected $view;
44
-
45
-    /**
46
-     * The array of view data.
47
-     *
48
-     * @var array
49
-     */
50
-    protected $data;
51
-
52
-    /**
53
-     * The path to the view file.
54
-     *
55
-     * @var string
56
-     */
57
-    protected $path;
58
-
59
-    /**
60
-     * Create a new view instance.
61
-     *
62
-     * @param  \Illuminate\View\Factory  $factory
63
-     * @param  \Illuminate\Contracts\View\Engine  $engine
64
-     * @param  string  $view
65
-     * @param  string  $path
66
-     * @param  mixed  $data
67
-     * @return void
68
-     */
69
-    public function __construct(Factory $factory, Engine $engine, $view, $path, $data = [])
70
-    {
71
-        $this->view = $view;
72
-        $this->path = $path;
73
-        $this->engine = $engine;
74
-        $this->factory = $factory;
75
-
76
-        $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data;
77
-    }
78
-
79
-    /**
80
-     * Get the string contents of the view.
81
-     *
82
-     * @param  callable|null  $callback
83
-     * @return array|string
84
-     *
85
-     * @throws \Throwable
86
-     */
87
-    public function render(callable $callback = null)
88
-    {
89
-        try {
90
-            $contents = $this->renderContents();
91
-
92
-            $response = isset($callback) ? call_user_func($callback, $this, $contents) : null;
93
-
94
-            // Once we have the contents of the view, we will flush the sections if we are
95
-            // done rendering all views so that there is nothing left hanging over when
96
-            // another view gets rendered in the future by the application developer.
97
-            $this->factory->flushStateIfDoneRendering();
98
-
99
-            return ! is_null($response) ? $response : $contents;
100
-        } catch (Exception $e) {
101
-            $this->factory->flushState();
102
-
103
-            throw $e;
104
-        } catch (Throwable $e) {
105
-            $this->factory->flushState();
106
-
107
-            throw $e;
108
-        }
109
-    }
110
-
111
-    /**
112
-     * Get the contents of the view instance.
113
-     *
114
-     * @return string
115
-     */
116
-    protected function renderContents()
117
-    {
118
-        // We will keep track of the amount of views being rendered so we can flush
119
-        // the section after the complete rendering operation is done. This will
120
-        // clear out the sections for any separate views that may be rendered.
121
-        $this->factory->incrementRender();
122
-
123
-        $this->factory->callComposer($this);
124
-
125
-        $contents = $this->getContents();
126
-
127
-        // Once we've finished rendering the view, we'll decrement the render count
128
-        // so that each sections get flushed out next time a view is created and
129
-        // no old sections are staying around in the memory of an environment.
130
-        $this->factory->decrementRender();
131
-
132
-        return $contents;
133
-    }
134
-
135
-    /**
136
-     * Get the evaluated contents of the view.
137
-     *
138
-     * @return string
139
-     */
140
-    protected function getContents()
141
-    {
142
-        return $this->engine->get($this->path, $this->gatherData());
143
-    }
144
-
145
-    /**
146
-     * Get the data bound to the view instance.
147
-     *
148
-     * @return array
149
-     */
150
-    public function gatherData()
151
-    {
152
-        $data = array_merge($this->factory->getShared(), $this->data);
153
-
154
-        foreach ($data as $key => $value) {
155
-            if ($value instanceof Renderable) {
156
-                $data[$key] = $value->render();
157
-            }
158
-        }
159
-
160
-        return $data;
161
-    }
162
-
163
-    /**
164
-     * Get the sections of the rendered view.
165
-     *
166
-     * @return array
167
-     *
168
-     * @throws \Throwable
169
-     */
170
-    public function renderSections()
171
-    {
172
-        return $this->render(function () {
173
-            return $this->factory->getSections();
174
-        });
175
-    }
176
-
177
-    /**
178
-     * Add a piece of data to the view.
179
-     *
180
-     * @param  string|array  $key
181
-     * @param  mixed   $value
182
-     * @return $this
183
-     */
184
-    public function with($key, $value = null)
185
-    {
186
-        if (is_array($key)) {
187
-            $this->data = array_merge($this->data, $key);
188
-        } else {
189
-            $this->data[$key] = $value;
190
-        }
191
-
192
-        return $this;
193
-    }
194
-
195
-    /**
196
-     * Add a view instance to the view data.
197
-     *
198
-     * @param  string  $key
199
-     * @param  string  $view
200
-     * @param  array   $data
201
-     * @return $this
202
-     */
203
-    public function nest($key, $view, array $data = [])
204
-    {
205
-        return $this->with($key, $this->factory->make($view, $data));
206
-    }
207
-
208
-    /**
209
-     * Add validation errors to the view.
210
-     *
211
-     * @param  \Illuminate\Contracts\Support\MessageProvider|array  $provider
212
-     * @return $this
213
-     */
214
-    public function withErrors($provider)
215
-    {
216
-        $this->with('errors', $this->formatErrors($provider));
217
-
218
-        return $this;
219
-    }
220
-
221
-    /**
222
-     * Format the given message provider into a MessageBag.
223
-     *
224
-     * @param  \Illuminate\Contracts\Support\MessageProvider|array  $provider
225
-     * @return \Illuminate\Support\MessageBag
226
-     */
227
-    protected function formatErrors($provider)
228
-    {
229
-        return $provider instanceof MessageProvider
230
-                        ? $provider->getMessageBag() : new MessageBag((array) $provider);
231
-    }
232
-
233
-    /**
234
-     * Get the name of the view.
235
-     *
236
-     * @return string
237
-     */
238
-    public function name()
239
-    {
240
-        return $this->getName();
241
-    }
242
-
243
-    /**
244
-     * Get the name of the view.
245
-     *
246
-     * @return string
247
-     */
248
-    public function getName()
249
-    {
250
-        return $this->view;
251
-    }
252
-
253
-    /**
254
-     * Get the array of view data.
255
-     *
256
-     * @return array
257
-     */
258
-    public function getData()
259
-    {
260
-        return $this->data;
261
-    }
262
-
263
-    /**
264
-     * Get the path to the view file.
265
-     *
266
-     * @return string
267
-     */
268
-    public function getPath()
269
-    {
270
-        return $this->path;
271
-    }
272
-
273
-    /**
274
-     * Set the path to the view.
275
-     *
276
-     * @param  string  $path
277
-     * @return void
278
-     */
279
-    public function setPath($path)
280
-    {
281
-        $this->path = $path;
282
-    }
283
-
284
-    /**
285
-     * Get the view factory instance.
286
-     *
287
-     * @return \Illuminate\View\Factory
288
-     */
289
-    public function getFactory()
290
-    {
291
-        return $this->factory;
292
-    }
293
-
294
-    /**
295
-     * Get the view's rendering engine.
296
-     *
297
-     * @return \Illuminate\Contracts\View\Engine
298
-     */
299
-    public function getEngine()
300
-    {
301
-        return $this->engine;
302
-    }
303
-
304
-    /**
305
-     * Determine if a piece of data is bound.
306
-     *
307
-     * @param  string  $key
308
-     * @return bool
309
-     */
310
-    public function offsetExists($key)
311
-    {
312
-        return array_key_exists($key, $this->data);
313
-    }
314
-
315
-    /**
316
-     * Get a piece of bound data to the view.
317
-     *
318
-     * @param  string  $key
319
-     * @return mixed
320
-     */
321
-    public function offsetGet($key)
322
-    {
323
-        return $this->data[$key];
324
-    }
325
-
326
-    /**
327
-     * Set a piece of data on the view.
328
-     *
329
-     * @param  string  $key
330
-     * @param  mixed   $value
331
-     * @return void
332
-     */
333
-    public function offsetSet($key, $value)
334
-    {
335
-        $this->with($key, $value);
336
-    }
337
-
338
-    /**
339
-     * Unset a piece of data from the view.
340
-     *
341
-     * @param  string  $key
342
-     * @return void
343
-     */
344
-    public function offsetUnset($key)
345
-    {
346
-        unset($this->data[$key]);
347
-    }
348
-
349
-    /**
350
-     * Get a piece of data from the view.
351
-     *
352
-     * @param  string  $key
353
-     * @return mixed
354
-     */
355
-    public function &__get($key)
356
-    {
357
-        return $this->data[$key];
358
-    }
359
-
360
-    /**
361
-     * Set a piece of data on the view.
362
-     *
363
-     * @param  string  $key
364
-     * @param  mixed   $value
365
-     * @return void
366
-     */
367
-    public function __set($key, $value)
368
-    {
369
-        $this->with($key, $value);
370
-    }
371
-
372
-    /**
373
-     * Check if a piece of data is bound to the view.
374
-     *
375
-     * @param  string  $key
376
-     * @return bool
377
-     */
378
-    public function __isset($key)
379
-    {
380
-        return isset($this->data[$key]);
381
-    }
382
-
383
-    /**
384
-     * Remove a piece of bound data from the view.
385
-     *
386
-     * @param  string  $key
387
-     * @return void
388
-     */
389
-    public function __unset($key)
390
-    {
391
-        unset($this->data[$key]);
392
-    }
393
-
394
-    /**
395
-     * Dynamically bind parameters to the view.
396
-     *
397
-     * @param  string  $method
398
-     * @param  array   $parameters
399
-     * @return \Illuminate\View\View
400
-     *
401
-     * @throws \BadMethodCallException
402
-     */
403
-    public function __call($method, $parameters)
404
-    {
405
-        if (static::hasMacro($method)) {
406
-            return $this->macroCall($method, $parameters);
407
-        }
408
-
409
-        if (! Str::startsWith($method, 'with')) {
410
-            throw new BadMethodCallException(sprintf(
411
-                'Method %s::%s does not exist.', static::class, $method
412
-            ));
413
-        }
414
-
415
-        return $this->with(Str::camel(substr($method, 4)), $parameters[0]);
416
-    }
417
-
418
-    /**
419
-     * Get the string contents of the view.
420
-     *
421
-     * @return string
422
-     *
423
-     * @throws \Throwable
424
-     */
425
-    public function __toString()
426
-    {
427
-        return $this->render();
428
-    }
429
-}
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,429 @@
1
+<?php
2
+
3
+namespace Illuminate\View;
4
+
5
+use Exception;
6
+use Throwable;
7
+use ArrayAccess;
8
+use BadMethodCallException;
9
+use Illuminate\Support\Str;
10
+use Illuminate\Support\MessageBag;
11
+use Illuminate\Contracts\View\Engine;
12
+use Illuminate\Support\Traits\Macroable;
13
+use Illuminate\Contracts\Support\Arrayable;
14
+use Illuminate\Contracts\Support\Renderable;
15
+use Illuminate\Contracts\Support\MessageProvider;
16
+use Illuminate\Contracts\View\View as ViewContract;
17
+
18
+class View implements ArrayAccess, ViewContract
19
+{
20
+    use Macroable {
21
+        __call as macroCall;
22
+    }
23
+
24
+    /**
25
+     * The view factory instance.
26
+     *
27
+     * @var \Illuminate\View\Factory
28
+     */
29
+    protected $factory;
30
+
31
+    /**
32
+     * The engine implementation.
33
+     *
34
+     * @var \Illuminate\Contracts\View\Engine
35
+     */
36
+    protected $engine;
37
+
38
+    /**
39
+     * The name of the view.
40
+     *
41
+     * @var string
42
+     */
43
+    protected $view;
44
+
45
+    /**
46
+     * The array of view data.
47
+     *
48
+     * @var array
49
+     */
50
+    protected $data;
51
+
52
+    /**
53
+     * The path to the view file.
54
+     *
55
+     * @var string
56
+     */
57
+    protected $path;
58
+
59
+    /**
60
+     * Create a new view instance.
61
+     *
62
+     * @param  \Illuminate\View\Factory  $factory
63
+     * @param  \Illuminate\Contracts\View\Engine  $engine
64
+     * @param  string  $view
65
+     * @param  string  $path
66
+     * @param  mixed  $data
67
+     * @return void
68
+     */
69
+    public function __construct(Factory $factory, Engine $engine, $view, $path, $data = [])
70
+    {
71
+        $this->view = $view;
72
+        $this->path = $path;
73
+        $this->engine = $engine;
74
+        $this->factory = $factory;
75
+
76
+        $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data;
77
+    }
78
+
79
+    /**
80
+     * Get the string contents of the view.
81
+     *
82
+     * @param  callable|null  $callback
83
+     * @return array|string
84
+     *
85
+     * @throws \Throwable
86
+     */
87
+    public function render(callable $callback = null)
88
+    {
89
+        try {
90
+            $contents = $this->renderContents();
91
+
92
+            $response = isset($callback) ? call_user_func($callback, $this, $contents) : null;
93
+
94
+            // Once we have the contents of the view, we will flush the sections if we are
95
+            // done rendering all views so that there is nothing left hanging over when
96
+            // another view gets rendered in the future by the application developer.
97
+            $this->factory->flushStateIfDoneRendering();
98
+
99
+            return ! is_null($response) ? $response : $contents;
100
+        } catch (Exception $e) {
101
+            $this->factory->flushState();
102
+
103
+            throw $e;
104
+        } catch (Throwable $e) {
105
+            $this->factory->flushState();
106
+
107
+            throw $e;
108
+        }
109
+    }
110
+
111
+    /**
112
+     * Get the contents of the view instance.
113
+     *
114
+     * @return string
115
+     */
116
+    protected function renderContents()
117
+    {
118
+        // We will keep track of the amount of views being rendered so we can flush
119
+        // the section after the complete rendering operation is done. This will
120
+        // clear out the sections for any separate views that may be rendered.
121
+        $this->factory->incrementRender();
122
+
123
+        $this->factory->callComposer($this);
124
+
125
+        $contents = $this->getContents();
126
+
127
+        // Once we've finished rendering the view, we'll decrement the render count
128
+        // so that each sections get flushed out next time a view is created and
129
+        // no old sections are staying around in the memory of an environment.
130
+        $this->factory->decrementRender();
131
+
132
+        return $contents;
133
+    }
134
+
135
+    /**
136
+     * Get the evaluated contents of the view.
137
+     *
138
+     * @return string
139
+     */
140
+    protected function getContents()
141
+    {
142
+        return $this->engine->get($this->path, $this->gatherData());
143
+    }
144
+
145
+    /**
146
+     * Get the data bound to the view instance.
147
+     *
148
+     * @return array
149
+     */
150
+    public function gatherData()
151
+    {
152
+        $data = array_merge($this->factory->getShared(), $this->data);
153
+
154
+        foreach ($data as $key => $value) {
155
+            if ($value instanceof Renderable) {
156
+                $data[$key] = $value->render();
157
+            }
158
+        }
159
+
160
+        return $data;
161
+    }
162
+
163
+    /**
164
+     * Get the sections of the rendered view.
165
+     *
166
+     * @return array
167
+     *
168
+     * @throws \Throwable
169
+     */
170
+    public function renderSections()
171
+    {
172
+        return $this->render(function () {
173
+            return $this->factory->getSections();
174
+        });
175
+    }
176
+
177
+    /**
178
+     * Add a piece of data to the view.
179
+     *
180
+     * @param  string|array  $key
181
+     * @param  mixed   $value
182
+     * @return $this
183
+     */
184
+    public function with($key, $value = null)
185
+    {
186
+        if (is_array($key)) {
187
+            $this->data = array_merge($this->data, $key);
188
+        } else {
189
+            $this->data[$key] = $value;
190
+        }
191
+
192
+        return $this;
193
+    }
194
+
195
+    /**
196
+     * Add a view instance to the view data.
197
+     *
198
+     * @param  string  $key
199
+     * @param  string  $view
200
+     * @param  array   $data
201
+     * @return $this
202
+     */
203
+    public function nest($key, $view, array $data = [])
204
+    {
205
+        return $this->with($key, $this->factory->make($view, $data));
206
+    }
207
+
208
+    /**
209
+     * Add validation errors to the view.
210
+     *
211
+     * @param  \Illuminate\Contracts\Support\MessageProvider|array  $provider
212
+     * @return $this
213
+     */
214
+    public function withErrors($provider)
215
+    {
216
+        $this->with('errors', $this->formatErrors($provider));
217
+
218
+        return $this;
219
+    }
220
+
221
+    /**
222
+     * Format the given message provider into a MessageBag.
223
+     *
224
+     * @param  \Illuminate\Contracts\Support\MessageProvider|array  $provider
225
+     * @return \Illuminate\Support\MessageBag
226
+     */
227
+    protected function formatErrors($provider)
228
+    {
229
+        return $provider instanceof MessageProvider
230
+                        ? $provider->getMessageBag() : new MessageBag((array) $provider);
231
+    }
232
+
233
+    /**
234
+     * Get the name of the view.
235
+     *
236
+     * @return string
237
+     */
238
+    public function name()
239
+    {
240
+        return $this->getName();
241
+    }
242
+
243
+    /**
244
+     * Get the name of the view.
245
+     *
246
+     * @return string
247
+     */
248
+    public function getName()
249
+    {
250
+        return $this->view;
251
+    }
252
+
253
+    /**
254
+     * Get the array of view data.
255
+     *
256
+     * @return array
257
+     */
258
+    public function getData()
259
+    {
260
+        return $this->data;
261
+    }
262
+
263
+    /**
264
+     * Get the path to the view file.
265
+     *
266
+     * @return string
267
+     */
268
+    public function getPath()
269
+    {
270
+        return $this->path;
271
+    }
272
+
273
+    /**
274
+     * Set the path to the view.
275
+     *
276
+     * @param  string  $path
277
+     * @return void
278
+     */
279
+    public function setPath($path)
280
+    {
281
+        $this->path = $path;
282
+    }
283
+
284
+    /**
285
+     * Get the view factory instance.
286
+     *
287
+     * @return \Illuminate\View\Factory
288
+     */
289
+    public function getFactory()
290
+    {
291
+        return $this->factory;
292
+    }
293
+
294
+    /**
295
+     * Get the view's rendering engine.
296
+     *
297
+     * @return \Illuminate\Contracts\View\Engine
298
+     */
299
+    public function getEngine()
300
+    {
301
+        return $this->engine;
302
+    }
303
+
304
+    /**
305
+     * Determine if a piece of data is bound.
306
+     *
307
+     * @param  string  $key
308
+     * @return bool
309
+     */
310
+    public function offsetExists($key)
311
+    {
312
+        return array_key_exists($key, $this->data);
313
+    }
314
+
315
+    /**
316
+     * Get a piece of bound data to the view.
317
+     *
318
+     * @param  string  $key
319
+     * @return mixed
320
+     */
321
+    public function offsetGet($key)
322
+    {
323
+        return $this->data[$key];
324
+    }
325
+
326
+    /**
327
+     * Set a piece of data on the view.
328
+     *
329
+     * @param  string  $key
330
+     * @param  mixed   $value
331
+     * @return void
332
+     */
333
+    public function offsetSet($key, $value)
334
+    {
335
+        $this->with($key, $value);
336
+    }
337
+
338
+    /**
339
+     * Unset a piece of data from the view.
340
+     *
341
+     * @param  string  $key
342
+     * @return void
343
+     */
344
+    public function offsetUnset($key)
345
+    {
346
+        unset($this->data[$key]);
347
+    }
348
+
349
+    /**
350
+     * Get a piece of data from the view.
351
+     *
352
+     * @param  string  $key
353
+     * @return mixed
354
+     */
355
+    public function &__get($key)
356
+    {
357
+        return $this->data[$key];
358
+    }
359
+
360
+    /**
361
+     * Set a piece of data on the view.
362
+     *
363
+     * @param  string  $key
364
+     * @param  mixed   $value
365
+     * @return void
366
+     */
367
+    public function __set($key, $value)
368
+    {
369
+        $this->with($key, $value);
370
+    }
371
+
372
+    /**
373
+     * Check if a piece of data is bound to the view.
374
+     *
375
+     * @param  string  $key
376
+     * @return bool
377
+     */
378
+    public function __isset($key)
379
+    {
380
+        return isset($this->data[$key]);
381
+    }
382
+
383
+    /**
384
+     * Remove a piece of bound data from the view.
385
+     *
386
+     * @param  string  $key
387
+     * @return void
388
+     */
389
+    public function __unset($key)
390
+    {
391
+        unset($this->data[$key]);
392
+    }
393
+
394
+    /**
395
+     * Dynamically bind parameters to the view.
396
+     *
397
+     * @param  string  $method
398
+     * @param  array   $parameters
399
+     * @return \Illuminate\View\View
400
+     *
401
+     * @throws \BadMethodCallException
402
+     */
403
+    public function __call($method, $parameters)
404
+    {
405
+        if (static::hasMacro($method)) {
406
+            return $this->macroCall($method, $parameters);
407
+        }
408
+
409
+        if (! Str::startsWith($method, 'with')) {
410
+            throw new BadMethodCallException(sprintf(
411
+                'Method %s::%s does not exist.', static::class, $method
412
+            ));
413
+        }
414
+
415
+        return $this->with(Str::camel(substr($method, 4)), $parameters[0]);
416
+    }
417
+
418
+    /**
419
+     * Get the string contents of the view.
420
+     *
421
+     * @return string
422
+     *
423
+     * @throws \Throwable
424
+     */
425
+    public function __toString()
426
+    {
427
+        return $this->render();
428
+    }
429
+}