| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sabberworm\CSS; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sabberworm\CSS\CSSList\Document; |
| 7 |
use WCPOS\Vendor\Sabberworm\CSS\Parsing\ParserState; |
| 8 |
use WCPOS\Vendor\Sabberworm\CSS\Parsing\SourceException; |
| 9 |
/** |
| 10 |
* This class parses CSS from text into a data structure. |
| 11 |
*/ |
| 12 |
class Parser |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var ParserState |
| 16 |
*/ |
| 17 |
private $parserState; |
| 18 |
/** |
| 19 |
* @param string $text the complete CSS as text (i.e., usually the contents of a CSS file) |
| 20 |
* @param int<1, max> $lineNumber the line number (starting from 1, not from 0) |
| 21 |
*/ |
| 22 |
public function __construct(string $text, ?Settings $parserSettings = null, int $lineNumber = 1) |
| 23 |
{ |
| 24 |
if ($parserSettings === null) { |
| 25 |
$parserSettings = Settings::create(); |
| 26 |
} |
| 27 |
$this->parserState = new ParserState($text, $parserSettings, $lineNumber); |
| 28 |
} |
| 29 |
/** |
| 30 |
* Parses the CSS provided to the constructor and creates a `Document` from it. |
| 31 |
* |
| 32 |
* @throws SourceException |
| 33 |
*/ |
| 34 |
public function parse() : Document |
| 35 |
{ |
| 36 |
return Document::parse($this->parserState); |
| 37 |
} |
| 38 |
} |
| 39 |
|