CSSList
4 days ago
Comment
4 days ago
Parsing
4 days ago
Position
4 days ago
Property
4 days ago
Rule
4 days ago
RuleSet
4 days ago
Value
4 days ago
CSSElement.php
2 months ago
OutputFormat.php
4 days ago
OutputFormatter.php
4 days ago
Parser.php
4 days ago
Renderable.php
4 days ago
Settings.php
4 days ago
ShortClassNameProvider.php
4 days ago
Parser.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace ProfilePressVendor\Sabberworm\CSS; |
| 5 | |
| 6 | use ProfilePressVendor\Sabberworm\CSS\CSSList\Document; |
| 7 | use ProfilePressVendor\Sabberworm\CSS\Parsing\ParserState; |
| 8 | use ProfilePressVendor\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 |