Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\View\Compilers\Concerns;
4
 
5
use Illuminate\Support\Str;
6
 
7
trait CompilesConditionals
8
{
9
    /**
10
     * Identifier for the first case in the switch statement.
11
     *
12
     * @var bool
13
     */
14
    protected $firstCaseInSwitch = true;
15
 
16
    /**
17
     * Compile the if-auth statements into valid PHP.
18
     *
19
     * @param  string|null  $guard
20
     * @return string
21
     */
22
    protected function compileAuth($guard = null)
23
    {
24
        $guard = is_null($guard) ? '()' : $guard;
25
 
26
        return "<?php if(auth()->guard{$guard}->check()): ?>";
27
    }
28
 
29
    /**
30
     * Compile the else-auth statements into valid PHP.
31
     *
32
     * @param  string|null  $guard
33
     * @return string
34
     */
35
    protected function compileElseAuth($guard = null)
36
    {
37
        $guard = is_null($guard) ? '()' : $guard;
38
 
39
        return "<?php elseif(auth()->guard{$guard}->check()): ?>";
40
    }
41
 
42
    /**
43
     * Compile the end-auth statements into valid PHP.
44
     *
45
     * @return string
46
     */
47
    protected function compileEndAuth()
48
    {
49
        return '<?php endif; ?>';
50
    }
51
 
52
    /**
53
     * Compile the env statements into valid PHP.
54
     *
55
     * @param  string  $environments
56
     * @return string
57
     */
58
    protected function compileEnv($environments)
59
    {
60
        return "<?php if(app()->environment{$environments}): ?>";
61
    }
62
 
63
    /**
64
     * Compile the end-env statements into valid PHP.
65
     *
66
     * @return string
67
     */
68
    protected function compileEndEnv()
69
    {
70
        return '<?php endif; ?>';
71
    }
72
 
73
    /**
74
     * Compile the production statements into valid PHP.
75
     *
76
     * @return string
77
     */
78
    protected function compileProduction()
79
    {
80
        return "<?php if(app()->environment('production')): ?>";
81
    }
82
 
83
    /**
84
     * Compile the end-production statements into valid PHP.
85
     *
86
     * @return string
87
     */
88
    protected function compileEndProduction()
89
    {
90
        return '<?php endif; ?>';
91
    }
92
 
93
    /**
94
     * Compile the if-guest statements into valid PHP.
95
     *
96
     * @param  string|null  $guard
97
     * @return string
98
     */
99
    protected function compileGuest($guard = null)
100
    {
101
        $guard = is_null($guard) ? '()' : $guard;
102
 
103
        return "<?php if(auth()->guard{$guard}->guest()): ?>";
104
    }
105
 
106
    /**
107
     * Compile the else-guest statements into valid PHP.
108
     *
109
     * @param  string|null  $guard
110
     * @return string
111
     */
112
    protected function compileElseGuest($guard = null)
113
    {
114
        $guard = is_null($guard) ? '()' : $guard;
115
 
116
        return "<?php elseif(auth()->guard{$guard}->guest()): ?>";
117
    }
118
 
119
    /**
120
     * Compile the end-guest statements into valid PHP.
121
     *
122
     * @return string
123
     */
124
    protected function compileEndGuest()
125
    {
126
        return '<?php endif; ?>';
127
    }
128
 
129
    /**
130
     * Compile the has-section statements into valid PHP.
131
     *
132
     * @param  string  $expression
133
     * @return string
134
     */
135
    protected function compileHasSection($expression)
136
    {
137
        return "<?php if (! empty(trim(\$__env->yieldContent{$expression}))): ?>";
138
    }
139
 
140
    /**
141
     * Compile the section-missing statements into valid PHP.
142
     *
143
     * @param  string  $expression
144
     * @return string
145
     */
146
    protected function compileSectionMissing($expression)
147
    {
148
        return "<?php if (empty(trim(\$__env->yieldContent{$expression}))): ?>";
149
    }
150
 
151
    /**
152
     * Compile the if statements into valid PHP.
153
     *
154
     * @param  string  $expression
155
     * @return string
156
     */
157
    protected function compileIf($expression)
158
    {
159
        return "<?php if{$expression}: ?>";
160
    }
161
 
162
    /**
163
     * Compile the unless statements into valid PHP.
164
     *
165
     * @param  string  $expression
166
     * @return string
167
     */
168
    protected function compileUnless($expression)
169
    {
170
        return "<?php if (! {$expression}): ?>";
171
    }
172
 
173
    /**
174
     * Compile the else-if statements into valid PHP.
175
     *
176
     * @param  string  $expression
177
     * @return string
178
     */
179
    protected function compileElseif($expression)
180
    {
181
        return "<?php elseif{$expression}: ?>";
182
    }
183
 
184
    /**
185
     * Compile the else statements into valid PHP.
186
     *
187
     * @return string
188
     */
189
    protected function compileElse()
190
    {
191
        return '<?php else: ?>';
192
    }
193
 
194
    /**
195
     * Compile the end-if statements into valid PHP.
196
     *
197
     * @return string
198
     */
199
    protected function compileEndif()
200
    {
201
        return '<?php endif; ?>';
202
    }
203
 
204
    /**
205
     * Compile the end-unless statements into valid PHP.
206
     *
207
     * @return string
208
     */
209
    protected function compileEndunless()
210
    {
211
        return '<?php endif; ?>';
212
    }
213
 
214
    /**
215
     * Compile the if-isset statements into valid PHP.
216
     *
217
     * @param  string  $expression
218
     * @return string
219
     */
220
    protected function compileIsset($expression)
221
    {
222
        return "<?php if(isset{$expression}): ?>";
223
    }
224
 
225
    /**
226
     * Compile the end-isset statements into valid PHP.
227
     *
228
     * @return string
229
     */
230
    protected function compileEndIsset()
231
    {
232
        return '<?php endif; ?>';
233
    }
234
 
235
    /**
236
     * Compile the switch statements into valid PHP.
237
     *
238
     * @param  string  $expression
239
     * @return string
240
     */
241
    protected function compileSwitch($expression)
242
    {
243
        $this->firstCaseInSwitch = true;
244
 
245
        return "<?php switch{$expression}:";
246
    }
247
 
248
    /**
249
     * Compile the case statements into valid PHP.
250
     *
251
     * @param  string  $expression
252
     * @return string
253
     */
254
    protected function compileCase($expression)
255
    {
256
        if ($this->firstCaseInSwitch) {
257
            $this->firstCaseInSwitch = false;
258
 
259
            return "case {$expression}: ?>";
260
        }
261
 
262
        return "<?php case {$expression}: ?>";
263
    }
264
 
265
    /**
266
     * Compile the default statements in switch case into valid PHP.
267
     *
268
     * @return string
269
     */
270
    protected function compileDefault()
271
    {
272
        return '<?php default: ?>';
273
    }
274
 
275
    /**
276
     * Compile the end switch statements into valid PHP.
277
     *
278
     * @return string
279
     */
280
    protected function compileEndSwitch()
281
    {
282
        return '<?php endswitch; ?>';
283
    }
284
 
285
    /**
286
     * Compile a once block into valid PHP.
287
     *
288
     * @param  string|null  $id
289
     * @return string
290
     */
291
    protected function compileOnce($id = null)
292
    {
293
        $id = $id ? $this->stripParentheses($id) : "'".(string) Str::uuid()."'";
294
 
295
        return '<?php if (! $__env->hasRenderedOnce('.$id.')): $__env->markAsRenderedOnce('.$id.'); ?>';
296
    }
297
 
298
    /**
299
     * Compile an end-once block into valid PHP.
300
     *
301
     * @return string
302
     */
303
    public function compileEndOnce()
304
    {
305
        return '<?php endif; ?>';
306
    }
307
 
308
    /**
309
     * Compile a selected block into valid PHP.
310
     *
311
     * @param  string  $condition
312
     * @return string
313
     */
314
    protected function compileSelected($condition)
315
    {
316
        return "<?php if{$condition}: echo 'selected'; endif; ?>";
317
    }
318
 
319
    /**
320
     * Compile a checked block into valid PHP.
321
     *
322
     * @param  string  $condition
323
     * @return string
324
     */
325
    protected function compileChecked($condition)
326
    {
327
        return "<?php if{$condition}: echo 'checked'; endif; ?>";
328
    }
329
 
330
    /**
331
     * Compile a disabled block into valid PHP.
332
     *
333
     * @param  string  $condition
334
     * @return string
335
     */
336
    protected function compileDisabled($condition)
337
    {
338
        return "<?php if{$condition}: echo 'disabled'; endif; ?>";
339
    }
340
 
341
    /**
342
     * Compile a required block into valid PHP.
343
     *
344
     * @param  string  $condition
345
     * @return string
346
     */
347
    protected function compileRequired($condition)
348
    {
349
        return "<?php if{$condition}: echo 'required'; endif; ?>";
350
    }
351
 
352
    /**
353
     * Compile a readonly block into valid PHP.
354
     *
355
     * @param  string  $condition
356
     * @return string
357
     */
358
    protected function compileReadonly($condition)
359
    {
360
        return "<?php if{$condition}: echo 'readonly'; endif; ?>";
361
    }
362
 
363
    /**
364
     * Compile the push statements into valid PHP.
365
     *
366
     * @param  string  $expression
367
     * @return string
368
     */
369
    protected function compilePushIf($expression)
370
    {
371
        $parts = explode(',', $this->stripParentheses($expression), 2);
372
 
373
        return "<?php if({$parts[0]}): \$__env->startPush({$parts[1]}); ?>";
374
    }
375
 
376
    /**
377
     * Compile the end-push statements into valid PHP.
378
     *
379
     * @return string
380
     */
381
    protected function compileEndPushIf()
382
    {
383
        return '<?php $__env->stopPush(); endif; ?>';
384
    }
385
}