Commit | Line | Data |
---|---|---|
fbe18cc0 FM |
1 | <?php |
2 | ||
3 | namespace Sabberworm\CSS; | |
4 | ||
fbe18cc0 | 5 | use Sabberworm\CSS\CSSList\Document; |
376eb156 | 6 | use Sabberworm\CSS\Parsing\ParserState; |
fbe18cc0 FM |
7 | |
8 | /** | |
9 | * Parser class parses CSS from text into a data structure. | |
10 | */ | |
11 | class Parser { | |
376eb156 | 12 | private $oParserState; |
fbe18cc0 FM |
13 | |
14 | /** | |
15 | * Parser constructor. | |
16 | * Note that that iLineNo starts from 1 and not 0 | |
17 | * | |
18 | * @param $sText | |
19 | * @param Settings|null $oParserSettings | |
20 | * @param int $iLineNo | |
21 | */ | |
22 | public function __construct($sText, Settings $oParserSettings = null, $iLineNo = 1) { | |
fbe18cc0 FM |
23 | if ($oParserSettings === null) { |
24 | $oParserSettings = Settings::create(); | |
25 | } | |
376eb156 | 26 | $this->oParserState = new ParserState($sText, $oParserSettings, $iLineNo); |
fbe18cc0 FM |
27 | } |
28 | ||
29 | public function setCharset($sCharset) { | |
376eb156 | 30 | $this->oParserState->setCharset($sCharset); |
fbe18cc0 FM |
31 | } |
32 | ||
33 | public function getCharset() { | |
376eb156 | 34 | $this->oParserState->getCharset(); |
fbe18cc0 FM |
35 | } |
36 | ||
37 | public function parse() { | |
376eb156 | 38 | return Document::parse($this->oParserState); |
fbe18cc0 FM |
39 | } |
40 | ||
41 | } |