|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\CssSelector\Node; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\CssSelector\XPathExpr; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* HashNode represents a "selector#id" node. |
|
|
18 |
* |
|
|
19 |
* This component is a port of the Python lxml library, |
|
|
20 |
* which is copyright Infrae and distributed under the BSD license. |
|
|
21 |
* |
|
|
22 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
23 |
*/ |
|
|
24 |
class HashNode implements NodeInterface |
|
|
25 |
{ |
|
|
26 |
protected $selector; |
|
|
27 |
protected $id; |
|
|
28 |
|
|
|
29 |
/** |
|
|
30 |
* Constructor. |
|
|
31 |
* |
|
|
32 |
* @param NodeInterface $selector The NodeInterface object |
|
|
33 |
* @param string $id The ID |
|
|
34 |
*/ |
|
|
35 |
public function __construct($selector, $id) |
|
|
36 |
{ |
|
|
37 |
$this->selector = $selector; |
|
|
38 |
$this->id = $id; |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
/** |
|
|
42 |
* {@inheritDoc} |
|
|
43 |
*/ |
|
|
44 |
public function __toString() |
|
|
45 |
{ |
|
|
46 |
return sprintf('%s[%s#%s]', __CLASS__, $this->selector, $this->id); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* {@inheritDoc} |
|
|
51 |
*/ |
|
|
52 |
public function toXpath() |
|
|
53 |
{ |
|
|
54 |
$path = $this->selector->toXpath(); |
|
|
55 |
$path->addCondition(sprintf('@id = %s', XPathExpr::xpathLiteral($this->id))); |
|
|
56 |
|
|
|
57 |
return $path; |
|
|
58 |
} |
|
|
59 |
} |