Completed
Push — master ( bc7135...aca075 )
by Asmir
10s
created

getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Goetas\Twital\EventSubscriber;
4
5
use Goetas\Twital\EventDispatcher\CompilerEvents;
6
use Goetas\Twital\EventDispatcher\SourceEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
/**
10
 *
11
 * @author Asmir Mustafic <[email protected]>
12
 *
13
 */
14
class ReplaceDoctypeAsTwigExpressionSubscriber implements EventSubscriberInterface
15
{
16 25
    public static function getSubscribedEvents()
17
    {
18
        return array(
19 25
            CompilerEvents::PRE_LOAD => array('replaceDoctype', 130),
20 25
        );
21
    }
22
23
    /**
24
     *
25
     * @param SourceEvent $event
26
     */
27 24
    public function replaceDoctype(SourceEvent $event)
28
    {
29 24
        $source = $event->getTemplate();
30
31 24
        $source = preg_replace_callback('/^<!doctype.*?>/im', function ($mch) {
32 2
            return '{{ \'' . addslashes($mch[0]) . '\' }}';
33 24
        }, $source);
34
35 24
        $event->setTemplate($source);
36 24
    }
37
}
38