Complex classes like Compiler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Compiler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
48 | class Compiler |
||
49 | { |
||
50 | const VERSION = 'v0.5.1'; |
||
51 | |||
52 | public static $TRUE = ['keyword', 'true']; |
||
53 | public static $FALSE = ['keyword', 'false']; |
||
54 | |||
55 | /** |
||
56 | * @var callable[] |
||
57 | */ |
||
58 | private $libFunctions = []; |
||
59 | |||
60 | /** |
||
61 | * @var string[] |
||
62 | */ |
||
63 | private $registeredVars = []; |
||
64 | |||
65 | /** |
||
66 | * @var bool |
||
67 | */ |
||
68 | protected $preserveComments = false; |
||
69 | |||
70 | /** |
||
71 | * @var string $vPrefix prefix of abstract properties |
||
72 | */ |
||
73 | private $vPrefix = '@'; |
||
74 | |||
75 | /** |
||
76 | * @var string $mPrefix prefix of abstract blocks |
||
77 | */ |
||
78 | private $mPrefix = '$'; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | private $parentSelector = '&'; |
||
84 | |||
85 | /** |
||
86 | * @var bool $importDisabled disable @import |
||
87 | */ |
||
88 | private $importDisabled = false; |
||
89 | |||
90 | /** |
||
91 | * @var string[] |
||
92 | */ |
||
93 | private $importDirs = []; |
||
94 | |||
95 | /** |
||
96 | * @var int |
||
97 | */ |
||
98 | private $numberPrecision; |
||
99 | |||
100 | /** |
||
101 | * @var string[] |
||
102 | */ |
||
103 | private $allParsedFiles = []; |
||
104 | |||
105 | /** |
||
106 | * set to the parser that generated the current line when compiling |
||
107 | * so we know how to create error messages |
||
108 | * @var \LesserPhp\Parser |
||
109 | */ |
||
110 | private $sourceParser; |
||
111 | |||
112 | /** |
||
113 | * @var integer $sourceLoc Lines of Code |
||
114 | */ |
||
115 | private $sourceLoc; |
||
116 | |||
117 | /** |
||
118 | * @var int $nextImportId uniquely identify imports |
||
119 | */ |
||
120 | private static $nextImportId = 0; |
||
121 | |||
122 | /** |
||
123 | * @var Parser |
||
124 | */ |
||
125 | private $parser; |
||
126 | |||
127 | /** |
||
128 | * @var \LesserPhp\Formatter\FormatterInterface |
||
129 | */ |
||
130 | private $formatter; |
||
131 | |||
132 | /** |
||
133 | * @var \LesserPhp\NodeEnv What's the meaning of "env" in this context? |
||
134 | */ |
||
135 | private $env; |
||
136 | |||
137 | /** |
||
138 | * @var \LesserPhp\Library\Coerce |
||
139 | */ |
||
140 | private $coerce; |
||
141 | |||
142 | /** |
||
143 | * @var \LesserPhp\Library\Assertions |
||
144 | */ |
||
145 | private $assertions; |
||
146 | |||
147 | /** |
||
148 | * @var \LesserPhp\Library\Functions |
||
149 | */ |
||
150 | private $functions; |
||
151 | |||
152 | /** |
||
153 | * @var mixed what's this exactly? |
||
154 | */ |
||
155 | private $scope; |
||
156 | |||
157 | /** |
||
158 | * @var string |
||
159 | */ |
||
160 | private $formatterName; |
||
161 | |||
162 | /** |
||
163 | * @var \LesserPhp\Color\Converter |
||
164 | */ |
||
165 | private $converter; |
||
166 | |||
167 | /** |
||
168 | * Constructor. |
||
169 | * |
||
170 | * Hardwires dependencies for now |
||
171 | */ |
||
172 | 64 | public function __construct() |
|
173 | { |
||
174 | 64 | $this->coerce = new Coerce(); |
|
175 | 64 | $this->assertions = new Assertions($this->coerce); |
|
176 | 64 | $this->converter = new Converter(); |
|
177 | 64 | $this->functions = new Functions($this->assertions, $this->coerce, $this, $this->converter); |
|
178 | 64 | } |
|
179 | |||
180 | /** |
||
181 | * @param array $items |
||
182 | * @param $delim |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | 48 | public static function compressList(array $items, $delim) |
|
187 | { |
||
188 | 48 | if (!isset($items[1]) && isset($items[0])) { |
|
189 | 48 | return $items[0]; |
|
190 | } else { |
||
191 | 27 | return ['list', $delim, $items]; |
|
192 | } |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @param string $what |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | 36 | public static function pregQuote($what) |
|
201 | { |
||
202 | 36 | return preg_quote($what, '/'); |
|
203 | } |
||
204 | |||
205 | /** |
||
206 | * @param array $importPath |
||
207 | * @param $parentBlock |
||
208 | * @param $out |
||
209 | * |
||
210 | * @return array|false |
||
211 | * @throws \LesserPhp\Exception\GeneralException |
||
212 | */ |
||
213 | 3 | protected function tryImport(array $importPath, $parentBlock, $out) |
|
214 | { |
||
215 | 3 | if ($importPath[0] === 'function' && $importPath[1] === 'url') { |
|
216 | 2 | $importPath = $this->flattenList($importPath[2]); |
|
217 | } |
||
218 | |||
219 | 3 | $str = $this->coerce->coerceString($importPath); |
|
220 | 3 | if ($str === null) { |
|
221 | 2 | return false; |
|
222 | } |
||
223 | |||
224 | 3 | $url = $this->compileValue($this->functions->e($str)); |
|
225 | |||
226 | // don't import if it ends in css |
||
227 | 3 | if (substr_compare($url, '.css', -4, 4) === 0) { |
|
228 | return false; |
||
229 | } |
||
230 | |||
231 | 3 | $realPath = $this->functions->findImport($url); |
|
232 | |||
233 | 3 | if ($realPath === null) { |
|
234 | 2 | return false; |
|
235 | } |
||
236 | |||
237 | 3 | if ($this->isImportDisabled()) { |
|
238 | 1 | return [false, '/* import disabled */']; |
|
239 | } |
||
240 | |||
241 | 2 | if (isset($this->allParsedFiles[realpath($realPath)])) { |
|
242 | 2 | return [false, null]; |
|
243 | } |
||
244 | |||
245 | 2 | $this->addParsedFile($realPath); |
|
246 | 2 | $parser = $this->makeParser($realPath); |
|
247 | 2 | $root = $parser->parse(file_get_contents($realPath)); |
|
248 | |||
249 | // set the parents of all the block props |
||
250 | 2 | foreach ($root->props as $prop) { |
|
251 | 2 | if ($prop[0] === 'block') { |
|
252 | 2 | $prop[1]->parent = $parentBlock; |
|
253 | } |
||
254 | } |
||
255 | |||
256 | // copy mixins into scope, set their parents |
||
257 | // bring blocks from import into current block |
||
258 | // TODO: need to mark the source parser these came from this file |
||
259 | 2 | foreach ($root->children as $childName => $child) { |
|
260 | 2 | if (isset($parentBlock->children[$childName])) { |
|
261 | 2 | $parentBlock->children[$childName] = array_merge( |
|
262 | 2 | $parentBlock->children[$childName], |
|
263 | $child |
||
264 | ); |
||
265 | } else { |
||
266 | 2 | $parentBlock->children[$childName] = $child; |
|
267 | } |
||
268 | } |
||
269 | |||
270 | 2 | $pi = pathinfo($realPath); |
|
271 | 2 | $dir = $pi["dirname"]; |
|
272 | |||
273 | 2 | list($top, $bottom) = $this->sortProps($root->props, true); |
|
274 | 2 | $this->compileImportedProps($top, $parentBlock, $out, $dir); |
|
275 | |||
276 | 2 | return [true, $bottom, $parser, $dir]; |
|
277 | } |
||
278 | |||
279 | /** |
||
280 | * @param array $props |
||
281 | * @param $block |
||
282 | * @param $out |
||
283 | * @param string $importDir |
||
284 | */ |
||
285 | 2 | protected function compileImportedProps(array $props, $block, $out, $importDir) |
|
300 | |||
301 | /** |
||
302 | * Recursively compiles a block. |
||
303 | * |
||
304 | * A block is analogous to a CSS block in most cases. A single LESS document |
||
305 | * is encapsulated in a block when parsed, but it does not have parent tags |
||
306 | * so all of it's children appear on the root level when compiled. |
||
307 | * |
||
308 | * Blocks are made up of props and children. |
||
309 | * |
||
310 | * Props are property instructions, array tuples which describe an action |
||
311 | * to be taken, eg. write a property, set a variable, mixin a block. |
||
312 | * |
||
313 | * The children of a block are just all the blocks that are defined within. |
||
314 | * This is used to look up mixins when performing a mixin. |
||
315 | * |
||
316 | * Compiling the block involves pushing a fresh environment on the stack, |
||
317 | * and iterating through the props, compiling each one. |
||
318 | * |
||
319 | * See lessc::compileProp() |
||
320 | * |
||
321 | * @param Block $block |
||
322 | * |
||
323 | * @throws \LesserPhp\Exception\GeneralException |
||
324 | */ |
||
325 | 49 | protected function compileBlock(Block $block) |
|
349 | |||
350 | /** |
||
351 | * @param Block $block |
||
352 | * |
||
353 | * @throws \LesserPhp\Exception\GeneralException |
||
354 | */ |
||
355 | 46 | protected function compileCSSBlock(Block $block) |
|
369 | |||
370 | /** |
||
371 | * @param Block\Media $media |
||
372 | */ |
||
373 | 3 | protected function compileMedia(Block\Media $media) |
|
398 | |||
399 | /** |
||
400 | * @param $scope |
||
401 | * |
||
402 | * @return mixed |
||
403 | */ |
||
404 | 3 | protected function mediaParent($scope) |
|
415 | |||
416 | /** |
||
417 | * @param Block $block |
||
418 | * @param string[] $selectors |
||
419 | */ |
||
420 | 4 | protected function compileNestedBlock(Block $block, array $selectors) |
|
431 | |||
432 | /** |
||
433 | * @param Block $root |
||
434 | */ |
||
435 | 49 | protected function compileRoot(Block $root) |
|
442 | |||
443 | /** |
||
444 | * @param Block $block |
||
445 | * @param \stdClass $out |
||
446 | * |
||
447 | * @throws \LesserPhp\Exception\GeneralException |
||
448 | */ |
||
449 | 49 | protected function compileProps(Block $block, $out) |
|
456 | |||
457 | /** |
||
458 | * Deduplicate lines in a block. Comments are not deduplicated. If a |
||
459 | * duplicate rule is detected, the comments immediately preceding each |
||
460 | * occurence are consolidated. |
||
461 | * |
||
462 | * @param array $lines |
||
463 | * |
||
464 | * @return array |
||
465 | */ |
||
466 | 38 | protected function deduplicate(array $lines) |
|
485 | |||
486 | /** |
||
487 | * @param array $props |
||
488 | * @param bool $split |
||
489 | * |
||
490 | * @return array |
||
491 | */ |
||
492 | 49 | protected function sortProps(array $props, $split = false) |
|
536 | |||
537 | /** |
||
538 | * @param array $queries |
||
539 | * |
||
540 | * @return string |
||
541 | */ |
||
542 | 3 | protected function compileMediaQuery(array $queries) |
|
579 | |||
580 | /** |
||
581 | * @param \LesserPhp\NodeEnv $env |
||
582 | * @param array $childQueries |
||
583 | * |
||
584 | * @return array |
||
585 | */ |
||
586 | 3 | protected function multiplyMedia(NodeEnv $env = null, array $childQueries = null) |
|
613 | |||
614 | /** |
||
615 | * @param $tag |
||
616 | * @param $replace |
||
617 | * |
||
618 | * @return int |
||
619 | */ |
||
620 | 46 | protected function expandParentSelectors(&$tag, $replace) |
|
632 | |||
633 | /** |
||
634 | * @return array|null |
||
635 | */ |
||
636 | 46 | protected function findClosestSelectors() |
|
650 | |||
651 | |||
652 | /** |
||
653 | * multiply $selectors against the nearest selectors in env |
||
654 | * |
||
655 | * @param array $selectors |
||
656 | * |
||
657 | * @return array |
||
658 | */ |
||
659 | 46 | protected function multiplySelectors(array $selectors) |
|
689 | |||
690 | /** |
||
691 | * reduces selector expressions |
||
692 | * |
||
693 | * @param array $selectors |
||
694 | * |
||
695 | * @return array |
||
696 | * @throws \LesserPhp\Exception\GeneralException |
||
697 | */ |
||
698 | 46 | protected function compileSelectors(array $selectors) |
|
713 | |||
714 | /** |
||
715 | * @param $left |
||
716 | * @param $right |
||
717 | * |
||
718 | * @return bool |
||
719 | */ |
||
720 | 4 | protected function equals($left, $right) |
|
724 | |||
725 | /** |
||
726 | * @param $block |
||
727 | * @param $orderedArgs |
||
728 | * @param $keywordArgs |
||
729 | * |
||
730 | * @return bool |
||
731 | */ |
||
732 | 21 | protected function patternMatch($block, $orderedArgs, $keywordArgs) |
|
820 | |||
821 | /** |
||
822 | * @param array $blocks |
||
823 | * @param $orderedArgs |
||
824 | * @param $keywordArgs |
||
825 | * @param array $skip |
||
826 | * |
||
827 | * @return array|null |
||
828 | */ |
||
829 | 21 | protected function patternMatchAll(array $blocks, $orderedArgs, $keywordArgs, array $skip = []) |
|
845 | |||
846 | /** |
||
847 | * attempt to find blocks matched by path and args |
||
848 | * |
||
849 | * @param $searchIn |
||
850 | * @param array $path |
||
851 | * @param $orderedArgs |
||
852 | * @param $keywordArgs |
||
853 | * @param array $seen |
||
854 | * |
||
855 | * @return array|null |
||
856 | */ |
||
857 | 22 | protected function findBlocks($searchIn, array $path, $orderedArgs, $keywordArgs, array $seen = []) |
|
905 | |||
906 | /** |
||
907 | * sets all argument names in $args to either the default value |
||
908 | * or the one passed in through $values |
||
909 | * |
||
910 | * @param array $args |
||
911 | * @param $orderedValues |
||
912 | * @param $keywordValues |
||
913 | * |
||
914 | * @throws \LesserPhp\Exception\GeneralException |
||
915 | */ |
||
916 | 16 | protected function zipSetArgs(array $args, $orderedValues, $keywordValues) |
|
956 | |||
957 | /** |
||
958 | * compile a prop and update $lines or $blocks appropriately |
||
959 | * |
||
960 | * @param $prop |
||
961 | * @param Block $block |
||
962 | * @param $out |
||
963 | * |
||
964 | * @throws \LesserPhp\Exception\GeneralException |
||
965 | */ |
||
966 | 49 | protected function compileProp($prop, Block $block, $out) |
|
1111 | |||
1112 | |||
1113 | /** |
||
1114 | * Compiles a primitive value into a CSS property value. |
||
1115 | * |
||
1116 | * Values in lessphp are typed by being wrapped in arrays, their format is |
||
1117 | * typically: |
||
1118 | * |
||
1119 | * array(type, contents [, additional_contents]*) |
||
1120 | * |
||
1121 | * The input is expected to be reduced. This function will not work on |
||
1122 | * things like expressions and variables. |
||
1123 | * |
||
1124 | * @param array $value |
||
1125 | * @param array $options |
||
1126 | * |
||
1127 | * @return string |
||
1128 | * @throws GeneralException |
||
1129 | */ |
||
1130 | 53 | public function compileValue(array $value, array $options = []) |
|
1149 | |||
1150 | /** |
||
1151 | * Helper function to get arguments for color manipulation functions. |
||
1152 | * takes a list that contains a color like thing and a percentage |
||
1153 | * |
||
1154 | * @param array $args |
||
1155 | * |
||
1156 | * @return array |
||
1157 | */ |
||
1158 | 2 | public function colorArgs(array $args) |
|
1169 | |||
1170 | /** |
||
1171 | * Convert the rgb, rgba, hsl color literals of function type |
||
1172 | * as returned by the parser into values of color type. |
||
1173 | * |
||
1174 | * @param array $func |
||
1175 | * |
||
1176 | * @return bool|mixed |
||
1177 | */ |
||
1178 | 24 | protected function funcToColor(array $func) |
|
1179 | { |
||
1180 | 24 | $fname = $func[1]; |
|
1181 | 24 | if ($func[2][0] !== 'list') { |
|
1182 | 6 | return false; |
|
1183 | } // need a list of arguments |
||
1184 | /** @var array $rawComponents */ |
||
1185 | 24 | $rawComponents = $func[2][2]; |
|
1186 | |||
1187 | 24 | if ($fname === 'hsl' || $fname === 'hsla') { |
|
1188 | 1 | $hsl = ['hsl']; |
|
1189 | 1 | $i = 0; |
|
1190 | 1 | foreach ($rawComponents as $c) { |
|
1191 | 1 | $val = $this->reduce($c); |
|
1192 | 1 | $val = isset($val[1]) ? (float) $val[1] : 0; |
|
1193 | |||
1194 | 1 | if ($i === 0) { |
|
1195 | 1 | $clamp = 360; |
|
1196 | 1 | } elseif ($i < 3) { |
|
1197 | 1 | $clamp = 100; |
|
1198 | } else { |
||
1199 | 1 | $clamp = 1; |
|
1200 | } |
||
1201 | |||
1202 | 1 | $hsl[] = $this->converter->clamp($val, $clamp); |
|
1203 | 1 | $i++; |
|
1204 | } |
||
1205 | |||
1206 | 1 | while (count($hsl) < 4) { |
|
1207 | $hsl[] = 0; |
||
1208 | } |
||
1209 | |||
1210 | 1 | return $this->converter->toRGB($hsl); |
|
1211 | 24 | } elseif ($fname === 'rgb' || $fname === 'rgba') { |
|
1212 | 4 | $components = []; |
|
1213 | 4 | $i = 1; |
|
1214 | 4 | foreach ($rawComponents as $c) { |
|
1215 | 4 | $c = $this->reduce($c); |
|
1216 | 4 | if ($i < 4) { |
|
1217 | 4 | if ($c[0] === "number" && $c[2] === "%") { |
|
1218 | 1 | $components[] = 255 * ($c[1] / 100); |
|
1219 | } else { |
||
1220 | 4 | $components[] = (float) $c[1]; |
|
1221 | } |
||
1222 | 4 | } elseif ($i === 4) { |
|
1223 | 4 | if ($c[0] === "number" && $c[2] === "%") { |
|
1224 | $components[] = 1.0 * ($c[1] / 100); |
||
1225 | } else { |
||
1226 | 4 | $components[] = (float) $c[1]; |
|
1227 | } |
||
1228 | } else { |
||
1229 | break; |
||
1230 | } |
||
1231 | |||
1232 | 4 | $i++; |
|
1233 | } |
||
1234 | 4 | while (count($components) < 3) { |
|
1235 | $components[] = 0; |
||
1236 | } |
||
1237 | 4 | array_unshift($components, 'color'); |
|
1238 | |||
1239 | 4 | return $this->fixColor($components); |
|
1240 | } |
||
1241 | |||
1242 | 23 | return false; |
|
1243 | } |
||
1244 | |||
1245 | /** |
||
1246 | * @param array $value |
||
1247 | * @param bool $forExpression |
||
1248 | * |
||
1249 | * @return array|bool|mixed|null // <!-- dafuq? |
||
1250 | */ |
||
1251 | 48 | public function reduce(array $value, $forExpression = false) |
|
1399 | |||
1400 | /** |
||
1401 | * turn list of length 1 into value type |
||
1402 | * |
||
1403 | * @param array $value |
||
1404 | * |
||
1405 | * @return array |
||
1406 | */ |
||
1407 | 2 | protected function flattenList(array $value) |
|
1415 | |||
1416 | /** |
||
1417 | * evaluate an expression |
||
1418 | * |
||
1419 | * @param array $exp |
||
1420 | * |
||
1421 | * @return array |
||
1422 | */ |
||
1423 | 19 | protected function evaluate($exp) |
|
1477 | |||
1478 | /** |
||
1479 | * @param array $left |
||
1480 | * @param array $right |
||
1481 | * |
||
1482 | * @return array|null |
||
1483 | */ |
||
1484 | protected function stringConcatenate(array $left, array $right) |
||
1505 | |||
1506 | |||
1507 | /** |
||
1508 | * make sure a color's components don't go out of bounds |
||
1509 | * |
||
1510 | * @param array $c |
||
1511 | * |
||
1512 | * @return mixed |
||
1513 | */ |
||
1514 | public function fixColor(array $c) |
||
1527 | |||
1528 | /** |
||
1529 | * @param string $op |
||
1530 | * @param array $lft |
||
1531 | * @param array $rgt |
||
1532 | * |
||
1533 | * @return array|null |
||
1534 | * @throws \LesserPhp\Exception\GeneralException |
||
1535 | */ |
||
1536 | protected function op_number_color($op, array $lft, array $rgt) |
||
1544 | |||
1545 | /** |
||
1546 | * @param string $op |
||
1547 | * @param array $lft |
||
1548 | * @param array $rgt |
||
1549 | * |
||
1550 | * @return array |
||
1551 | * @throws \LesserPhp\Exception\GeneralException |
||
1552 | */ |
||
1553 | protected function op_color_number($op, array $lft, array $rgt) |
||
1565 | |||
1566 | /** |
||
1567 | * @param string $op |
||
1568 | * @param array |
||
1569 | * $left |
||
1570 | * @param array $right |
||
1571 | * |
||
1572 | * @return array |
||
1573 | * @throws \LesserPhp\Exception\GeneralException |
||
1574 | */ |
||
1575 | protected function op_color_color($op, array $left, array $right) |
||
1608 | |||
1609 | /** |
||
1610 | * operator on two numbers |
||
1611 | * |
||
1612 | * @param string $op |
||
1613 | * @param array $left |
||
1614 | * @param array $right |
||
1615 | * |
||
1616 | * @return array |
||
1617 | * @throws \LesserPhp\Exception\GeneralException |
||
1618 | */ |
||
1619 | protected function op_number_number($op, $left, $right) |
||
1657 | |||
1658 | /** |
||
1659 | * @param $type |
||
1660 | * @param null $selectors |
||
1661 | * |
||
1662 | * @return \stdClass |
||
1663 | */ |
||
1664 | protected function makeOutputBlock($type, $selectors = null) |
||
1675 | |||
1676 | /** |
||
1677 | * @param \LesserPhp\NodeEnv $parent |
||
1678 | * @param Block|null $block |
||
1679 | * |
||
1680 | * @return \LesserPhp\NodeEnv |
||
1681 | */ |
||
1682 | protected function pushEnv($parent, Block $block = null) |
||
1693 | |||
1694 | /** |
||
1695 | * pop something off the stack |
||
1696 | * |
||
1697 | * @return \LesserPhp\NodeEnv |
||
1698 | */ |
||
1699 | protected function popEnv() |
||
1706 | |||
1707 | /** |
||
1708 | * set something in the current env |
||
1709 | * |
||
1710 | * @param $name |
||
1711 | * @param $value |
||
1712 | */ |
||
1713 | protected function set($name, $value) |
||
1717 | |||
1718 | /** |
||
1719 | * get the highest occurrence entry for a name |
||
1720 | * |
||
1721 | * @param $name |
||
1722 | * |
||
1723 | * @return array |
||
1724 | * @throws \LesserPhp\Exception\GeneralException |
||
1725 | */ |
||
1726 | protected function get($name) |
||
1781 | |||
1782 | /** |
||
1783 | * inject array of unparsed strings into environment as variables |
||
1784 | * |
||
1785 | * @param string[] $args |
||
1786 | * |
||
1787 | * @throws \LesserPhp\Exception\GeneralException |
||
1788 | */ |
||
1789 | protected function injectVariables(array $args) |
||
1806 | |||
1807 | /** |
||
1808 | * @param string $string |
||
1809 | * @param string $name |
||
1810 | * |
||
1811 | * @return string |
||
1812 | * @throws \LesserPhp\Exception\GeneralException |
||
1813 | */ |
||
1814 | public function compile($string, $name = null) |
||
1842 | |||
1843 | /** |
||
1844 | * @param string $fname |
||
1845 | * @param string $outFname |
||
1846 | * |
||
1847 | * @return int|string |
||
1848 | * @throws \LesserPhp\Exception\GeneralException |
||
1849 | */ |
||
1850 | public function compileFile($fname, $outFname = null) |
||
1874 | |||
1875 | /** |
||
1876 | * Based on explicit input/output files does a full change check on cache before compiling. |
||
1877 | * |
||
1878 | * @param string $in |
||
1879 | * @param string $out |
||
1880 | * @param boolean $force |
||
1881 | * |
||
1882 | * @return string Compiled CSS results |
||
1883 | * @throws GeneralException |
||
1884 | */ |
||
1885 | public function checkedCachedCompile($in, $out, $force = false) |
||
1913 | |||
1914 | /** |
||
1915 | * compile only if changed input has changed or output doesn't exist |
||
1916 | * |
||
1917 | * @param string $in |
||
1918 | * @param string $out |
||
1919 | * |
||
1920 | * @return bool |
||
1921 | * @throws \LesserPhp\Exception\GeneralException |
||
1922 | */ |
||
1923 | public function checkedCompile($in, $out) |
||
1933 | |||
1934 | /** |
||
1935 | * Execute lessphp on a .less file or a lessphp cache structure |
||
1936 | * |
||
1937 | * The lessphp cache structure contains information about a specific |
||
1938 | * less file having been parsed. It can be used as a hint for future |
||
1939 | * calls to determine whether or not a rebuild is required. |
||
1940 | * |
||
1941 | * The cache structure contains two important keys that may be used |
||
1942 | * externally: |
||
1943 | * |
||
1944 | * compiled: The final compiled CSS |
||
1945 | * updated: The time (in seconds) the CSS was last compiled |
||
1946 | * |
||
1947 | * The cache structure is a plain-ol' PHP associative array and can |
||
1948 | * be serialized and unserialized without a hitch. |
||
1949 | * |
||
1950 | * @param mixed $in Input |
||
1951 | * @param bool $force Force rebuild? |
||
1952 | * |
||
1953 | * @return array lessphp cache structure |
||
1954 | * @throws \LesserPhp\Exception\GeneralException |
||
1955 | */ |
||
1956 | public function cachedCompile($in, $force = false) |
||
2000 | |||
2001 | /** |
||
2002 | * parse and compile buffer |
||
2003 | * This is deprecated |
||
2004 | * |
||
2005 | * @param null $str |
||
2006 | * @param null $initialVariables |
||
2007 | * |
||
2008 | * @return int|string |
||
2009 | * @throws \LesserPhp\Exception\GeneralException |
||
2010 | * @deprecated |
||
2011 | */ |
||
2012 | public function parse($str = null, $initialVariables = null) |
||
2034 | |||
2035 | /** |
||
2036 | * @param string $name |
||
2037 | * |
||
2038 | * @return \LesserPhp\Parser |
||
2039 | */ |
||
2040 | protected function makeParser($name) |
||
2047 | |||
2048 | /** |
||
2049 | * @param string $name |
||
2050 | */ |
||
2051 | public function setFormatter($name) |
||
2055 | |||
2056 | public function setFormatterClass($formatter) |
||
2060 | |||
2061 | /** |
||
2062 | * @return \LesserPhp\Formatter\FormatterInterface |
||
2063 | */ |
||
2064 | protected function newFormatter() |
||
2078 | |||
2079 | /** |
||
2080 | * @param bool $preserve |
||
2081 | */ |
||
2082 | public function setPreserveComments($preserve) |
||
2086 | |||
2087 | /** |
||
2088 | * @param string $name |
||
2089 | * @param callable $func |
||
2090 | */ |
||
2091 | public function registerFunction($name, callable $func) |
||
2095 | |||
2096 | /** |
||
2097 | * @param string $name |
||
2098 | */ |
||
2099 | public function unregisterFunction($name) |
||
2103 | |||
2104 | /** |
||
2105 | * @param array $variables |
||
2106 | */ |
||
2107 | public function setVariables(array $variables) |
||
2111 | |||
2112 | /** |
||
2113 | * @param $name |
||
2114 | */ |
||
2115 | public function unsetVariable($name) |
||
2119 | |||
2120 | /** |
||
2121 | * @param string[] $dirs |
||
2122 | */ |
||
2123 | public function setImportDirs(array $dirs) |
||
2127 | |||
2128 | /** |
||
2129 | * @param string $dir |
||
2130 | */ |
||
2131 | public function addImportDir($dir) |
||
2135 | |||
2136 | /** |
||
2137 | * @return string[] |
||
2138 | */ |
||
2139 | public function getImportDirs() |
||
2143 | |||
2144 | /** |
||
2145 | * @param string $file |
||
2146 | */ |
||
2147 | public function addParsedFile($file) |
||
2151 | |||
2152 | /** |
||
2153 | * Uses the current value of $this->count to show line and line number |
||
2154 | * |
||
2155 | * @param string $msg |
||
2156 | * |
||
2157 | * @throws GeneralException |
||
2158 | */ |
||
2159 | public function throwError($msg = null) |
||
2166 | |||
2167 | /** |
||
2168 | * compile file $in to file $out if $in is newer than $out |
||
2169 | * returns true when it compiles, false otherwise |
||
2170 | * |
||
2171 | * @param $in |
||
2172 | * @param $out |
||
2173 | * @param \LesserPhp\Compiler|null $less |
||
2174 | * |
||
2175 | * @return bool |
||
2176 | * @throws \LesserPhp\Exception\GeneralException |
||
2177 | */ |
||
2178 | public static function ccompile($in, $out, Compiler $less = null) |
||
2186 | |||
2187 | /** |
||
2188 | * @param $in |
||
2189 | * @param bool $force |
||
2190 | * @param \LesserPhp\Compiler|null $less |
||
2191 | * |
||
2192 | * @return array |
||
2193 | * @throws \LesserPhp\Exception\GeneralException |
||
2194 | */ |
||
2195 | public static function cexecute($in, $force = false, Compiler $less = null) |
||
2203 | |||
2204 | /** |
||
2205 | * prefix of abstract properties |
||
2206 | * |
||
2207 | * @return string |
||
2208 | */ |
||
2209 | public function getVPrefix() |
||
2213 | |||
2214 | /** |
||
2215 | * prefix of abstract blocks |
||
2216 | * |
||
2217 | * @return string |
||
2218 | */ |
||
2219 | public function getMPrefix() |
||
2223 | |||
2224 | /** |
||
2225 | * @return string |
||
2226 | */ |
||
2227 | public function getParentSelector() |
||
2231 | |||
2232 | /** |
||
2233 | * @param int $numberPresicion |
||
2234 | */ |
||
2235 | protected function setNumberPrecision($numberPresicion = null) |
||
2239 | |||
2240 | /** |
||
2241 | * @return \LesserPhp\Library\Coerce |
||
2242 | */ |
||
2243 | protected function getCoerce() |
||
2247 | |||
2248 | public function setImportDisabled() |
||
2252 | |||
2253 | /** |
||
2254 | * @return bool |
||
2255 | */ |
||
2256 | public function isImportDisabled() |
||
2260 | } |
||
2261 |