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/Component/CssSelector/Node/ElementNode.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2010-03-31 07:42:18 +01:00
<?php
namespace Symfony\Component\CssSelector\Node;
2010-03-31 07:42:18 +01:00
use Symfony\Component\CssSelector\XPathExpr;
2010-03-31 07:42:18 +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.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2010-03-31 07:42:18 +01:00
*/
class ElementNode implements NodeInterface
{
protected $namespace;
protected $element;
2010-03-31 07:42:18 +01:00
public function __construct($namespace, $element)
2010-03-31 07:42:18 +01:00
{
$this->namespace = $namespace;
$this->element = $element;
2010-03-31 07:42:18 +01:00
}
public function __toString()
2010-03-31 07:42:18 +01:00
{
return sprintf('%s[%s]', __CLASS__, $this->formatElement());
2010-03-31 07:42:18 +01:00
}
public function formatElement()
2010-03-31 07:42:18 +01:00
{
if ($this->namespace == '*') {
return $this->element;
}
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 {
// 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
}