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

78 lines
1.6 KiB
PHP
Raw Normal View History

2010-03-31 07:42:18 +01:00
<?php
/*
* This file is part of the Symfony package.
2010-03-31 07:42:18 +01: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.
*/
namespace Symfony\Component\CssSelector\Node;
2010-03-31 07:42:18 +01:00
/**
* Represents a "<namespace>|<element>" node.
2010-03-31 07:42:18 +01:00
*
* This component is a port of the Python cssselector library,
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
2010-03-31 07:42:18 +01:00
*
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
2010-03-31 07:42:18 +01:00
*/
class ElementNode extends AbstractNode
2010-03-31 07:42:18 +01:00
{
/**
* @var string|null
*/
private $namespace;
/**
* @var string|null
*/
private $element;
2010-03-31 07:42:18 +01:00
2011-02-09 00:19:47 +00:00
/**
* @param string|null $namespace
* @param string|null $element
2011-04-15 20:12:02 +01:00
*/
public function __construct($namespace = null, $element = null)
2010-03-31 07:42:18 +01:00
{
$this->namespace = $namespace;
$this->element = $element;
2010-03-31 07:42:18 +01:00
}
2011-02-09 00:19:47 +00:00
/**
* @return null|string
2011-02-09 00:19:47 +00:00
*/
public function getNamespace()
2010-03-31 07:42:18 +01:00
{
return $this->namespace;
2010-03-31 07:42:18 +01:00
}
2011-02-09 00:19:47 +00:00
/**
* @return null|string
2011-02-09 00:19:47 +00:00
*/
public function getElement()
2010-03-31 07:42:18 +01:00
{
return $this->element;
}
/**
* {@inheritdoc}
*/
public function getSpecificity()
{
return new Specificity(0, 0, $this->element ? 1 : 0);
2010-03-31 07:42:18 +01:00
}
2011-02-09 00:19:47 +00:00
/**
* {@inheritdoc}
2011-02-09 00:19:47 +00:00
*/
public function __toString()
{
$element = $this->element ?: '*';
return sprintf('%s[%s]', $this->getNodeName(), $this->namespace ? $this->namespace.'|'.$element : $element);
}
2010-03-31 07:42:18 +01:00
}