2010-03-31 07:42:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\CssSelector\Node;
|
|
|
|
|
|
|
|
use Symfony\Component\CssSelector\XPathExpr;
|
|
|
|
|
2010-03-31 07:42:18 +01:00
|
|
|
/**
|
|
|
|
* HashNode represents a "selector#id" node.
|
|
|
|
*
|
|
|
|
* This component is a port of the Python lxml library,
|
|
|
|
* which is copyright Infrae and distributed under the BSD license.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-03-31 07:42:18 +01:00
|
|
|
*/
|
|
|
|
class HashNode implements NodeInterface
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $selector;
|
|
|
|
protected $id;
|
|
|
|
|
2011-02-09 00:19:47 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param NodeInterface $selector The NodeInterface object
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $id The ID
|
2011-02-09 00:19:47 +00:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __construct($selector, $id)
|
|
|
|
{
|
|
|
|
$this->selector = $selector;
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:12:02 +01:00
|
|
|
/**
|
2011-02-09 00:19:47 +00:00
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return sprintf('%s[%s#%s]', __CLASS__, $this->selector, $this->id);
|
|
|
|
}
|
|
|
|
|
2011-02-09 00:19:47 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function toXpath()
|
|
|
|
{
|
|
|
|
$path = $this->selector->toXpath();
|
|
|
|
$path->addCondition(sprintf('@id = %s', XPathExpr::xpathLiteral($this->id)));
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|