2010-03-31 07:42:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Components\CssSelector\Node;
|
|
|
|
|
|
|
|
use Symfony\Components\CssSelector\XPathExpr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ElementNode represents a "namespace|element" node.
|
|
|
|
*
|
|
|
|
* This component is a port of the Python lxml library,
|
|
|
|
* which is copyright Infrae and distributed under the BSD license.
|
|
|
|
*
|
|
|
|
* @package symfony
|
|
|
|
* @subpackage css_selector
|
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
|
|
|
class ElementNode implements NodeInterface
|
|
|
|
{
|
|
|
|
protected $namespace;
|
|
|
|
protected $element;
|
|
|
|
|
|
|
|
public function __construct($namespace, $element)
|
|
|
|
{
|
|
|
|
$this->namespace = $namespace;
|
|
|
|
$this->element = $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return sprintf('%s[%s]', __CLASS__, $this->formatElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function formatElement()
|
|
|
|
{
|
|
|
|
if ($this->namespace == '*')
|
|
|
|
{
|
|
|
|
return $this->element;
|
|
|
|
}
|
2010-04-03 00:54:42 +01:00
|
|
|
|
|
|
|
return sprintf('%s|%s', $this->namespace, $this->element);
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toXpath()
|
|
|
|
{
|
|
|
|
if ($this->namespace == '*')
|
|
|
|
{
|
|
|
|
$el = strtolower($this->element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-03 00:48:10 +01:00
|
|
|
// FIXME: Should we lowercase here?
|
2010-03-31 07:42:18 +01:00
|
|
|
$el = sprintf('%s:%s', $this->namespace, $this->element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new XPathExpr(null, null, $el);
|
|
|
|
}
|
|
|
|
}
|