Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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  	 	 if (is_numeric($sSpecificitySearch) || is_numeric($sSpecificitySearch[0])) {
  76  	 	 	 $sSpecificitySearch = "== $sSpecificitySearch";
  77  	 	 }
  78  	 	 $aResult = array();
  79  	 	 $this->allSelectors($aResult, $sSpecificitySearch);
  80  	 	 return $aResult;
  81  	 }
  82  
  83  	 /**
  84  	  * Expands all shorthand properties to their long value
  85  	  */
  86  	public function expandShorthands() {
  87  	 	 foreach ($this->getAllDeclarationBlocks() as $oDeclaration) {
  88  	 	 	 $oDeclaration->expandShorthands();
  89  	 	 }
  90  	 }
  91  
  92  	 /**
  93  	  * Create shorthands properties whenever possible
  94  	  */
  95  	public function createShorthands() {
  96  	 	 foreach ($this->getAllDeclarationBlocks() as $oDeclaration) {
  97  	 	 	 $oDeclaration->createShorthands();
  98  	 	 }
  99  	 }
 100  
 101  	 // Override render() to make format argument optional
 102  	public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat = null) {
 103  	 	 if($oOutputFormat === null) {
 104  	 	 	 $oOutputFormat = new \Sabberworm\CSS\OutputFormat();
 105  	 	 }
 106  	 	 return parent::render($oOutputFormat);
 107  	 }
 108  
 109  	public function isRootList() {
 110  	 	 return true;
 111  	 }
 112  
 113  }