Skip to content

Commit f78fca5

Browse files
authored
[TASK] Add SelectorComponent interface (#1478)
This will be implemented by `CompoundSelector` and `Combinator` to break up the components of a selector. Part of #1325.
1 parent 9641004 commit f78fca5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS\Property\Selector;
6+
7+
/**
8+
* This interface is for a class that represents a part of a selector which is either a compound selector (or a simple
9+
* selector, which is effectively a compound selector without any compounding) or a selector combinator.
10+
*
11+
* It allows a selector to be represented as an array of objects that implement this interface.
12+
* This is the formal definition:
13+
* selector = compound-selector [combinator, compound-selector]*
14+
*
15+
* The selector is comprised of an array of alternating types that can't be easily represented in a type-safe manner
16+
* without this.
17+
*
18+
* 'Selector component' is not a known grammar in the spec, but a convenience for the implementation.
19+
*
20+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Selectors/Selector_structure
21+
* @see https://www.w3.org/TR/selectors-4/#structure
22+
*/
23+
interface SelectorComponent
24+
{
25+
/**
26+
* @return non-empty-string
27+
*/
28+
public function getValue(): string;
29+
30+
/**
31+
* @param non-empty-string $value
32+
*/
33+
public function setValue(string $value): void;
34+
35+
/**
36+
* @return int<0, max>
37+
*/
38+
public function getSpecificity(): int;
39+
}

0 commit comments

Comments
 (0)