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() |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @param array $items |
||
| 182 | * @param $delim |
||
| 183 | * |
||
| 184 | * @return array |
||
| 185 | */ |
||
| 186 | 48 | public static function compressList(array $items, $delim) |
|
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $what |
||
| 197 | * |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | 36 | public static function pregQuote($what) |
|
| 204 | |||
| 205 | /** |
||
| 206 | * @param array $importPath |
||
| 207 | * @param Block $parentBlock |
||
| 208 | * @param \stdClass $out |
||
| 209 | * |
||
| 210 | * @return array|false |
||
| 211 | * @throws \LesserPhp\Exception\GeneralException |
||
| 212 | */ |
||
| 213 | 3 | protected function tryImport(array $importPath, Block $parentBlock, \stdClass $out) |
|
| 278 | |||
| 279 | /** |
||
| 280 | * @param Property[] $props |
||
| 281 | * @param Block $block |
||
| 282 | * @param \stdClass $out |
||
| 283 | * @param string $importDir |
||
| 284 | */ |
||
| 285 | 2 | protected function compileImportedProps(array $props, Block $block, \stdClass $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, \stdClass $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 Property[] $props |
||
| 488 | * @param bool $split |
||
| 489 | * |
||
| 490 | * @return Property[] |
||
| 491 | */ |
||
| 492 | 49 | protected function sortProps(array $props, $split = false) |
|
| 541 | |||
| 542 | 3 | /** |
|
| 543 | * @param array $queries |
||
| 544 | 3 | * |
|
| 545 | 3 | * @return string |
|
| 546 | 3 | */ |
|
| 547 | 3 | protected function compileMediaQuery(array $queries) |
|
| 584 | |||
| 585 | /** |
||
| 586 | 3 | * @param \LesserPhp\NodeEnv $env |
|
| 587 | * @param array $childQueries |
||
| 588 | 3 | * |
|
| 589 | 3 | * @return array |
|
| 590 | */ |
||
| 591 | 3 | protected function multiplyMedia(NodeEnv $env = null, array $childQueries = null) |
|
| 618 | |||
| 619 | /** |
||
| 620 | 46 | * @param $tag |
|
| 621 | * @param $replace |
||
| 622 | 46 | * |
|
| 623 | 46 | * @return int |
|
| 624 | 46 | */ |
|
| 625 | 46 | protected function expandParentSelectors(&$tag, $replace) |
|
| 637 | |||
| 638 | 46 | /** |
|
| 639 | 46 | * @return array|null |
|
| 640 | 46 | */ |
|
| 641 | 46 | protected function findClosestSelectors() |
|
| 655 | |||
| 656 | |||
| 657 | /** |
||
| 658 | * multiply $selectors against the nearest selectors in env |
||
| 659 | 46 | * |
|
| 660 | * @param array $selectors |
||
| 661 | * |
||
| 662 | * @return array |
||
| 663 | 46 | */ |
|
| 664 | 46 | protected function multiplySelectors(array $selectors) |
|
| 694 | |||
| 695 | /** |
||
| 696 | * reduces selector expressions |
||
| 697 | * |
||
| 698 | 46 | * @param array $selectors |
|
| 699 | * |
||
| 700 | 46 | * @return array |
|
| 701 | * @throws \LesserPhp\Exception\GeneralException |
||
| 702 | 46 | */ |
|
| 703 | 46 | protected function compileSelectors(array $selectors) |
|
| 718 | |||
| 719 | /** |
||
| 720 | 4 | * @param $left |
|
| 721 | * @param $right |
||
| 722 | 4 | * |
|
| 723 | * @return bool |
||
| 724 | */ |
||
| 725 | protected function equals($left, $right) |
||
| 729 | |||
| 730 | /** |
||
| 731 | * @param $block |
||
| 732 | 21 | * @param $orderedArgs |
|
| 733 | * @param $keywordArgs |
||
| 734 | * |
||
| 735 | * @return bool |
||
| 736 | 21 | */ |
|
| 737 | 5 | protected function patternMatch($block, $orderedArgs, $keywordArgs) |
|
| 825 | |||
| 826 | /** |
||
| 827 | * @param array $blocks |
||
| 828 | * @param $orderedArgs |
||
| 829 | 21 | * @param $keywordArgs |
|
| 830 | * @param array $skip |
||
| 831 | 21 | * |
|
| 832 | 21 | * @return array|null |
|
| 833 | */ |
||
| 834 | 21 | protected function patternMatchAll(array $blocks, $orderedArgs, $keywordArgs, array $skip = []) |
|
| 850 | |||
| 851 | /** |
||
| 852 | * attempt to find blocks matched by path and args |
||
| 853 | * |
||
| 854 | * @param $searchIn |
||
| 855 | * @param array $path |
||
| 856 | * @param $orderedArgs |
||
| 857 | 22 | * @param $keywordArgs |
|
| 858 | * @param array $seen |
||
| 859 | 22 | * |
|
| 860 | 5 | * @return array|null |
|
| 861 | */ |
||
| 862 | 22 | protected function findBlocks($searchIn, array $path, $orderedArgs, $keywordArgs, array $seen = []) |
|
| 910 | |||
| 911 | /** |
||
| 912 | * sets all argument names in $args to either the default value |
||
| 913 | * or the one passed in through $values |
||
| 914 | * |
||
| 915 | * @param array $args |
||
| 916 | 16 | * @param $orderedValues |
|
| 917 | * @param $keywordValues |
||
| 918 | 16 | * |
|
| 919 | * @throws \LesserPhp\Exception\GeneralException |
||
| 920 | 16 | */ |
|
| 921 | 16 | protected function zipSetArgs(array $args, $orderedValues, $keywordValues) |
|
| 922 | 14 | { |
|
| 923 | 14 | $assignedValues = []; |
|
| 924 | |||
| 925 | 2 | $i = 0; |
|
| 926 | 14 | foreach ($args as $a) { |
|
| 927 | if ($a[0] === "arg") { |
||
| 928 | 13 | if (isset($keywordValues[$a[1]])) { |
|
| 929 | 13 | // has keyword arg |
|
| 930 | 6 | $value = $keywordValues[$a[1]]; |
|
| 931 | } elseif (isset($orderedValues[$i])) { |
||
| 932 | 6 | // has ordered arg |
|
| 933 | $value = $orderedValues[$i]; |
||
| 934 | $i++; |
||
| 935 | } elseif (isset($a[2])) { |
||
| 936 | // has default value |
||
| 937 | 14 | $value = $a[2]; |
|
| 938 | 14 | } else { |
|
| 939 | 14 | throw new GeneralException('Failed to assign arg ' . $a[1]); |
|
| 940 | } |
||
| 941 | |||
| 942 | 14 | $value = $this->reduce($value); |
|
| 943 | $this->set($a[1], $value); |
||
| 944 | $assignedValues[] = $value; |
||
| 945 | } else { |
||
| 946 | // a lit |
||
| 947 | 16 | $i++; |
|
| 948 | 16 | } |
|
| 949 | 2 | } |
|
| 950 | 2 | ||
| 951 | // check for a rest |
||
| 952 | $last = end($args); |
||
| 953 | if ($last !== false && $last[0] === "rest") { |
||
| 954 | 16 | $rest = array_slice($orderedValues, count($args) - 1); |
|
| 955 | 16 | $this->set($last[1], $this->reduce(["list", " ", $rest])); |
|
| 956 | } |
||
| 957 | |||
| 958 | // wow is this the only true use of PHP's + operator for arrays? |
||
| 959 | $this->env->setArguments($assignedValues + $orderedValues); |
||
| 960 | } |
||
| 961 | |||
| 962 | /** |
||
| 963 | * compile a prop and update $lines or $blocks appropriately |
||
| 964 | * |
||
| 965 | * @param Property $prop |
||
| 966 | 49 | * @param Block $block |
|
| 967 | * @param \stdClass $out |
||
| 968 | * |
||
| 969 | 49 | * @throws \LesserPhp\Exception\GeneralException |
|
| 970 | */ |
||
| 971 | 49 | protected function compileProp(Property $prop, Block $block, \stdClass $out) |
|
| 1110 | 38 | ||
| 1111 | |||
| 1112 | /** |
||
| 1113 | * Compiles a primitive value into a CSS property value. |
||
| 1114 | * |
||
| 1115 | * Values in lessphp are typed by being wrapped in arrays, their format is |
||
| 1116 | * typically: |
||
| 1117 | * |
||
| 1118 | * array(type, contents [, additional_contents]*) |
||
| 1119 | * |
||
| 1120 | * The input is expected to be reduced. This function will not work on |
||
| 1121 | * things like expressions and variables. |
||
| 1122 | * |
||
| 1123 | * @param array $value |
||
| 1124 | * @param array $options |
||
| 1125 | * |
||
| 1126 | * @return string |
||
| 1127 | * @throws GeneralException |
||
| 1128 | */ |
||
| 1129 | public function compileValue(array $value, array $options = []) |
||
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Helper function to get arguments for color manipulation functions. |
||
| 1151 | * takes a list that contains a color like thing and a percentage |
||
| 1152 | * |
||
| 1153 | * @param array $args |
||
| 1154 | * |
||
| 1155 | * @return array |
||
| 1156 | */ |
||
| 1157 | public function colorArgs(array $args) |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Convert the rgb, rgba, hsl color literals of function type |
||
| 1171 | * as returned by the parser into values of color type. |
||
| 1172 | * |
||
| 1173 | * @param array $func |
||
| 1174 | * |
||
| 1175 | * @return bool|mixed |
||
| 1176 | */ |
||
| 1177 | protected function funcToColor(array $func) |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * @param array $value |
||
| 1246 | * @param bool $forExpression |
||
| 1247 | * |
||
| 1248 | * @return array|bool|mixed|null // <!-- dafuq? |
||
| 1249 | */ |
||
| 1250 | public function reduce(array $value, $forExpression = false) |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * turn list of length 1 into value type |
||
| 1401 | * |
||
| 1402 | * @param array $value |
||
| 1403 | * |
||
| 1404 | * @return array |
||
| 1405 | */ |
||
| 1406 | protected function flattenList(array $value) |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * evaluate an expression |
||
| 1417 | * |
||
| 1418 | * @param array $exp |
||
| 1419 | * |
||
| 1420 | * @return array |
||
| 1421 | */ |
||
| 1422 | protected function evaluate($exp) |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * @param array $left |
||
| 1479 | * @param array $right |
||
| 1480 | * |
||
| 1481 | * @return array|null |
||
| 1482 | */ |
||
| 1483 | protected function stringConcatenate(array $left, array $right) |
||
| 1504 | |||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * make sure a color's components don't go out of bounds |
||
| 1508 | * |
||
| 1509 | * @param array $c |
||
| 1510 | * |
||
| 1511 | * @return mixed |
||
| 1512 | */ |
||
| 1513 | public function fixColor(array $c) |
||
| 1526 | |||
| 1527 | /** |
||
| 1528 | * @param string $op |
||
| 1529 | * @param array $lft |
||
| 1530 | * @param array $rgt |
||
| 1531 | * |
||
| 1532 | * @return array|null |
||
| 1533 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1534 | */ |
||
| 1535 | protected function op_number_color($op, array $lft, array $rgt) |
||
| 1543 | |||
| 1544 | /** |
||
| 1545 | * @param string $op |
||
| 1546 | * @param array $lft |
||
| 1547 | * @param array $rgt |
||
| 1548 | * |
||
| 1549 | * @return array |
||
| 1550 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1551 | */ |
||
| 1552 | protected function op_color_number($op, array $lft, array $rgt) |
||
| 1564 | |||
| 1565 | /** |
||
| 1566 | * @param string $op |
||
| 1567 | * @param array |
||
| 1568 | * $left |
||
| 1569 | * @param array $right |
||
| 1570 | * |
||
| 1571 | * @return array |
||
| 1572 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1573 | */ |
||
| 1574 | protected function op_color_color($op, array $left, array $right) |
||
| 1607 | |||
| 1608 | /** |
||
| 1609 | * operator on two numbers |
||
| 1610 | * |
||
| 1611 | * @param string $op |
||
| 1612 | * @param array $left |
||
| 1613 | * @param array $right |
||
| 1614 | * |
||
| 1615 | * @return array |
||
| 1616 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1617 | */ |
||
| 1618 | protected function op_number_number($op, $left, $right) |
||
| 1656 | |||
| 1657 | /** |
||
| 1658 | * @param $type |
||
| 1659 | * @param null $selectors |
||
| 1660 | * |
||
| 1661 | * @return \stdClass |
||
| 1662 | */ |
||
| 1663 | protected function makeOutputBlock($type, $selectors = null) |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * @param \LesserPhp\NodeEnv $parent |
||
| 1677 | * @param Block|null $block |
||
| 1678 | * |
||
| 1679 | * @return \LesserPhp\NodeEnv |
||
| 1680 | */ |
||
| 1681 | protected function pushEnv($parent, Block $block = null) |
||
| 1692 | |||
| 1693 | /** |
||
| 1694 | * pop something off the stack |
||
| 1695 | * |
||
| 1696 | * @return \LesserPhp\NodeEnv |
||
| 1697 | */ |
||
| 1698 | protected function popEnv() |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * set something in the current env |
||
| 1708 | * |
||
| 1709 | * @param $name |
||
| 1710 | * @param $value |
||
| 1711 | */ |
||
| 1712 | protected function set($name, $value) |
||
| 1716 | 27 | ||
| 1717 | /** |
||
| 1718 | * get the highest occurrence entry for a name |
||
| 1719 | * |
||
| 1720 | * @param $name |
||
| 1721 | * |
||
| 1722 | * @return array |
||
| 1723 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1724 | */ |
||
| 1725 | protected function get($name) |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * inject array of unparsed strings into environment as variables |
||
| 1783 | * |
||
| 1784 | * @param string[] $args |
||
| 1785 | * |
||
| 1786 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1787 | */ |
||
| 1788 | protected function injectVariables(array $args) |
||
| 1805 | 1 | ||
| 1806 | /** |
||
| 1807 | * @param string $string |
||
| 1808 | * @param string $name |
||
| 1809 | * |
||
| 1810 | * @return string |
||
| 1811 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1812 | */ |
||
| 1813 | public function compile($string, $name = null) |
||
| 1841 | |||
| 1842 | /** |
||
| 1843 | * @param string $fname |
||
| 1844 | * @param string $outFname |
||
| 1845 | * |
||
| 1846 | * @return int|string |
||
| 1847 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1848 | */ |
||
| 1849 | public function compileFile($fname, $outFname = null) |
||
| 1873 | |||
| 1874 | /** |
||
| 1875 | * Based on explicit input/output files does a full change check on cache before compiling. |
||
| 1876 | * |
||
| 1877 | * @param string $in |
||
| 1878 | * @param string $out |
||
| 1879 | * @param boolean $force |
||
| 1880 | * |
||
| 1881 | * @return string Compiled CSS results |
||
| 1882 | * @throws GeneralException |
||
| 1883 | */ |
||
| 1884 | public function checkedCachedCompile($in, $out, $force = false) |
||
| 1912 | |||
| 1913 | /** |
||
| 1914 | * compile only if changed input has changed or output doesn't exist |
||
| 1915 | * |
||
| 1916 | * @param string $in |
||
| 1917 | * @param string $out |
||
| 1918 | * |
||
| 1919 | * @return bool |
||
| 1920 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1921 | */ |
||
| 1922 | public function checkedCompile($in, $out) |
||
| 1932 | |||
| 1933 | /** |
||
| 1934 | * Execute lessphp on a .less file or a lessphp cache structure |
||
| 1935 | * |
||
| 1936 | * The lessphp cache structure contains information about a specific |
||
| 1937 | * less file having been parsed. It can be used as a hint for future |
||
| 1938 | * calls to determine whether or not a rebuild is required. |
||
| 1939 | * |
||
| 1940 | * The cache structure contains two important keys that may be used |
||
| 1941 | * externally: |
||
| 1942 | * |
||
| 1943 | * compiled: The final compiled CSS |
||
| 1944 | * updated: The time (in seconds) the CSS was last compiled |
||
| 1945 | * |
||
| 1946 | * The cache structure is a plain-ol' PHP associative array and can |
||
| 1947 | * be serialized and unserialized without a hitch. |
||
| 1948 | * |
||
| 1949 | * @param mixed $in Input |
||
| 1950 | * @param bool $force Force rebuild? |
||
| 1951 | * |
||
| 1952 | * @return array lessphp cache structure |
||
| 1953 | * @throws \LesserPhp\Exception\GeneralException |
||
| 1954 | */ |
||
| 1955 | public function cachedCompile($in, $force = false) |
||
| 1999 | |||
| 2000 | /** |
||
| 2001 | * parse and compile buffer |
||
| 2002 | * This is deprecated |
||
| 2003 | * |
||
| 2004 | * @param null $str |
||
| 2005 | * @param null $initialVariables |
||
| 2006 | * |
||
| 2007 | * @return int|string |
||
| 2008 | * @throws \LesserPhp\Exception\GeneralException |
||
| 2009 | * @deprecated |
||
| 2010 | */ |
||
| 2011 | public function parse($str = null, $initialVariables = null) |
||
| 2033 | |||
| 2034 | /** |
||
| 2035 | * @param string $name |
||
| 2036 | * |
||
| 2037 | * @return \LesserPhp\Parser |
||
| 2038 | */ |
||
| 2039 | protected function makeParser($name) |
||
| 2046 | |||
| 2047 | /** |
||
| 2048 | * @param string $name |
||
| 2049 | */ |
||
| 2050 | public function setFormatter($name) |
||
| 2054 | 1 | ||
| 2055 | public function setFormatterClass($formatter) |
||
| 2059 | 14 | ||
| 2060 | /** |
||
| 2061 | * @return \LesserPhp\Formatter\FormatterInterface |
||
| 2062 | */ |
||
| 2063 | protected function newFormatter() |
||
| 2077 | |||
| 2078 | /** |
||
| 2079 | * @param bool $preserve |
||
| 2080 | */ |
||
| 2081 | public function setPreserveComments($preserve) |
||
| 2085 | 1 | ||
| 2086 | /** |
||
| 2087 | * @param string $name |
||
| 2088 | * @param callable $func |
||
| 2089 | */ |
||
| 2090 | public function registerFunction($name, callable $func) |
||
| 2094 | 1 | ||
| 2095 | /** |
||
| 2096 | * @param string $name |
||
| 2097 | */ |
||
| 2098 | public function unregisterFunction($name) |
||
| 2102 | 1 | ||
| 2103 | /** |
||
| 2104 | * @param array $variables |
||
| 2105 | */ |
||
| 2106 | public function setVariables(array $variables) |
||
| 2110 | 1 | ||
| 2111 | /** |
||
| 2112 | * @param $name |
||
| 2113 | */ |
||
| 2114 | public function unsetVariable($name) |
||
| 2118 | |||
| 2119 | /** |
||
| 2120 | * @param string[] $dirs |
||
| 2121 | */ |
||
| 2122 | public function setImportDirs(array $dirs) |
||
| 2126 | 38 | ||
| 2127 | /** |
||
| 2128 | * @param string $dir |
||
| 2129 | */ |
||
| 2130 | public function addImportDir($dir) |
||
| 2134 | |||
| 2135 | /** |
||
| 2136 | * @return string[] |
||
| 2137 | */ |
||
| 2138 | public function getImportDirs() |
||
| 2142 | |||
| 2143 | /** |
||
| 2144 | * @param string $file |
||
| 2145 | */ |
||
| 2146 | public function addParsedFile($file) |
||
| 2150 | 2 | ||
| 2151 | /** |
||
| 2152 | * Uses the current value of $this->count to show line and line number |
||
| 2153 | * |
||
| 2154 | * @param string $msg |
||
| 2155 | * |
||
| 2156 | * @throws GeneralException |
||
| 2157 | */ |
||
| 2158 | public function throwError($msg = null) |
||
| 2165 | |||
| 2166 | /** |
||
| 2167 | * compile file $in to file $out if $in is newer than $out |
||
| 2168 | * returns true when it compiles, false otherwise |
||
| 2169 | * |
||
| 2170 | * @param $in |
||
| 2171 | * @param $out |
||
| 2172 | * @param \LesserPhp\Compiler|null $less |
||
| 2173 | * |
||
| 2174 | * @return bool |
||
| 2175 | * @throws \LesserPhp\Exception\GeneralException |
||
| 2176 | */ |
||
| 2177 | public static function ccompile($in, $out, Compiler $less = null) |
||
| 2185 | |||
| 2186 | /** |
||
| 2187 | * @param $in |
||
| 2188 | * @param bool $force |
||
| 2189 | * @param \LesserPhp\Compiler|null $less |
||
| 2190 | * |
||
| 2191 | * @return array |
||
| 2192 | * @throws \LesserPhp\Exception\GeneralException |
||
| 2193 | */ |
||
| 2194 | public static function cexecute($in, $force = false, Compiler $less = null) |
||
| 2202 | |||
| 2203 | /** |
||
| 2204 | * prefix of abstract properties |
||
| 2205 | * |
||
| 2206 | * @return string |
||
| 2207 | */ |
||
| 2208 | public function getVPrefix() |
||
| 2212 | |||
| 2213 | /** |
||
| 2214 | * prefix of abstract blocks |
||
| 2215 | * |
||
| 2216 | * @return string |
||
| 2217 | */ |
||
| 2218 | public function getMPrefix() |
||
| 2222 | |||
| 2223 | /** |
||
| 2224 | * @return string |
||
| 2225 | */ |
||
| 2226 | public function getParentSelector() |
||
| 2230 | |||
| 2231 | /** |
||
| 2232 | * @param int $numberPresicion |
||
| 2233 | */ |
||
| 2234 | protected function setNumberPrecision($numberPresicion = null) |
||
| 2238 | |||
| 2239 | /** |
||
| 2240 | * @return \LesserPhp\Library\Coerce |
||
| 2241 | */ |
||
| 2242 | protected function getCoerce() |
||
| 2246 | |||
| 2247 | public function setImportDisabled() |
||
| 2251 | 1 | ||
| 2252 | /** |
||
| 2253 | * @return bool |
||
| 2254 | */ |
||
| 2255 | public function isImportDisabled() |
||
| 2259 | } |
||
| 2260 |