Completed
Push — master ( 32c171...66d5a1 )
by Anton
02:51
created

ProcessorsTrait::processSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Views\Engines\Traits;
10
11
use Spiral\Views\EnvironmentInterface;
12
use Spiral\Views\ViewSource;
13
14
/**
15
 * Provides support to pre-process view source before sending it to engine. Processing always
16
 * environment specific.
17
 */
18
trait ProcessorsTrait
19
{
20
    /**
21
     * @var \Spiral\Views\ProcessorInterface[]
22
     */
23
    private $processors;
24
25
    /**
26
     * Pre-process view source.
27
     *
28
     * @param EnvironmentInterface $environment
29
     * @param ViewSource           $source
30
     *
31
     * @return ViewSource
32
     */
33
    private function processSource(
34
        EnvironmentInterface $environment,
35
        ViewSource $source
36
    ): ViewSource {
37
        foreach ($this->processors as $processor) {
38
            $source = $source->withCode(
39
                $processor->modify($environment, $source, $source->getCode())
40
            );
41
        }
42
43
        return $source;
44
    }
45
}