2010-03-31 07:42:18 +01:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Component\CssSelector\Node;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\CssSelector\XPathExpr;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
|
|
|
* (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.
|
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-03-31 07:42:18 +01:00
|
|
|
*/
|
|
|
|
class ElementNode implements NodeInterface
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $namespace;
|
|
|
|
protected $element;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __construct($namespace, $element)
|
2010-03-31 07:42:18 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->namespace = $namespace;
|
|
|
|
$this->element = $element;
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|
2010-04-03 00:54:42 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __toString()
|
2010-03-31 07:42:18 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return sprintf('%s[%s]', __CLASS__, $this->formatElement());
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
|
|
|
|
public function formatElement()
|
2010-03-31 07:42:18 +01:00
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($this->namespace == '*') {
|
2010-05-06 12:25:53 +01:00
|
|
|
return $this->element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf('%s|%s', $this->namespace, $this->element);
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function toXpath()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($this->namespace == '*') {
|
2010-05-06 12:25:53 +01:00
|
|
|
$el = strtolower($this->element);
|
2010-05-07 15:09:11 +01:00
|
|
|
} else {
|
2010-05-06 12:25:53 +01:00
|
|
|
// FIXME: Should we lowercase here?
|
|
|
|
$el = sprintf('%s:%s', $this->namespace, $this->element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new XPathExpr(null, null, $el);
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|