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,145 +0,0 @@
1
-<?php
2
-
3
-namespace Illuminate\View\Concerns;
4
-
5
-use Illuminate\Support\Arr;
6
-use Illuminate\Support\HtmlString;
7
-
8
-trait ManagesComponents
9
-{
10
-    /**
11
-     * The components being rendered.
12
-     *
13
-     * @var array
14
-     */
15
-    protected $componentStack = [];
16
-
17
-    /**
18
-     * The original data passed to the component.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $componentData = [];
23
-
24
-    /**
25
-     * The slot contents for the component.
26
-     *
27
-     * @var array
28
-     */
29
-    protected $slots = [];
30
-
31
-    /**
32
-     * The names of the slots being rendered.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $slotStack = [];
37
-
38
-    /**
39
-     * Start a component rendering process.
40
-     *
41
-     * @param  string  $name
42
-     * @param  array  $data
43
-     * @return void
44
-     */
45
-    public function startComponent($name, array $data = [])
46
-    {
47
-        if (ob_start()) {
48
-            $this->componentStack[] = $name;
49
-
50
-            $this->componentData[$this->currentComponent()] = $data;
51
-
52
-            $this->slots[$this->currentComponent()] = [];
53
-        }
54
-    }
55
-
56
-    /**
57
-     * Get the first view that actually exists from the given list, and start a component.
58
-     *
59
-     * @param  array  $names
60
-     * @param  array  $data
61
-     * @return void
62
-     */
63
-    public function startComponentFirst(array $names, array $data = [])
64
-    {
65
-        $name = Arr::first($names, function ($item) {
66
-            return $this->exists($item);
67
-        });
68
-
69
-        $this->startComponent($name, $data);
70
-    }
71
-
72
-    /**
73
-     * Render the current component.
74
-     *
75
-     * @return string
76
-     */
77
-    public function renderComponent()
78
-    {
79
-        $name = array_pop($this->componentStack);
80
-
81
-        return $this->make($name, $this->componentData($name))->render();
82
-    }
83
-
84
-    /**
85
-     * Get the data for the given component.
86
-     *
87
-     * @param  string  $name
88
-     * @return array
89
-     */
90
-    protected function componentData($name)
91
-    {
92
-        return array_merge(
93
-            $this->componentData[count($this->componentStack)],
94
-            ['slot' => new HtmlString(trim(ob_get_clean()))],
95
-            $this->slots[count($this->componentStack)]
96
-        );
97
-    }
98
-
99
-    /**
100
-     * Start the slot rendering process.
101
-     *
102
-     * @param  string  $name
103
-     * @param  string|null  $content
104
-     * @return void
105
-     */
106
-    public function slot($name, $content = null)
107
-    {
108
-        if (func_num_args() === 2) {
109
-            $this->slots[$this->currentComponent()][$name] = $content;
110
-        } else {
111
-            if (ob_start()) {
112
-                $this->slots[$this->currentComponent()][$name] = '';
113
-
114
-                $this->slotStack[$this->currentComponent()][] = $name;
115
-            }
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Save the slot content for rendering.
121
-     *
122
-     * @return void
123
-     */
124
-    public function endSlot()
125
-    {
126
-        last($this->componentStack);
127
-
128
-        $currentSlot = array_pop(
129
-            $this->slotStack[$this->currentComponent()]
130
-        );
131
-
132
-        $this->slots[$this->currentComponent()]
133
-                    [$currentSlot] = new HtmlString(trim(ob_get_clean()));
134
-    }
135
-
136
-    /**
137
-     * Get the index for the current component.
138
-     *
139
-     * @return int
140
-     */
141
-    protected function currentComponent()
142
-    {
143
-        return count($this->componentStack) - 1;
144
-    }
145
-}
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,145 @@
1
+<?php
2
+
3
+namespace Illuminate\View\Concerns;
4
+
5
+use Illuminate\Support\Arr;
6
+use Illuminate\Support\HtmlString;
7
+
8
+trait ManagesComponents
9
+{
10
+    /**
11
+     * The components being rendered.
12
+     *
13
+     * @var array
14
+     */
15
+    protected $componentStack = [];
16
+
17
+    /**
18
+     * The original data passed to the component.
19
+     *
20
+     * @var array
21
+     */
22
+    protected $componentData = [];
23
+
24
+    /**
25
+     * The slot contents for the component.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $slots = [];
30
+
31
+    /**
32
+     * The names of the slots being rendered.
33
+     *
34
+     * @var array
35
+     */
36
+    protected $slotStack = [];
37
+
38
+    /**
39
+     * Start a component rendering process.
40
+     *
41
+     * @param  string  $name
42
+     * @param  array  $data
43
+     * @return void
44
+     */
45
+    public function startComponent($name, array $data = [])
46
+    {
47
+        if (ob_start()) {
48
+            $this->componentStack[] = $name;
49
+
50
+            $this->componentData[$this->currentComponent()] = $data;
51
+
52
+            $this->slots[$this->currentComponent()] = [];
53
+        }
54
+    }
55
+
56
+    /**
57
+     * Get the first view that actually exists from the given list, and start a component.
58
+     *
59
+     * @param  array  $names
60
+     * @param  array  $data
61
+     * @return void
62
+     */
63
+    public function startComponentFirst(array $names, array $data = [])
64
+    {
65
+        $name = Arr::first($names, function ($item) {
66
+            return $this->exists($item);
67
+        });
68
+
69
+        $this->startComponent($name, $data);
70
+    }
71
+
72
+    /**
73
+     * Render the current component.
74
+     *
75
+     * @return string
76
+     */
77
+    public function renderComponent()
78
+    {
79
+        $name = array_pop($this->componentStack);
80
+
81
+        return $this->make($name, $this->componentData($name))->render();
82
+    }
83
+
84
+    /**
85
+     * Get the data for the given component.
86
+     *
87
+     * @param  string  $name
88
+     * @return array
89
+     */
90
+    protected function componentData($name)
91
+    {
92
+        return array_merge(
93
+            $this->componentData[count($this->componentStack)],
94
+            ['slot' => new HtmlString(trim(ob_get_clean()))],
95
+            $this->slots[count($this->componentStack)]
96
+        );
97
+    }
98
+
99
+    /**
100
+     * Start the slot rendering process.
101
+     *
102
+     * @param  string  $name
103
+     * @param  string|null  $content
104
+     * @return void
105
+     */
106
+    public function slot($name, $content = null)
107
+    {
108
+        if (func_num_args() === 2) {
109
+            $this->slots[$this->currentComponent()][$name] = $content;
110
+        } else {
111
+            if (ob_start()) {
112
+                $this->slots[$this->currentComponent()][$name] = '';
113
+
114
+                $this->slotStack[$this->currentComponent()][] = $name;
115
+            }
116
+        }
117
+    }
118
+
119
+    /**
120
+     * Save the slot content for rendering.
121
+     *
122
+     * @return void
123
+     */
124
+    public function endSlot()
125
+    {
126
+        last($this->componentStack);
127
+
128
+        $currentSlot = array_pop(
129
+            $this->slotStack[$this->currentComponent()]
130
+        );
131
+
132
+        $this->slots[$this->currentComponent()]
133
+                    [$currentSlot] = new HtmlString(trim(ob_get_clean()));
134
+    }
135
+
136
+    /**
137
+     * Get the index for the current component.
138
+     *
139
+     * @return int
140
+     */
141
+    protected function currentComponent()
142
+    {
143
+        return count($this->componentStack) - 1;
144
+    }
145
+}