/**
  * 
  **/
 public function testMergeDeclarations()
 {
     $sFile = __DIR__ . '/files/merge.css';
     $oParser = new CSSParser();
     $oDoc = $oParser->parseString(file_get_contents($sFile));
     $aDeclarations = $oDoc->getAllDeclarationBlocks();
     $oMerged = CSSDocument::mergeDeclarations($aDeclarations);
     $sExpected = "{color: rgb(255,0,0);background: rgb(0,255,255) none repeat-x 0% 0% scroll;margin: 0 0 1em;}";
     $this->assertEquals(trim($oMerged->__toString()), $sExpected);
 }
示例#2
0
 /**
  * Add CSS rules for this element to the given document
  *
  * @param CSSDocument $css
  * @param string $selector
  */
 public function toCSS(CSSDocument $css, $selector)
 {
     if ($this->url) {
         $size = 'contain';
         $repeat = 'no-repeat';
         $positionHor = 'center';
         $positionVer = 'center';
         switch ($this->style) {
             case self::TYPE_STRETCH:
                 $size = '100% 100%';
                 break;
             case self::TYPE_TILE:
                 $repeat = 'repeat';
                 break;
             case self::TYPE_CENTER:
                 if (is_array($this->size)) {
                     $size = "{$this->size['width']}px {$this->size['height']}px";
                 } else {
                     $size = 'auto';
                 }
                 break;
             case self::TYPE_FILL:
                 $size = 'cover';
                 break;
         }
         if ($this->attachment) {
             $i = $this->attachment & 3;
             if ($i == 1) {
                 $positionHor = 'left';
             } else {
                 if ($i == 3) {
                     $positionHor = 'right';
                 }
             }
             $i = $this->attachment & 12;
             if ($i == 4) {
                 $positionVer = 'top';
             } else {
                 if ($i == 12) {
                     $positionVer = 'bottom';
                 }
             }
         }
         $css->addRule($selector, 'background-image', $css->getURLValue($this->url));
         $css->addRule($selector, 'background-repeat', $repeat);
         $css->addRule($selector, 'background-position', "{$positionHor} {$positionVer}");
         $css->addRule($selector, 'background-size', $size);
     }
     $css->addRule($selector, 'background-color', $css->getColorValue($this->color));
 }