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,220 +0,0 @@
1
-<?php
2
-
3
-namespace Illuminate\View\Concerns;
4
-
5
-use InvalidArgumentException;
6
-use Illuminate\Contracts\View\View;
7
-
8
-trait ManagesLayouts
9
-{
10
-    /**
11
-     * All of the finished, captured sections.
12
-     *
13
-     * @var array
14
-     */
15
-    protected $sections = [];
16
-
17
-    /**
18
-     * The stack of in-progress sections.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $sectionStack = [];
23
-
24
-    /**
25
-     * The parent placeholder for the request.
26
-     *
27
-     * @var mixed
28
-     */
29
-    protected static $parentPlaceholder = [];
30
-
31
-    /**
32
-     * Start injecting content into a section.
33
-     *
34
-     * @param  string  $section
35
-     * @param  string|null  $content
36
-     * @return void
37
-     */
38
-    public function startSection($section, $content = null)
39
-    {
40
-        if ($content === null) {
41
-            if (ob_start()) {
42
-                $this->sectionStack[] = $section;
43
-            }
44
-        } else {
45
-            $this->extendSection($section, $content instanceof View ? $content : e($content));
46
-        }
47
-    }
48
-
49
-    /**
50
-     * Inject inline content into a section.
51
-     *
52
-     * @param  string  $section
53
-     * @param  string  $content
54
-     * @return void
55
-     */
56
-    public function inject($section, $content)
57
-    {
58
-        $this->startSection($section, $content);
59
-    }
60
-
61
-    /**
62
-     * Stop injecting content into a section and return its contents.
63
-     *
64
-     * @return string
65
-     */
66
-    public function yieldSection()
67
-    {
68
-        if (empty($this->sectionStack)) {
69
-            return '';
70
-        }
71
-
72
-        return $this->yieldContent($this->stopSection());
73
-    }
74
-
75
-    /**
76
-     * Stop injecting content into a section.
77
-     *
78
-     * @param  bool  $overwrite
79
-     * @return string
80
-     *
81
-     * @throws \InvalidArgumentException
82
-     */
83
-    public function stopSection($overwrite = false)
84
-    {
85
-        if (empty($this->sectionStack)) {
86
-            throw new InvalidArgumentException('Cannot end a section without first starting one.');
87
-        }
88
-
89
-        $last = array_pop($this->sectionStack);
90
-
91
-        if ($overwrite) {
92
-            $this->sections[$last] = ob_get_clean();
93
-        } else {
94
-            $this->extendSection($last, ob_get_clean());
95
-        }
96
-
97
-        return $last;
98
-    }
99
-
100
-    /**
101
-     * Stop injecting content into a section and append it.
102
-     *
103
-     * @return string
104
-     *
105
-     * @throws \InvalidArgumentException
106
-     */
107
-    public function appendSection()
108
-    {
109
-        if (empty($this->sectionStack)) {
110
-            throw new InvalidArgumentException('Cannot end a section without first starting one.');
111
-        }
112
-
113
-        $last = array_pop($this->sectionStack);
114
-
115
-        if (isset($this->sections[$last])) {
116
-            $this->sections[$last] .= ob_get_clean();
117
-        } else {
118
-            $this->sections[$last] = ob_get_clean();
119
-        }
120
-
121
-        return $last;
122
-    }
123
-
124
-    /**
125
-     * Append content to a given section.
126
-     *
127
-     * @param  string  $section
128
-     * @param  string  $content
129
-     * @return void
130
-     */
131
-    protected function extendSection($section, $content)
132
-    {
133
-        if (isset($this->sections[$section])) {
134
-            $content = str_replace(static::parentPlaceholder($section), $content, $this->sections[$section]);
135
-        }
136
-
137
-        $this->sections[$section] = $content;
138
-    }
139
-
140
-    /**
141
-     * Get the string contents of a section.
142
-     *
143
-     * @param  string  $section
144
-     * @param  string  $default
145
-     * @return string
146
-     */
147
-    public function yieldContent($section, $default = '')
148
-    {
149
-        $sectionContent = $default instanceof View ? $default : e($default);
150
-
151
-        if (isset($this->sections[$section])) {
152
-            $sectionContent = $this->sections[$section];
153
-        }
154
-
155
-        $sectionContent = str_replace('@parent', '@parent', $sectionContent);
156
-
157
-        return str_replace(
158
-            '@parent', '@parent', str_replace(static::parentPlaceholder($section), '', $sectionContent)
159
-        );
160
-    }
161
-
162
-    /**
163
-     * Get the parent placeholder for the current request.
164
-     *
165
-     * @param  string  $section
166
-     * @return string
167
-     */
168
-    public static function parentPlaceholder($section = '')
169
-    {
170
-        if (! isset(static::$parentPlaceholder[$section])) {
171
-            static::$parentPlaceholder[$section] = '##parent-placeholder-'.sha1($section).'##';
172
-        }
173
-
174
-        return static::$parentPlaceholder[$section];
175
-    }
176
-
177
-    /**
178
-     * Check if section exists.
179
-     *
180
-     * @param  string  $name
181
-     * @return bool
182
-     */
183
-    public function hasSection($name)
184
-    {
185
-        return array_key_exists($name, $this->sections);
186
-    }
187
-
188
-    /**
189
-     * Get the contents of a section.
190
-     *
191
-     * @param  string  $name
192
-     * @param  string|null  $default
193
-     * @return mixed
194
-     */
195
-    public function getSection($name, $default = null)
196
-    {
197
-        return $this->getSections()[$name] ?? $default;
198
-    }
199
-
200
-    /**
201
-     * Get the entire array of sections.
202
-     *
203
-     * @return array
204
-     */
205
-    public function getSections()
206
-    {
207
-        return $this->sections;
208
-    }
209
-
210
-    /**
211
-     * Flush all of the sections.
212
-     *
213
-     * @return void
214
-     */
215
-    public function flushSections()
216
-    {
217
-        $this->sections = [];
218
-        $this->sectionStack = [];
219
-    }
220
-}
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,220 @@
1
+<?php
2
+
3
+namespace Illuminate\View\Concerns;
4
+
5
+use InvalidArgumentException;
6
+use Illuminate\Contracts\View\View;
7
+
8
+trait ManagesLayouts
9
+{
10
+    /**
11
+     * All of the finished, captured sections.
12
+     *
13
+     * @var array
14
+     */
15
+    protected $sections = [];
16
+
17
+    /**
18
+     * The stack of in-progress sections.
19
+     *
20
+     * @var array
21
+     */
22
+    protected $sectionStack = [];
23
+
24
+    /**
25
+     * The parent placeholder for the request.
26
+     *
27
+     * @var mixed
28
+     */
29
+    protected static $parentPlaceholder = [];
30
+
31
+    /**
32
+     * Start injecting content into a section.
33
+     *
34
+     * @param  string  $section
35
+     * @param  string|null  $content
36
+     * @return void
37
+     */
38
+    public function startSection($section, $content = null)
39
+    {
40
+        if ($content === null) {
41
+            if (ob_start()) {
42
+                $this->sectionStack[] = $section;
43
+            }
44
+        } else {
45
+            $this->extendSection($section, $content instanceof View ? $content : e($content));
46
+        }
47
+    }
48
+
49
+    /**
50
+     * Inject inline content into a section.
51
+     *
52
+     * @param  string  $section
53
+     * @param  string  $content
54
+     * @return void
55
+     */
56
+    public function inject($section, $content)
57
+    {
58
+        $this->startSection($section, $content);
59
+    }
60
+
61
+    /**
62
+     * Stop injecting content into a section and return its contents.
63
+     *
64
+     * @return string
65
+     */
66
+    public function yieldSection()
67
+    {
68
+        if (empty($this->sectionStack)) {
69
+            return '';
70
+        }
71
+
72
+        return $this->yieldContent($this->stopSection());
73
+    }
74
+
75
+    /**
76
+     * Stop injecting content into a section.
77
+     *
78
+     * @param  bool  $overwrite
79
+     * @return string
80
+     *
81
+     * @throws \InvalidArgumentException
82
+     */
83
+    public function stopSection($overwrite = false)
84
+    {
85
+        if (empty($this->sectionStack)) {
86
+            throw new InvalidArgumentException('Cannot end a section without first starting one.');
87
+        }
88
+
89
+        $last = array_pop($this->sectionStack);
90
+
91
+        if ($overwrite) {
92
+            $this->sections[$last] = ob_get_clean();
93
+        } else {
94
+            $this->extendSection($last, ob_get_clean());
95
+        }
96
+
97
+        return $last;
98
+    }
99
+
100
+    /**
101
+     * Stop injecting content into a section and append it.
102
+     *
103
+     * @return string
104
+     *
105
+     * @throws \InvalidArgumentException
106
+     */
107
+    public function appendSection()
108
+    {
109
+        if (empty($this->sectionStack)) {
110
+            throw new InvalidArgumentException('Cannot end a section without first starting one.');
111
+        }
112
+
113
+        $last = array_pop($this->sectionStack);
114
+
115
+        if (isset($this->sections[$last])) {
116
+            $this->sections[$last] .= ob_get_clean();
117
+        } else {
118
+            $this->sections[$last] = ob_get_clean();
119
+        }
120
+
121
+        return $last;
122
+    }
123
+
124
+    /**
125
+     * Append content to a given section.
126
+     *
127
+     * @param  string  $section
128
+     * @param  string  $content
129
+     * @return void
130
+     */
131
+    protected function extendSection($section, $content)
132
+    {
133
+        if (isset($this->sections[$section])) {
134
+            $content = str_replace(static::parentPlaceholder($section), $content, $this->sections[$section]);
135
+        }
136
+
137
+        $this->sections[$section] = $content;
138
+    }
139
+
140
+    /**
141
+     * Get the string contents of a section.
142
+     *
143
+     * @param  string  $section
144
+     * @param  string  $default
145
+     * @return string
146
+     */
147
+    public function yieldContent($section, $default = '')
148
+    {
149
+        $sectionContent = $default instanceof View ? $default : e($default);
150
+
151
+        if (isset($this->sections[$section])) {
152
+            $sectionContent = $this->sections[$section];
153
+        }
154
+
155
+        $sectionContent = str_replace('@parent', '@parent', $sectionContent);
156
+
157
+        return str_replace(
158
+            '@parent', '@parent', str_replace(static::parentPlaceholder($section), '', $sectionContent)
159
+        );
160
+    }
161
+
162
+    /**
163
+     * Get the parent placeholder for the current request.
164
+     *
165
+     * @param  string  $section
166
+     * @return string
167
+     */
168
+    public static function parentPlaceholder($section = '')
169
+    {
170
+        if (! isset(static::$parentPlaceholder[$section])) {
171
+            static::$parentPlaceholder[$section] = '##parent-placeholder-'.sha1($section).'##';
172
+        }
173
+
174
+        return static::$parentPlaceholder[$section];
175
+    }
176
+
177
+    /**
178
+     * Check if section exists.
179
+     *
180
+     * @param  string  $name
181
+     * @return bool
182
+     */
183
+    public function hasSection($name)
184
+    {
185
+        return array_key_exists($name, $this->sections);
186
+    }
187
+
188
+    /**
189
+     * Get the contents of a section.
190
+     *
191
+     * @param  string  $name
192
+     * @param  string|null  $default
193
+     * @return mixed
194
+     */
195
+    public function getSection($name, $default = null)
196
+    {
197
+        return $this->getSections()[$name] ?? $default;
198
+    }
199
+
200
+    /**
201
+     * Get the entire array of sections.
202
+     *
203
+     * @return array
204
+     */
205
+    public function getSections()
206
+    {
207
+        return $this->sections;
208
+    }
209
+
210
+    /**
211
+     * Flush all of the sections.
212
+     *
213
+     * @return void
214
+     */
215
+    public function flushSections()
216
+    {
217
+        $this->sections = [];
218
+        $this->sectionStack = [];
219
+    }
220
+}