PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / sabberworm / php-css-parser / src / OutputFormatter.php
independent-analytics / vendor / sabberworm / php-css-parser / src Last commit date
CSSList 3 years ago Comment 3 years ago Parsing 3 years ago Property 3 years ago Rule 3 years ago RuleSet 3 years ago Value 3 years ago OutputFormat.php 3 years ago OutputFormatter.php 3 years ago Parser.php 3 years ago Renderable.php 3 years ago Settings.php 3 years ago
OutputFormatter.php
213 lines
1 <?php
2
3 namespace IAWP\Sabberworm\CSS;
4
5 use IAWP\Sabberworm\CSS\Parsing\OutputException;
6 class OutputFormatter
7 {
8 /**
9 * @var OutputFormat
10 */
11 private $oFormat;
12 public function __construct(OutputFormat $oFormat)
13 {
14 $this->oFormat = $oFormat;
15 }
16 /**
17 * @param string $sName
18 * @param string|null $sType
19 *
20 * @return string
21 */
22 public function space($sName, $sType = null)
23 {
24 $sSpaceString = $this->oFormat->get("Space{$sName}");
25 // If $sSpaceString is an array, we have multiple values configured
26 // depending on the type of object the space applies to
27 if (\is_array($sSpaceString)) {
28 if ($sType !== null && isset($sSpaceString[$sType])) {
29 $sSpaceString = $sSpaceString[$sType];
30 } else {
31 $sSpaceString = \reset($sSpaceString);
32 }
33 }
34 return $this->prepareSpace($sSpaceString);
35 }
36 /**
37 * @return string
38 */
39 public function spaceAfterRuleName()
40 {
41 return $this->space('AfterRuleName');
42 }
43 /**
44 * @return string
45 */
46 public function spaceBeforeRules()
47 {
48 return $this->space('BeforeRules');
49 }
50 /**
51 * @return string
52 */
53 public function spaceAfterRules()
54 {
55 return $this->space('AfterRules');
56 }
57 /**
58 * @return string
59 */
60 public function spaceBetweenRules()
61 {
62 return $this->space('BetweenRules');
63 }
64 /**
65 * @return string
66 */
67 public function spaceBeforeBlocks()
68 {
69 return $this->space('BeforeBlocks');
70 }
71 /**
72 * @return string
73 */
74 public function spaceAfterBlocks()
75 {
76 return $this->space('AfterBlocks');
77 }
78 /**
79 * @return string
80 */
81 public function spaceBetweenBlocks()
82 {
83 return $this->space('BetweenBlocks');
84 }
85 /**
86 * @return string
87 */
88 public function spaceBeforeSelectorSeparator()
89 {
90 return $this->space('BeforeSelectorSeparator');
91 }
92 /**
93 * @return string
94 */
95 public function spaceAfterSelectorSeparator()
96 {
97 return $this->space('AfterSelectorSeparator');
98 }
99 /**
100 * @param string $sSeparator
101 *
102 * @return string
103 */
104 public function spaceBeforeListArgumentSeparator($sSeparator)
105 {
106 return $this->space('BeforeListArgumentSeparator', $sSeparator);
107 }
108 /**
109 * @param string $sSeparator
110 *
111 * @return string
112 */
113 public function spaceAfterListArgumentSeparator($sSeparator)
114 {
115 return $this->space('AfterListArgumentSeparator', $sSeparator);
116 }
117 /**
118 * @return string
119 */
120 public function spaceBeforeOpeningBrace()
121 {
122 return $this->space('BeforeOpeningBrace');
123 }
124 /**
125 * Runs the given code, either swallowing or passing exceptions, depending on the `bIgnoreExceptions` setting.
126 *
127 * @param string $cCode the name of the function to call
128 *
129 * @return string|null
130 */
131 public function safely($cCode)
132 {
133 if ($this->oFormat->get('IgnoreExceptions')) {
134 // If output exceptions are ignored, run the code with exception guards
135 try {
136 return $cCode();
137 } catch (OutputException $e) {
138 return null;
139 }
140 // Do nothing
141 } else {
142 // Run the code as-is
143 return $cCode();
144 }
145 }
146 /**
147 * Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
148 *
149 * @param string $sSeparator
150 * @param array<array-key, Renderable|string> $aValues
151 * @param bool $bIncreaseLevel
152 *
153 * @return string
154 */
155 public function implode($sSeparator, array $aValues, $bIncreaseLevel = \false)
156 {
157 $sResult = '';
158 $oFormat = $this->oFormat;
159 if ($bIncreaseLevel) {
160 $oFormat = $oFormat->nextLevel();
161 }
162 $bIsFirst = \true;
163 foreach ($aValues as $mValue) {
164 if ($bIsFirst) {
165 $bIsFirst = \false;
166 } else {
167 $sResult .= $sSeparator;
168 }
169 if ($mValue instanceof Renderable) {
170 $sResult .= $mValue->render($oFormat);
171 } else {
172 $sResult .= $mValue;
173 }
174 }
175 return $sResult;
176 }
177 /**
178 * @param string $sString
179 *
180 * @return string
181 */
182 public function removeLastSemicolon($sString)
183 {
184 if ($this->oFormat->get('SemicolonAfterLastRule')) {
185 return $sString;
186 }
187 $sString = \explode(';', $sString);
188 if (\count($sString) < 2) {
189 return $sString[0];
190 }
191 $sLast = \array_pop($sString);
192 $sNextToLast = \array_pop($sString);
193 \array_push($sString, $sNextToLast . $sLast);
194 return \implode(';', $sString);
195 }
196 /**
197 * @param string $sSpaceString
198 *
199 * @return string
200 */
201 private function prepareSpace($sSpaceString)
202 {
203 return \str_replace("\n", "\n" . $this->indent(), $sSpaceString);
204 }
205 /**
206 * @return string
207 */
208 private function indent()
209 {
210 return \str_repeat($this->oFormat->sIndentation, $this->oFormat->level());
211 }
212 }
213