mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -33,7 +33,7 @@ The resulting CSS document structure can be manipulated prior to being output.
|
||||
|
||||
#### Charset
|
||||
|
||||
The charset option is used only if no `@charset` declaration is found in the CSS file. UTF-8 is the default, so you won’t have to create a settings object at all if you don’t intend to change that.
|
||||
The charset option will only be used if the CSS file does not contain an `@charset` declaration. UTF-8 is the default, so you won’t have to create a settings object at all if you don’t intend to change that.
|
||||
|
||||
```php
|
||||
$settings = \Sabberworm\CSS\Settings::create()
|
||||
@@ -43,7 +43,7 @@ $parser = new \Sabberworm\CSS\Parser($css, $settings);
|
||||
|
||||
#### Strict parsing
|
||||
|
||||
To have the parser choke on invalid rules, supply a thusly configured `\Sabberworm\CSS\Settings` object:
|
||||
To have the parser throw an exception when encountering invalid/unknown constructs (as opposed to trying to ignore them and carry on parsing), supply a thusly configured `\Sabberworm\CSS\Settings` object:
|
||||
|
||||
```php
|
||||
$parser = new \Sabberworm\CSS\Parser(
|
||||
@@ -52,6 +52,8 @@ $parser = new \Sabberworm\CSS\Parser(
|
||||
);
|
||||
```
|
||||
|
||||
Note that this will also disable a workaround for parsing the unquoted variant of the legacy IE-specific `filter` rule.
|
||||
|
||||
#### Disable multibyte functions
|
||||
|
||||
To achieve faster parsing, you can choose to have PHP-CSS-Parser use regular string functions instead of `mb_*` functions. This should work fine in most cases, even for UTF-8 files, as all the multibyte characters are in string literals. Still it’s not recommended using this with input you have no control over as it’s not thoroughly covered by test cases.
|
||||
@@ -67,12 +69,9 @@ The resulting data structure consists mainly of five basic types: `CSSList`, `Ru
|
||||
|
||||
#### CSSList
|
||||
|
||||
`CSSList` represents a generic CSS container, most likely containing declaration blocks (rule sets with a selector), but it may also contain at-rules, charset declarations, etc. `CSSList` has the following concrete subtypes:
|
||||
`CSSList` represents a generic CSS container, most likely containing declaration blocks (rule sets with a selector), but it may also contain at-rules, charset declarations, etc.
|
||||
|
||||
* `Document` – representing the root of a CSS file.
|
||||
* `MediaQuery` – represents a subsection of a `CSSList` that only applies to an output device matching the contained media query.
|
||||
|
||||
To access the items stored in a `CSSList` – like the document you got back when calling `$parser->parse()` –, use `getContents()`, then iterate over that collection and use instanceof to check whether you’re dealing with another `CSSList`, a `RuleSet`, a `Import` or a `Charset`.
|
||||
To access the items stored in a `CSSList` – like the document you got back when calling `$parser->parse()` –, use `getContents()`, then iterate over that collection and use `instanceof` to check whether you’re dealing with another `CSSList`, a `RuleSet`, a `Import` or a `Charset`.
|
||||
|
||||
To append a new item (selector, media query, etc.) to an existing `CSSList`, construct it using the constructor for this class and use the `append($oItem)` method.
|
||||
|
||||
@@ -80,16 +79,16 @@ To append a new item (selector, media query, etc.) to an existing `CSSList`, con
|
||||
|
||||
`RuleSet` is a container for individual rules. The most common form of a rule set is one constrained by a selector. The following concrete subtypes exist:
|
||||
|
||||
* `AtRuleSet` – for generic at-rules which do not match the ones specifically mentioned like `@import`, `@charset` or `@media`. A common example for this is `@font-face`.
|
||||
* `AtRuleSet` – for generic at-rules for generic at-rules which are not covered by specific classes, i.e., not `@import`, `@charset` or `@media`. A common example for this is `@font-face`.
|
||||
* `DeclarationBlock` – a `RuleSet` constrained by a `Selector`; contains an array of selector objects (comma-separated in the CSS) as well as the rules to be applied to the matching elements.
|
||||
|
||||
Note: A `CSSList` can contain other `CSSList`s (and `Import`s as well as a `Charset`), while a `RuleSet` can only contain `Rule`s.
|
||||
|
||||
If you want to manipulate a `RuleSet`, use the methods `addRule(Rule $rule)`, `getRules()` and `removeRule($rule)` (which accepts either a `Rule` instance or a rule name; optionally suffixed by a dash to remove all related rules).
|
||||
If you want to manipulate a `RuleSet`, use the methods `addRule(Rule $rule)`, `getRules()` and `removeRule($rule)` (which accepts either a `Rule` or a rule name; optionally suffixed by a dash to remove all related rules).
|
||||
|
||||
#### Rule
|
||||
|
||||
`Rule`s just have a key (the rule) and a value. These values are all instances of a `Value`.
|
||||
`Rule`s just have a string key (the rule) and a `Value`.
|
||||
|
||||
#### Value
|
||||
|
||||
@@ -98,19 +97,21 @@ If you want to manipulate a `RuleSet`, use the methods `addRule(Rule $rule)`, `g
|
||||
* `Size` – consists of a numeric `size` value and a unit.
|
||||
* `Color` – colors can be input in the form #rrggbb, #rgb or schema(val1, val2, …) but are always stored as an array of ('s' => val1, 'c' => val2, 'h' => val3, …) and output in the second form.
|
||||
* `CSSString` – this is just a wrapper for quoted strings to distinguish them from keywords; always output with double quotes.
|
||||
* `URL` – URLs in CSS; always output in URL("") notation.
|
||||
* `URL` – URLs in CSS; always output in `URL("")` notation.
|
||||
|
||||
There is another abstract subclass of `Value`, `ValueList`. A `ValueList` represents a lists of `Value`s, separated by some separation character (mostly `,`, whitespace, or `/`). There are two types of `ValueList`s:
|
||||
There is another abstract subclass of `Value`, `ValueList`: A `ValueList` represents a lists of `Value`s, separated by some separation character (mostly `,`, whitespace, or `/`).
|
||||
|
||||
* `RuleValueList` – The default type, used to represent all multi-valued rules like `font: bold 12px/3 Helvetica, Verdana, sans-serif;` (where the value would be a whitespace-separated list of the primitive value `bold`, a slash-separated list and a comma-separated list).
|
||||
There are two types of `ValueList`s:
|
||||
|
||||
* `RuleValueList` – The default type, used to represent all multivalued rules like `font: bold 12px/3 Helvetica, Verdana, sans-serif;` (where the value would be a whitespace-separated list of the primitive value `bold`, a slash-separated list and a comma-separated list).
|
||||
* `CSSFunction` – A special kind of value that also contains a function name and where the values are the function’s arguments. Also handles equals-sign-separated argument lists like `filter: alpha(opacity=90);`.
|
||||
|
||||
#### Convenience methods
|
||||
|
||||
There are a few convenience methods on Document to ease finding, manipulating and deleting rules:
|
||||
There are a few convenience methods on `Document` to ease finding, manipulating and deleting rules:
|
||||
|
||||
* `getAllDeclarationBlocks()` – does what it says; no matter how deeply nested your selectors are. Aliased as `getAllSelectors()`.
|
||||
* `getAllRuleSets()` – does what it says; no matter how deeply nested your rule sets are.
|
||||
* `getAllDeclarationBlocks()` – does what it says; no matter how deeply nested the selectors are. Aliased as `getAllSelectors()`.
|
||||
* `getAllRuleSets()` – does what it says; no matter how deeply nested the rule sets are.
|
||||
* `getAllValues()` – finds all `Value` objects inside `Rule`s.
|
||||
|
||||
## To-Do
|
||||
@@ -156,7 +157,7 @@ $cssDocument = $parser->parse();
|
||||
foreach($cssDocument->getAllRuleSets() as $oRuleSet) {
|
||||
// Note that the added dash will make this remove all rules starting with
|
||||
// `font-` (like `font-size`, `font-weight`, etc.) as well as a potential
|
||||
// `font-rule`.
|
||||
// `font` rule.
|
||||
$oRuleSet->removeRule('font-');
|
||||
$oRuleSet->removeRule('cursor');
|
||||
}
|
||||
@@ -214,7 +215,8 @@ html, body {
|
||||
|
||||
```
|
||||
|
||||
#### Structure (`var_dump()`)
|
||||
<details>
|
||||
<summary><b>Structure (<code>var_dump()</code>)</b></summary>
|
||||
|
||||
```php
|
||||
class Sabberworm\CSS\CSSList\Document#4 (2) {
|
||||
@@ -435,6 +437,7 @@ class Sabberworm\CSS\CSSList\Document#4 (2) {
|
||||
}
|
||||
|
||||
```
|
||||
</details>
|
||||
|
||||
#### Output (`render()`)
|
||||
|
||||
@@ -458,7 +461,8 @@ html, body {font-size: 1.6em;}
|
||||
|
||||
```
|
||||
|
||||
#### Structure (`var_dump()`)
|
||||
<details>
|
||||
<summary><b>Structure (<code>var_dump()</code>)</b></summary>
|
||||
|
||||
```php
|
||||
class Sabberworm\CSS\CSSList\Document#4 (2) {
|
||||
@@ -603,6 +607,7 @@ class Sabberworm\CSS\CSSList\Document#4 (2) {
|
||||
}
|
||||
|
||||
```
|
||||
</details>
|
||||
|
||||
#### Output (`render()`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user