Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  
   3  namespace Sabberworm\CSS\CSSList;
   4  
   5  use Sabberworm\CSS\RuleSet\DeclarationBlock;
   6  use Sabberworm\CSS\RuleSet\RuleSet;
   7  use Sabberworm\CSS\Property\Selector;
   8  use Sabberworm\CSS\Rule\Rule;
   9  use Sabberworm\CSS\Value\ValueList;
  10  use Sabberworm\CSS\Value\CSSFunction;
  11  
  12  /**
  13   * A CSSBlockList is a CSSList whose DeclarationBlocks are guaranteed to contain valid declaration blocks or at-rules.
  14   * Most CSSLists conform to this category but some at-rules (such as @keyframes) do not.
  15   */
  16  abstract class CSSBlockList extends CSSList {
  17  	public function __construct($iLineNo = 0) {
  18  	 	 parent::__construct($iLineNo);
  19  	 }
  20  
  21  	protected function allDeclarationBlocks(&$aResult) {
  22  	 	 foreach ($this->aContents as $mContent) {
  23  	 	 	 if ($mContent instanceof DeclarationBlock) {
  24  	 	 	 	 $aResult[] = $mContent;
  25  	 	 	 } else if ($mContent instanceof CSSBlockList) {
  26  	 	 	 	 $mContent->allDeclarationBlocks($aResult);
  27  	 	 	 }
  28  	 	 }
  29  	 }
  30  
  31  	protected function allRuleSets(&$aResult) {
  32  	 	 foreach ($this->aContents as $mContent) {
  33  	 	 	 if ($mContent instanceof RuleSet) {
  34  	 	 	 	 $aResult[] = $mContent;
  35  	 	 	 } else if ($mContent instanceof CSSBlockList) {
  36  	 	 	 	 $mContent->allRuleSets($aResult);
  37  	 	 	 }
  38  	 	 }
  39  	 }
  40  
  41  	protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) {
  42  	 	 if ($oElement instanceof CSSBlockList) {
  43  	 	 	 foreach ($oElement->getContents() as $oContent) {
  44  	 	 	 	 $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments);
  45  	 	 	 }
  46  	 	 } else if ($oElement instanceof RuleSet) {
  47  	 	 	 foreach ($oElement->getRules($sSearchString) as $oRule) {
  48  	 	 	 	 $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments);
  49  	 	 	 }
  50  	 	 } else if ($oElement instanceof Rule) {
  51  	 	 	 $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments);
  52  	 	 } else if ($oElement instanceof ValueList) {
  53  	 	 	 if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) {
  54  	 	 	 	 foreach ($oElement->getListComponents() as $mComponent) {
  55  	 	 	 	 	 $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments);
  56  	 	 	 	 }
  57  	 	 	 }
  58  	 	 } else {
  59  	 	 	 //Non-List Value or CSSString (CSS identifier)
  60  	 	 	 $aResult[] = $oElement;
  61  	 	 }
  62  	 }
  63  
  64  	protected function allSelectors(&$aResult, $sSpecificitySearch = null) {
  65  	 	 $aDeclarationBlocks = array();
  66  	 	 $this->allDeclarationBlocks($aDeclarationBlocks);
  67  	 	 foreach ($aDeclarationBlocks as $oBlock) {
  68  	 	 	 foreach ($oBlock->getSelectors() as $oSelector) {
  69  	 	 	 	 if ($sSpecificitySearch === null) {
  70  	 	 	 	 	 $aResult[] = $oSelector;
  71  	 	 	 	 } else {
  72  	 	 	 	 	 $sComparison = "\$bRes = {$oSelector->getSpecificity()} $sSpecificitySearch;";
  73  	 	 	 	 	 eval($sComparison);
  74  	 	 	 	 	 if ($bRes) {
  75  	 	 	 	 	 	 $aResult[] = $oSelector;
  76  	 	 	 	 	 }
  77  	 	 	 	 }
  78  	 	 	 }
  79  	 	 }
  80  	 }
  81  
  82  }