1 | <?php |
||
8 | class PHPCRAssetsExtension extends \Twig_Extension |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | private $jsPath; |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $cssPath; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $modesDir; |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $themesDir; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $rendered; |
||
31 | |||
32 | /** |
||
33 | * @param array $paths |
||
34 | */ |
||
35 | public function __construct($paths = array()) |
||
44 | |||
45 | /** |
||
46 | * {@inheritDoc} |
||
47 | * @see Twig_Extension::getFunctions() |
||
48 | */ |
||
49 | public function getFunctions() |
||
57 | |||
58 | /** |
||
59 | * @param array $parameters |
||
60 | */ |
||
61 | public function parametersRender($parameters) |
||
65 | |||
66 | /** |
||
67 | * @param array $parameters |
||
68 | * @param string $force |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getJs($parameters, $force = false) |
||
73 | { |
||
74 | $urls = array(); |
||
75 | |||
76 | if ($this->jsPath) { |
||
77 | $urls[] = $this->jsPath; |
||
78 | } |
||
79 | |||
80 | if ($this->modesDir) { |
||
81 | $urls[] = preg_replace('@\/$@', '', $this->modesDir) . '/' . $parameters['mode'] . '/' . $parameters['mode'] . '.js'; |
||
82 | } |
||
83 | |||
84 | |||
85 | if (!$force) { |
||
|
|||
86 | $urls = array_diff($urls, $this->rendered); |
||
87 | } |
||
88 | |||
89 | $this->rendered = array_unique(array_merge($this->rendered, $urls)); |
||
90 | |||
91 | return $urls; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param array $parameters |
||
96 | * @param string $force |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function getCss($parameters, $force = false) |
||
101 | { |
||
102 | $urls = array(); |
||
103 | |||
104 | if ($this->cssPath) { |
||
105 | $urls[] = $this->cssPath; |
||
106 | } |
||
107 | |||
108 | if ($this->modesDir) { |
||
109 | $urls[] = preg_replace('@\/$@', '', $this->themesDir) . '/' . $parameters['theme'] . '.css'; |
||
110 | } |
||
111 | |||
112 | |||
113 | if (!$force) { |
||
114 | $urls = array_diff($urls, $this->rendered); |
||
115 | } |
||
116 | |||
117 | $this->rendered = array_unique(array_merge($this->rendered, $urls)); |
||
118 | |||
119 | return $urls; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * {@inheritDoc} |
||
124 | * @see Twig_ExtensionInterface::getName() |
||
125 | */ |
||
126 | public function getName() |
||
130 | } |
||
131 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: