1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2016 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CoreBundle\Event; |
||
13 | |||
14 | use Symfony\Component\EventDispatcher\Event; |
||
15 | |||
16 | /** |
||
17 | * Class BuildJsEvent. |
||
18 | */ |
||
19 | class BuildJsEvent extends Event |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $js = ''; |
||
25 | |||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $debugMode; |
||
30 | |||
31 | /** |
||
32 | * @param bool $debugMode |
||
33 | */ |
||
34 | public function __construct($js, $debugMode = false) |
||
35 | { |
||
36 | $this->js = $js; |
||
37 | $this->debugMode = $debugMode; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getJs() |
||
44 | { |
||
45 | return $this->debugMode ? $this->js : \JSMin::minify($this->js); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Append JS. |
||
50 | * |
||
51 | * @param string $js |
||
52 | * @param string $section The section name. Shows when in debug mode |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function appendJs($js, $section = '') |
||
57 | { |
||
58 | if ($section && $this->debugMode) { |
||
59 | $slashes = str_repeat('/', strlen($section) + 10); |
||
60 | $this->js .= <<<JS |
||
61 | \n |
||
62 | {$slashes} |
||
63 | // {$section} Start |
||
64 | {$slashes} |
||
65 | \n |
||
66 | JS; |
||
67 | } |
||
68 | |||
69 | $this->js .= $js; |
||
70 | |||
71 | if ($section && $this->debugMode) { |
||
72 | $this->js .= <<<JS |
||
73 | \n |
||
74 | {$slashes} |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
75 | // {$section} End |
||
76 | {$slashes} |
||
77 | JS; |
||
78 | } |
||
79 | |||
80 | return $this; |
||
81 | } |
||
82 | } |
||
83 |