Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 3 namespace Sabberworm\CSS\CSSList; 4 5 use Sabberworm\CSS\Parsing\ParserState; 6 7 /** 8 * The root CSSList of a parsed file. Contains all top-level css contents, mostly declaration blocks, but also any @-rules encountered. 9 */ 10 class Document extends CSSBlockList { 11 /** 12 * Document constructor. 13 * @param int $iLineNo 14 */ 15 public function __construct($iLineNo = 0) { 16 parent::__construct($iLineNo); 17 } 18 19 public static function parse(ParserState $oParserState) { 20 $oDocument = new Document($oParserState->currentLine()); 21 CSSList::parseList($oParserState, $oDocument); 22 return $oDocument; 23 } 24 25 /** 26 * Gets all DeclarationBlock objects recursively. 27 */ 28 public function getAllDeclarationBlocks() { 29 $aResult = array(); 30 $this->allDeclarationBlocks($aResult); 31 return $aResult; 32 } 33 34 /** 35 * @deprecated use getAllDeclarationBlocks() 36 */ 37 public function getAllSelectors() { 38 return $this->getAllDeclarationBlocks(); 39 } 40 41 /** 42 * Returns all RuleSet objects found recursively in the tree. 43 */ 44 public function getAllRuleSets() { 45 $aResult = array(); 46 $this->allRuleSets($aResult); 47 return $aResult; 48 } 49 50 /** 51 * Returns all Value objects found recursively in the tree. 52 * @param (object|string) $mElement the CSSList or RuleSet to start the search from (defaults to the whole document). If a string is given, it is used as rule name filter (@see{RuleSet->getRules()}). 53 * @param (bool) $bSearchInFunctionArguments whether to also return Value objects used as Function arguments. 54 */ 55 public function getAllValues($mElement = null, $bSearchInFunctionArguments = false) { 56 $sSearchString = null; 57 if ($mElement === null) { 58 $mElement = $this; 59 } else if (is_string($mElement)) { 60 $sSearchString = $mElement; 61 $mElement = $this; 62 } 63 $aResult = array(); 64 $this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments); 65 return $aResult; 66 } 67 68 /** 69 * Returns all Selector objects found recursively in the tree. 70 * Note that this does not yield the full DeclarationBlock that the selector belongs to (and, currently, there is no way to get to that). 71 * @param $sSpecificitySearch An optional filter by specificity. May contain a comparison operator and a number or just a number (defaults to "=="). 72 * @example getSelectorsBySpecificity('>= 100') 73 */ 74 public function getSelectorsBySpecificity($sSpecificitySearch = null) { 75 $aResult = array(); 76 $this->allSelectors($aResult, $sSpecificitySearch); 77 return $aResult; 78 } 79 80 /** 81 * Expands all shorthand properties to their long value 82 */ 83 public function expandShorthands() { 84 foreach ($this->getAllDeclarationBlocks() as $oDeclaration) { 85 $oDeclaration->expandShorthands(); 86 } 87 } 88 89 /** 90 * Create shorthands properties whenever possible 91 */ 92 public function createShorthands() { 93 foreach ($this->getAllDeclarationBlocks() as $oDeclaration) { 94 $oDeclaration->createShorthands(); 95 } 96 } 97 98 // Override render() to make format argument optional 99 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat = null) { 100 if($oOutputFormat === null) { 101 $oOutputFormat = new \Sabberworm\CSS\OutputFormat(); 102 } 103 return parent::render($oOutputFormat); 104 } 105 106 public function isRootList() { 107 return true; 108 } 109 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body