This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Components/CssSelector/Node/ElementNode.php

69 lines
1.5 KiB
PHP
Raw Normal View History

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;
}
else
{
return sprintf('%s|%s', $this->namespace, $this->element);
}
}
public function toXpath()
{
if ($this->namespace == '*')
{
$el = strtolower($this->element);
}
else
{
// 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);
}
}