Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c06db30

Browse files
committed
minor #15988 [CssSelector] remove ConverterInterface (fabpot)
This PR was merged into the 2.8 branch. Discussion ---------- [CssSelector] remove ConverterInterface | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15934 | License | MIT | Doc PR | n/a Commits ------- 8b8b634 [CssSelector] updated README fd3fefb [CssSelector] remove ConverterInterface
2 parents b630972 + 8b8b634 commit c06db30

File tree

4 files changed

+59
-82
lines changed

4 files changed

+59
-82
lines changed

src/Symfony/Component/CssSelector/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
2.8.0
55
-----
66

7-
* Added the ConverterInterface and the Converter implementation as a non-static API for the component.
7+
* Added the `CssSelectorConverter` class as a non-static API for the component.
88
* Deprecated the `CssSelector` static API of the component.
99

1010
2.1.0

src/Symfony/Component/CssSelector/ConverterInterface.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Symfony/Component/CssSelector/Converter.php renamed to src/Symfony/Component/CssSelector/CssSelectorConverter.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
use Symfony\Component\CssSelector\XPath\Translator;
2020

2121
/**
22+
* CssSelectorConverter is the main entry point of the component and can convert CSS
23+
* selectors to XPath expressions.
24+
*
2225
* @author Christophe Coevoet <[email protected]>
2326
*/
24-
class Converter implements ConverterInterface
27+
class CssSelectorConverter
2528
{
2629
private $translator;
2730

@@ -45,7 +48,15 @@ public function __construct($html = true)
4548
}
4649

4750
/**
48-
* {@inheritdoc}
51+
* Translates a CSS expression to its XPath equivalent.
52+
*
53+
* Optionally, a prefix can be added to the resulting XPath
54+
* expression with the $prefix parameter.
55+
*
56+
* @param string $cssExpr The CSS expression.
57+
* @param string $prefix An optional prefix for the XPath expression.
58+
*
59+
* @return string
4960
*/
5061
public function toXPath($cssExpr, $prefix = 'descendant-or-self::')
5162
{

src/Symfony/Component/CssSelector/README.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,23 @@ The component only goal is to convert CSS selectors to their XPath
77
equivalents:
88

99
```php
10-
use Symfony\Component\CssSelector\CssSelector;
10+
use Symfony\Component\CssSelector\CssSelectorConverter;
1111

12-
print CssSelector::toXPath('div.item > h4 > a');
12+
$converter = new CssSelectorConverter();
13+
print $converter->toXPath('div.item > h4 > a');
1314
```
1415

1516
HTML and XML are different
1617
--------------------------
1718

1819
The `CssSelector` component comes with an `HTML` extension which is enabled by
1920
default. If you need to use this component with `XML` documents, you have to
20-
disable this `HTML` extension. That's because, `HTML` tag & attribute names
21-
are always lower-cased, but case-sensitive in `XML`:
21+
disable this `HTML` extension. That's because, `HTML` tag & attribute names are
22+
always lower-cased, but case-sensitive in `XML`:
2223

2324
```php
2425
// disable `HTML` extension:
25-
CssSelector::disableHtmlExtension();
26-
27-
// re-enable `HTML` extension:
28-
CssSelector::enableHtmlExtension();
26+
$converter = new CssSelectorConverter(false);
2927
```
3028

3129
When the `HTML` extension is enabled, tag names are lower-cased, attribute
@@ -45,3 +43,42 @@ You can run the unit tests with the following command:
4543
$ cd path/to/Symfony/Component/CssSelector/
4644
$ composer install
4745
$ phpunit
46+
47+
License
48+
-------
49+
50+
This component is a port of the Python cssselect library,
51+
which is copyright Ian Bicking, https://github.com/SimonSapin/cssselect.
52+
53+
Copyright (c) 2007-2012 Ian Bicking and contributors. See AUTHORS
54+
for more details.
55+
56+
All rights reserved.
57+
58+
Redistribution and use in source and binary forms, with or without
59+
modification, are permitted provided that the following conditions are
60+
met:
61+
62+
1. Redistributions of source code must retain the above copyright
63+
notice, this list of conditions and the following disclaimer.
64+
65+
2. Redistributions in binary form must reproduce the above copyright
66+
notice, this list of conditions and the following disclaimer in
67+
the documentation and/or other materials provided with the
68+
distribution.
69+
70+
3. Neither the name of Ian Bicking nor the names of its contributors may
71+
be used to endorse or promote products derived from this software
72+
without specific prior written permission.
73+
74+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
75+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
76+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
77+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IAN BICKING OR
78+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
79+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
80+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
81+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
82+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
83+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
84+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)