Skip to content

Commit a7c00b5

Browse files
author
Dan Schaefer
committed
I did not commit the changes in the last commit
Fixed Bug: The CSSSelector->aSelector is not being set correctly Added CSSParser->append to allow you to add multiple strings before parsing
1 parent 07bb6dc commit a7c00b5

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

CSSParser.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,34 @@ private function consumeUntil($sEnd) {
403403
private function inputLeft() {
404404
return mb_substr($this->sText, $this->iCurrentPosition, -1, $this->sCharset);
405405
}
406+
407+
/**
408+
* Appends a string to the sText CSS string.
409+
* This allows you to add multiple strings before parsing
410+
* @param string $sText
411+
*
412+
* @author dschaefer
413+
* @since 12/30/2010
414+
*
415+
* @example $CSSParser = new CSSParser(file_get_contents("css/default.css"));
416+
* $CSSParser->append(file_get_contents("css/custom.css"));
417+
*/
418+
public function append($sText, $sCharest=NULL){
419+
if(!isset($sCharest)){ $sCharest = $this->sCharset; }
420+
$this->sText .= $sText;
421+
$this->setCharset($sCharest);
422+
}
423+
424+
/**
425+
* Simply returns the private $sText variable
426+
* @return string
427+
*
428+
* @author dschaefer
429+
* @since 12/30/2010
430+
*/
431+
public function getContents(){
432+
return $this->sText;
433+
}
406434
}
407435

408436
abstract class CSSList {
@@ -472,18 +500,27 @@ protected function allValues($oElement, &$aResult, $sSearchString = null) {
472500
* are multiple selectors in the rule set, then each one will
473501
* have their own array element.
474502
*
503+
* Fixed Bug: The CSSSelector->aSelector is not being set correctly
504+
*
475505
* @param array $aResult
476506
*
477-
* @author dschaefer 12/23/2010
507+
* @author dschaefer
508+
* @since 12/23/2010
478509
*/
479510
protected function allUniqueRuleSets(&$aResult){
480-
foreach($this->aContents as $mContent) {
511+
foreach($this->aContents as $mContent){
481512
if($mContent instanceof CSSRuleSet) {
482-
foreach($mContent->getSelector() as $aSelector){
483-
$aResult[$aSelector] = $mContent;
513+
foreach($mContent->getSelector() as $sSelector){
514+
if(!isset($aResult[$sSelector])){
515+
$aResult[$sSelector] = new CSSSelector();
516+
}
517+
$aResult[$sSelector]->setSelector($sSelector);
518+
foreach($mContent->getRules() as $oRule){
519+
$aResult[$sSelector]->addRule($oRule);
520+
}
484521
}
485522
} else if($mContent instanceof CSSList) {
486-
$mContent->allRuleSets($aResult);
523+
$mContent->allUniqueRuleSets($aResult);
487524
}
488525
}
489526
}

0 commit comments

Comments
 (0)