Passed
Pull Request — master (#145)
by Sergei
07:40
created

WebView::isValidPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\View;
6
7
use InvalidArgumentException;
8
use Yiisoft\Arrays\ArrayHelper;
9
use Yiisoft\Html\Html;
10
use Yiisoft\Html\Tag\Script;
11
use Yiisoft\View\Event\BodyBegin;
12
use Yiisoft\View\Event\BodyEnd;
13
use Yiisoft\View\Event\PageEnd;
14
15
use function array_key_exists;
16
use function get_class;
17
use function gettype;
18
use function in_array;
19
use function is_object;
20
use function is_string;
21
22
/**
23
 * View represents a view object in the MVC pattern.
24
 *
25
 * View provides a set of methods (e.g. {@see render()} for rendering purpose.
26
 *
27
 * You can modify its configuration by adding an array to your application config under `components` as it is shown in
28
 * the following example:
29
 *
30
 * ```php
31
 * 'view' => [
32
 *     'theme' => 'app\themes\MyTheme',
33
 *     'renderers' => [
34
 *         // you may add Smarty or Twig renderer here
35
 *     ]
36
 *     // ...
37
 * ]
38
 * ```
39
 *
40
 * For more details and usage information on View, see the [guide article on views](guide:structure-views).
41
 */
42
class WebView extends View
43
{
44
    /**
45
     * The location of registered JavaScript code block or files.
46
     * This means the location is in the head section.
47
     */
48
    public const POSITION_HEAD = 1;
49
50
    /**
51
     * The location of registered JavaScript code block or files.
52
     * This means the location is at the beginning of the body section.
53
     */
54
    public const POSITION_BEGIN = 2;
55
56
    /**
57
     * The location of registered JavaScript code block or files.
58
     * This means the location is at the end of the body section.
59
     */
60
    public const POSITION_END = 3;
61
62
    /**
63
     * The location of registered JavaScript code block.
64
     * This means the JavaScript code block will be executed when HTML document composition is ready.
65
     */
66
    public const POSITION_READY = 4;
67
68
    /**
69
     * The location of registered JavaScript code block.
70
     * This means the JavaScript code block will be executed when HTML page is completely loaded.
71
     */
72
    public const POSITION_LOAD = 5;
73
74
    private const DEFAULT_POSITION_JS_VARIABLE = self::POSITION_HEAD;
75
76
    /**
77
     * This is internally used as the placeholder for receiving the content registered for the head section.
78
     */
79
    private const PLACEHOLDER_HEAD = '<![CDATA[YII-BLOCK-HEAD-%s]]>';
80
81
    /**
82
     * This is internally used as the placeholder for receiving the content registered for the beginning of the body
83
     * section.
84
     */
85
    private const PLACEHOLDER_BODY_BEGIN = '<![CDATA[YII-BLOCK-BODY-BEGIN-%s]]>';
86
87
    /**
88
     * This is internally used as the placeholder for receiving the content registered for the end of the body section.
89
     */
90
    private const PLACEHOLDER_BODY_END = '<![CDATA[YII-BLOCK-BODY-END-%s]]>';
91
92
    /**
93
     * @var string the page title
94
     */
95
    private string $title = '';
96
97
    /**
98
     * @var array the registered meta tags.
99
     *
100
     * {@see registerMetaTag()}
101
     */
102
    private array $metaTags = [];
103
104
    /**
105
     * @var array the registered link tags.
106
     *
107
     * {@see registerLinkTag()}
108
     */
109
    private array $linkTags = [];
110
111
    /**
112
     * @var array the registered CSS code blocks.
113
     *
114
     * {@see registerCss()}
115
     */
116
    private array $css = [];
117
118
    /**
119
     * @var array the registered CSS files.
120
     *
121
     * {@see registerCssFile()}
122
     */
123
    private array $cssFiles = [];
124
125
    /**
126
     * @var array the registered JS code blocks
127
     * @psalm-var array<int, string[]|Script[]>
128
     *
129
     * {@see registerJs()}
130
     */
131
    private array $js = [];
132
133
    /**
134
     * @var array the registered JS files.
135
     *
136
     * {@see registerJsFile()}
137
     */
138
    private array $jsFiles = [];
139
140
    /**
141
     * Marks the position of an HTML head section.
142
     */
143 12
    public function head(): void
144
    {
145 12
        echo sprintf(self::PLACEHOLDER_HEAD, $this->getPlaceholderSignature());
146 12
    }
147
148
    /**
149
     * Marks the beginning of an HTML body section.
150
     */
151 12
    public function beginBody(): void
152
    {
153 12
        echo sprintf(self::PLACEHOLDER_BODY_BEGIN, $this->getPlaceholderSignature());
154 12
        $this->eventDispatcher->dispatch(new BodyBegin($this->getViewFile()));
155 12
    }
156
157
    /**
158
     * Marks the ending of an HTML body section.
159
     */
160 12
    public function endBody(): void
161
    {
162 12
        $this->eventDispatcher->dispatch(new BodyEnd($this->getViewFile()));
163 12
        echo sprintf(self::PLACEHOLDER_BODY_END, $this->getPlaceholderSignature());
164 12
    }
165
166
    /**
167
     * Marks the ending of an HTML page.
168
     *
169
     * @param bool $ajaxMode whether the view is rendering in AJAX mode. If true, the JS scripts registered at
170
     * {@see POSITION_READY} and {@see POSITION_LOAD} positions will be rendered at the end of the view like
171
     * normal scripts.
172
     */
173 12
    public function endPage($ajaxMode = false): void
174
    {
175 12
        $this->eventDispatcher->dispatch(new PageEnd($this->getViewFile()));
176
177 12
        $content = ob_get_clean();
178
179 12
        echo strtr($content, [
180 12
            sprintf(self::PLACEHOLDER_HEAD, $this->getPlaceholderSignature()) => $this->renderHeadHtml(),
181 12
            sprintf(self::PLACEHOLDER_BODY_BEGIN, $this->getPlaceholderSignature()) => $this->renderBodyBeginHtml(),
182 12
            sprintf(self::PLACEHOLDER_BODY_END, $this->getPlaceholderSignature()) => $this->renderBodyEndHtml($ajaxMode),
183
        ]);
184
185 12
        $this->clear();
186 12
    }
187
188
    /**
189
     * Renders a view in response to an AJAX request.
190
     *
191
     * This method is similar to {@see render()} except that it will surround the view being rendered with the calls of
192
     * {@see beginPage()}, {@see head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the
193
     * method is able to inject into the rendering result with JS/CSS scripts and files that are registered with the
194
     * view.
195
     *
196
     * @param string $view the view name. Please refer to {@see render()} on how to specify this parameter.
197
     * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view
198
     * file.
199
     *
200
     * @return string the rendering result
201
     *
202
     * {@see render()}
203
     */
204 2
    public function renderAjax(string $view, array $params = []): string
205
    {
206 2
        $viewFile = $this->findTemplateFile($view);
207
208 2
        ob_start();
209 2
        PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
210
211 2
        $this->beginPage();
212 2
        $this->head();
213 2
        $this->beginBody();
214 2
        echo $this->renderFile($viewFile, $params);
215 2
        $this->endBody();
216 2
        $this->endPage(true);
217
218 2
        return ob_get_clean();
219
    }
220
221
    /**
222
     * Clears up the registered meta tags, link tags, css/js scripts and files.
223
     */
224 12
    public function clear(): void
225
    {
226 12
        $this->metaTags = [];
227 12
        $this->linkTags = [];
228 12
        $this->css = [];
229 12
        $this->cssFiles = [];
230 12
        $this->js = [];
231 12
        $this->jsFiles = [];
232 12
    }
233
234
    /**
235
     * Registers a meta tag.
236
     *
237
     * For example, a description meta tag can be added like the following:
238
     *
239
     * ```php
240
     * $view->registerMetaTag([
241
     *     'name' => 'description',
242
     *     'content' => 'This website is about funny raccoons.'
243
     * ]);
244
     * ```
245
     *
246
     * will result in the meta tag `<meta name="description" content="This website is about funny raccoons.">`.
247
     *
248
     * @param array $options the HTML attributes for the meta tag.
249
     * @param string $key the key that identifies the meta tag. If two meta tags are registered with the same key, the
250
     * latter will overwrite the former. If this is null, the new meta tag will be appended to the
251
     * existing ones.
252
     */
253 1
    public function registerMetaTag(array $options, string $key = null): void
254
    {
255 1
        if ($key === null) {
256 1
            $this->metaTags[] = Html::meta()->attributes($options)->render();
257
        } else {
258
            $this->metaTags[$key] = Html::meta()->attributes($options)->render();
259
        }
260 1
    }
261
262
    /**
263
     * Registers a link tag.
264
     *
265
     * For example, a link tag for a custom [favicon](http://www.w3.org/2005/10/howto-favicon) can be added like the
266
     * following:
267
     *
268
     * ```php
269
     * $view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/myicon.png']);
270
     * ```
271
     *
272
     * which will result in the following HTML: `<link rel="icon" type="image/png" href="/myicon.png">`.
273
     *
274
     * **Note:** To register link tags for CSS stylesheets, use {@see registerCssFile()]} instead, which has more
275
     * options for this kind of link tag.
276
     *
277
     * @param array $options the HTML attributes for the link tag.
278
     * @param string|null $key the key that identifies the link tag. If two link tags are registered with the same
279
     * key, the latter will overwrite the former. If this is null, the new link tag will be appended
280
     * to the existing ones.
281
     */
282 1
    public function registerLinkTag(array $options, ?string $key = null): void
283
    {
284 1
        if ($key === null) {
285 1
            $this->linkTags[] = Html::link()->attributes($options)->render();
286
        } else {
287
            $this->linkTags[$key] = Html::link()->attributes($options)->render();
288
        }
289 1
    }
290
291
    /**
292
     * Registers a CSS code block.
293
     *
294
     * @param string $css the content of the CSS code block to be registered
295
     * @param array $options the HTML attributes for the `<style>`-tag.
296
     * @param string $key the key that identifies the CSS code block. If null, it will use $css as the key. If two CSS
297
     * code blocks are registered with the same key, the latter will overwrite the former.
298
     */
299 1
    public function registerCss(string $css, array $options = [], string $key = null): void
300
    {
301 1
        $key = $key ?: md5($css);
302 1
        $this->css[$key] = Html::style($css, $options)->render();
303 1
    }
304
305
    /**
306
     * Registers a CSS file.
307
     *
308
     * This method should be used for simple registration of CSS files. If you want to use features of
309
     * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use
310
     * {@see \Yiisoft\Assets\AssetBundle}.
311
     *
312
     * @param string $url the CSS file to be registered.
313
     * @param array $options the HTML attributes for the link tag. Please refer to {@see \Yiisoft\Html\Html::cssFile()}
314
     * for the supported options.
315
     * @param string $key the key that identifies the CSS script file. If null, it will use $url as the key. If two CSS
316
     * files are registered with the same key, the latter will overwrite the former.
317
     */
318 1
    public function registerCssFile(string $url, array $options = [], string $key = null): void
319
    {
320 1
        $key = $key ?: $url;
321
322 1
        $this->cssFiles[$key] = Html::cssFile($url, $options)->render();
323 1
    }
324
325
    /**
326
     * Registers a JS code block.
327
     *
328
     * @param string $js the JS code block to be registered
329
     * @param int $position the position at which the JS script tag should be inserted in a page.
330
     *
331
     * The possible values are:
332
     *
333
     * - {@see POSITION_HEAD}: in the head section
334
     * - {@see POSITION_BEGIN}: at the beginning of the body section
335
     * - {@see POSITION_END}: at the end of the body section. This is the default value.
336
     * - {@see POSITION_LOAD}: executed when HTML page is completely loaded.
337
     * - {@see POSITION_READY}: executed when HTML document composition is ready.
338
     * @param string $key the key that identifies the JS code block. If null, it will use $js as the key. If two JS code
339
     * blocks are registered with the same key, the latter will overwrite the former.
340
     */
341 4
    public function registerJs(string $js, int $position = self::POSITION_END, string $key = null): void
342
    {
343 4
        $key = $key ?: md5($js);
344 4
        $this->js[$position][$key] = $js;
345 4
    }
346
347
    /**
348
     * Register a `script` tag
349
     *
350
     * @see registerJs()
351
     */
352 3
    public function registerScriptTag(Script $script, int $position = self::POSITION_END, string $key = null): void
353
    {
354 3
        $key = $key ?: md5($script->render());
355 3
        $this->js[$position][$key] = $script;
356 3
    }
357
358
    /**
359
     * Registers a JS file.
360
     *
361
     * This method should be used for simple registration of JS files. If you want to use features of
362
     * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use
363
     * {@see \Yiisoft\Assets\AssetBundle}.
364
     *
365
     * @param string $url the JS file to be registered.
366
     * @param array $options the HTML attributes for the script tag. The following options are specially handled and
367
     * are not treated as HTML attributes:
368
     *
369
     * - `position`: specifies where the JS script tag should be inserted in a page. The possible values are:
370
     *     * {@see POSITION_HEAD}: in the head section
371
     *     * {@see POSITION_BEGIN}: at the beginning of the body section
372
     *     * {@see POSITION_END}: at the end of the body section. This is the default value.
373
     *
374
     * Please refer to {@see \Yiisoft\Html\Html::javaScriptFile()} for other supported options.
375
     * @param string $key the key that identifies the JS script file. If null, it will use $url as the key. If two JS
376
     * files are registered with the same key at the same position, the latter will overwrite the former.
377
     * Note that position option takes precedence, thus files registered with the same key, but different
378
     * position option will not override each other.
379
     */
380 1
    public function registerJsFile(string $url, array $options = [], string $key = null): void
381
    {
382 1
        $key = $key ?: $url;
383
384 1
        $position = ArrayHelper::remove($options, 'position', self::POSITION_END);
385 1
        $this->jsFiles[$position][$key] = Html::javaScriptFile($url, $options)->render();
386 1
    }
387
388
    /**
389
     * Registers a JS code block defining a variable. The name of variable will be used as key, preventing duplicated
390
     * variable names.
391
     *
392
     * @param string $name Name of the variable
393
     * @param array|string $value Value of the variable
394
     * @param int $position the position in a page at which the JavaScript variable should be inserted.
395
     *
396
     * The possible values are:
397
     *
398
     * - {@see POSITION_HEAD}: in the head section. This is the default value.
399
     * - {@see POSITION_BEGIN}: at the beginning of the body section.
400
     * - {@see POSITION_END}: at the end of the body section.
401
     * - {@see POSITION_LOAD}: enclosed within jQuery(window).load().
402
     *   Note that by using this position, the method will automatically register the jQuery js file.
403
     * - {@see POSITION_READY}: enclosed within jQuery(document).ready().
404
     *   Note that by using this position, the method will automatically register the jQuery js file.
405
     */
406 2
    public function registerJsVar(string $name, $value, int $position = self::POSITION_HEAD): void
407
    {
408 2
        $js = sprintf('var %s = %s;', $name, \Yiisoft\Json\Json::htmlEncode($value));
409 2
        $this->registerJs($js, $position, $name);
410 2
    }
411
412
    /**
413
     * Renders the content to be inserted in the head section.
414
     *
415
     * The content is rendered using the registered meta tags, link tags, CSS/JS code blocks and files.
416
     *
417
     * @return string the rendered content
418
     */
419 12
    protected function renderHeadHtml(): string
420
    {
421 12
        $lines = [];
422 12
        if (!empty($this->metaTags)) {
423 1
            $lines[] = implode("\n", $this->metaTags);
424
        }
425
426 12
        if (!empty($this->linkTags)) {
427 1
            $lines[] = implode("\n", $this->linkTags);
428
        }
429 12
        if (!empty($this->cssFiles)) {
430 1
            $lines[] = implode("\n", $this->cssFiles);
431
        }
432 12
        if (!empty($this->css)) {
433 1
            $lines[] = implode("\n", $this->css);
434
        }
435 12
        if (!empty($this->jsFiles[self::POSITION_HEAD])) {
436 1
            $lines[] = implode("\n", $this->jsFiles[self::POSITION_HEAD]);
437
        }
438 12
        if (!empty($this->js[self::POSITION_HEAD])) {
439 2
            $lines[] = $this->generateJs($this->js[self::POSITION_HEAD]);
440
        }
441
442 12
        return empty($lines) ? '' : implode("\n", $lines);
443
    }
444
445
    /**
446
     * Renders the content to be inserted at the beginning of the body section.
447
     *
448
     * The content is rendered using the registered JS code blocks and files.
449
     *
450
     * @return string the rendered content
451
     */
452 12
    protected function renderBodyBeginHtml(): string
453
    {
454 12
        $lines = [];
455 12
        if (!empty($this->jsFiles[self::POSITION_BEGIN])) {
456 1
            $lines[] = implode("\n", $this->jsFiles[self::POSITION_BEGIN]);
457
        }
458 12
        if (!empty($this->js[self::POSITION_BEGIN])) {
459
            $lines[] = $this->generateJs($this->js[self::POSITION_BEGIN]);
460
        }
461
462 12
        return empty($lines) ? '' : implode("\n", $lines);
463
    }
464
465
    /**
466
     * Renders the content to be inserted at the end of the body section.
467
     *
468
     * The content is rendered using the registered JS code blocks and files.
469
     *
470
     * @param bool $ajaxMode whether the view is rendering in AJAX mode. If true, the JS scripts registered at
471
     * {@see POSITION_READY} and {@see POSITION_LOAD} positions will be rendered at the end of the view like normal
472
     * scripts.
473
     *
474
     * @return string the rendered content
475
     */
476 12
    protected function renderBodyEndHtml(bool $ajaxMode): string
477
    {
478 12
        $lines = [];
479
480 12
        if (!empty($this->jsFiles[self::POSITION_END])) {
481 1
            $lines[] = implode("\n", $this->jsFiles[self::POSITION_END]);
482
        }
483
484 12
        if ($ajaxMode) {
485 2
            $scripts = array_merge(
486 2
                $this->js[self::POSITION_END] ?? [],
487 2
                $this->js[self::POSITION_READY] ?? [],
488 2
                $this->js[self::POSITION_LOAD] ?? [],
489
            );
490 2
            if (!empty($scripts)) {
491 2
                $lines[] = $this->generateJs($scripts);
492
            }
493
        } else {
494 10
            if (!empty($this->js[self::POSITION_END])) {
495 3
                $lines[] = $this->generateJs($this->js[self::POSITION_END]);
496
            }
497 10
            if (!empty($this->js[self::POSITION_READY])) {
498
                $js = "document.addEventListener('DOMContentLoaded', function(event) {\n" .
499 1
                    $this->generateJsWithoutTag($this->js[self::POSITION_READY]) .
500 1
                    "\n});";
501 1
                $lines[] = Html::script($js)->render();
502
            }
503 10
            if (!empty($this->js[self::POSITION_LOAD])) {
504
                $js = "window.addEventListener('load', function (event) {\n" .
505
                    $this->generateJsWithoutTag($this->js[self::POSITION_LOAD]) .
506
                    "\n});";
507
                $lines[] = Html::script($js)->render();
508
            }
509
        }
510
511 12
        return empty($lines) ? '' : implode("\n", $lines);
512
    }
513
514
    /**
515
     * Get title in views.
516
     *
517
     * in Layout:
518
     *
519
     * ```php
520
     * <title><?= Html::encode($this->getTitle()) ?></title>
521
     * ```
522
     *
523
     * in Views:
524
     *
525
     * ```php
526
     * $this->setTitle('Web Application - Yii 3.0.');
527
     * ```
528
     *
529
     * @return string
530
     */
531
    public function getTitle(): string
532
    {
533
        return $this->title;
534
    }
535
536
    /**
537
     * It processes the CSS configuration generated by the asset manager and converts it into HTML code.
538
     *
539
     * @param array $cssFiles
540
     */
541
    public function setCssFiles(array $cssFiles): void
542
    {
543
        foreach ($cssFiles as $key => $value) {
544
            $this->registerCssFile(
545
                $cssFiles[$key]['url'],
546
                $cssFiles[$key]['attributes']
547
            );
548
        }
549
    }
550
551
    /**
552
     * It processes the JS configuration generated by the asset manager and converts it into HTML code.
553
     *
554
     * @param array $jsFiles
555
     */
556
    public function setJsFiles(array $jsFiles): void
557
    {
558
        foreach ($jsFiles as $key => $value) {
559
            $this->registerJsFile(
560
                $jsFiles[$key]['url'],
561
                $jsFiles[$key]['attributes']
562
            );
563
        }
564
    }
565
566
    /**
567
     * It processes the JS strings generated by the asset manager.
568
     *
569
     * @param array $jsStrings
570
     */
571
    public function setJsStrings(array $jsStrings): void
572
    {
573
        foreach ($jsStrings as $value) {
574
            $this->registerJs(
575
                $value['string'],
576
                $value['attributes']['position']
577
            );
578
        }
579
    }
580
581
    /**
582
     * It processes the JS variables generated by the asset manager and converts it into JS code.
583
     *
584
     * @param array $jsVars
585
     */
586 5
    public function setJsVars(array $jsVars): void
587
    {
588 5
        foreach ($jsVars as $key => $value) {
589 5
            if (is_string($key)) {
590 1
                $this->registerJsVar($key, $value, self::DEFAULT_POSITION_JS_VARIABLE);
591
            } else {
592 5
                $this->registerJsVarByConfig($value);
593
            }
594
        }
595 1
    }
596
597
    /**
598
     * Set title in views.
599
     *
600
     * {@see getTitle()}
601
     *
602
     * @param string $value
603
     */
604
    public function setTitle(string $value): void
605
    {
606
        $this->title = $value;
607
    }
608
609
    /**
610
     * @throws InvalidArgumentException
611
     */
612 5
    private function registerJsVarByConfig(array $config): void
613
    {
614 5
        if (!array_key_exists(0, $config)) {
615 1
            throw new InvalidArgumentException('Do not set JS variable name.');
616
        }
617 4
        $key = $config[0];
618
619 4
        if (!is_string($key)) {
620 1
            throw new InvalidArgumentException(
621 1
                sprintf(
622 1
                    'JS variable name should be string. Got %s.',
623 1
                    is_object($key) ? get_class($key) : gettype($key)
624
                )
625
            );
626
        }
627
628 3
        if (!array_key_exists(1, $config)) {
629 1
            throw new InvalidArgumentException('Do not set JS variable value.');
630
        }
631
        /** @var mixed */
632 2
        $value = $config[1];
633
634 2
        $position = $config['position'] ?? self::DEFAULT_POSITION_JS_VARIABLE;
635 2
        if (!$this->isValidPosition($position)) {
636 1
            throw new InvalidArgumentException('Invalid position of JS variable.');
637
        }
638
639 1
        $this->registerJsVar($key, $value, $position);
640 1
    }
641
642
    /**
643
     * @param Script[]|string[] $items
644
     */
645 5
    private function generateJs(array $items): string
646
    {
647 5
        $lines = [];
648
649 5
        $js = [];
650 5
        foreach ($items as $item) {
651 5
            if ($item instanceof Script) {
652 3
                if ($js !== []) {
653 2
                    $lines[] = Html::script(implode("\n", $js))->render();
654 2
                    $js = [];
655
                }
656 3
                $lines[] = $item->render();
657
            } else {
658 4
                $js[] = $item;
659
            }
660
        }
661 5
        if ($js !== []) {
662 3
            $lines[] = Html::script(implode("\n", $js))->render();
663
        }
664
665 5
        return implode("\n", $lines);
666
    }
667
668
    /**
669
     * @param Script[]|string[] $items
670
     */
671 1
    private function generateJsWithoutTag(array $items): string
672
    {
673 1
        $js = [];
674 1
        foreach ($items as $item) {
675 1
            $js[] = $item instanceof Script ? $item->getContent() : $item;
676
        }
677 1
        return implode("\n", $js);
678
    }
679
680 2
    private function isValidPosition($position): bool
681
    {
682 2
        return in_array(
683 2
            $position,
684
            [
685 2
                self::POSITION_HEAD,
686 2
                self::POSITION_BEGIN,
687 2
                self::POSITION_END,
688 2
                self::POSITION_READY,
689 2
                self::POSITION_LOAD,
690
            ],
691 2
            true,
692
        );
693
    }
694
}
695