Parser.php
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Sabberworm\CSS; |
| 4 | |
| 5 | use IAWP\Sabberworm\CSS\CSSList\Document; |
| 6 | use IAWP\Sabberworm\CSS\Parsing\ParserState; |
| 7 | use IAWP\Sabberworm\CSS\Parsing\SourceException; |
| 8 | /** |
| 9 | * This class parses CSS from text into a data structure. |
| 10 | */ |
| 11 | class Parser |
| 12 | { |
| 13 | /** |
| 14 | * @var ParserState |
| 15 | */ |
| 16 | private $oParserState; |
| 17 | /** |
| 18 | * @param string $sText |
| 19 | * @param Settings|null $oParserSettings |
| 20 | * @param int $iLineNo the line number (starting from 1, not from 0) |
| 21 | */ |
| 22 | public function __construct($sText, Settings $oParserSettings = null, $iLineNo = 1) |
| 23 | { |
| 24 | if ($oParserSettings === null) { |
| 25 | $oParserSettings = Settings::create(); |
| 26 | } |
| 27 | $this->oParserState = new ParserState($sText, $oParserSettings, $iLineNo); |
| 28 | } |
| 29 | /** |
| 30 | * @param string $sCharset |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function setCharset($sCharset) |
| 35 | { |
| 36 | $this->oParserState->setCharset($sCharset); |
| 37 | } |
| 38 | /** |
| 39 | * @return void |
| 40 | */ |
| 41 | public function getCharset() |
| 42 | { |
| 43 | // Note: The `return` statement is missing here. This is a bug that needs to be fixed. |
| 44 | $this->oParserState->getCharset(); |
| 45 | } |
| 46 | /** |
| 47 | * @return Document |
| 48 | * |
| 49 | * @throws SourceException |
| 50 | */ |
| 51 | public function parse() |
| 52 | { |
| 53 | return Document::parse($this->oParserState); |
| 54 | } |
| 55 | } |
| 56 |