Skip to content

Commit e74d5ab

Browse files
committed
Merge git://github.com/goetas/PHP-CSS-Parser
Add support for @namespace. Modify goetas’ change by adding support for the alternate @url syntax and use “native” CSS valus in CSSNamespace Closes MyIntervals#46 as fixed * git://github.com/goetas/PHP-CSS-Parser: added @namespace rule support added @namespace rule support Conflicts: lib/Sabberworm/CSS/Parser.php
2 parents 647c931 + acdfc7d commit e74d5ab

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sabberworm\CSS\CSSList\Keyframe;
99
use Sabberworm\CSS\Property\Import;
1010
use Sabberworm\CSS\Property\Charset;
11+
use Sabberworm\CSS\Property\CSSNamespace;
1112
use Sabberworm\CSS\RuleSet\AtRule;
1213
use Sabberworm\CSS\RuleSet\DeclarationBlock;
1314
use Sabberworm\CSS\Value\CSSFunction;
@@ -119,6 +120,21 @@ private function parseAtRule() {
119120
$this->consumeWhiteSpace();
120121
$this->parseList($oResult);
121122
return $oResult;
123+
} else if ($sIdentifier === 'namespace') {
124+
$sPrefix = null;
125+
$mUrl = $this->parsePrimitiveValue();
126+
if(!$this->comes(';')) {
127+
$sPrefix = $mUrl;
128+
$mUrl = $this->parsePrimitiveValue();
129+
}
130+
$this->consume(';');
131+
if($sPrefix !== null && !is_string($sPrefix)) {
132+
throw new \Exception('Wrong namespace prefix '.$sPrefix);
133+
}
134+
if(!($mUrl instanceof String || $mUrl instanceof URL)) {
135+
throw new \Exception('Wrong namespace url of invalid type '.$mUrl);
136+
}
137+
return new CSSNamespace($mUrl, $sPrefix);
122138
} else {
123139
//Unknown other at rule (font-face or such)
124140
$this->consume('{');
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Property;
4+
5+
/**
6+
* CSSNamespace represents an @namespace rule.
7+
*/
8+
class CSSNamespace {
9+
private $mUrl;
10+
private $sPrefix;
11+
12+
public function __construct($mUrl, $sPrefix = null) {
13+
$this->mUrl = $mUrl;
14+
$this->sPrefix = $sPrefix;
15+
}
16+
17+
public function __toString() {
18+
return '@namespace '.($this->sPrefix === null ? '' : $this->sPrefix.' ').$this->mUrl->__toString().';';
19+
}
20+
21+
public function getUrl() {
22+
return $this->mUrl;
23+
}
24+
25+
public function getPrefix() {
26+
return $this->sPrefix;
27+
}
28+
29+
public function setUrl($mUrl) {
30+
$this->mUrl = $mUrl;
31+
}
32+
33+
public function setPrefix($sPrefix) {
34+
$this->sPrefix = $sPrefix;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)