* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\CssSelector\XPath\Extension; use Symfony\Component\CssSelector\Exception\ExpressionErrorException; use Symfony\Component\CssSelector\XPath\XPathExpr; /** * XPath expression translator pseudo-class extension. * * This component is a port of the Python cssselect library, * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. * * @author Jean-François Simon * * @internal */ class PseudoClassExtension extends AbstractExtension { /** * {@inheritdoc} */ public function getPseudoClassTranslators() { return array( 'root' => array($this, 'translateRoot'), 'first-child' => array($this, 'translateFirstChild'), 'last-child' => array($this, 'translateLastChild'), 'first-of-type' => array($this, 'translateFirstOfType'), 'last-of-type' => array($this, 'translateLastOfType'), 'only-child' => array($this, 'translateOnlyChild'), 'only-of-type' => array($this, 'translateOnlyOfType'), 'empty' => array($this, 'translateEmpty'), ); } /** * @return XPathExpr */ public function translateRoot(XPathExpr $xpath) { return $xpath->addCondition('not(parent::*)'); } /** * @return XPathExpr */ public function translateFirstChild(XPathExpr $xpath) { return $xpath ->addStarPrefix() ->addNameTest() ->addCondition('position() = 1'); } /** * @return XPathExpr */ public function translateLastChild(XPathExpr $xpath) { return $xpath ->addStarPrefix() ->addNameTest() ->addCondition('position() = last()'); } /** * @return XPathExpr * * @throws ExpressionErrorException */ public function translateFirstOfType(XPathExpr $xpath) { if ('*' === $xpath->getElement()) { throw new ExpressionErrorException('"*:first-of-type" is not implemented.'); } return $xpath ->addStarPrefix() ->addCondition('position() = 1'); } /** * @return XPathExpr * * @throws ExpressionErrorException */ public function translateLastOfType(XPathExpr $xpath) { if ('*' === $xpath->getElement()) { throw new ExpressionErrorException('"*:last-of-type" is not implemented.'); } return $xpath ->addStarPrefix() ->addCondition('position() = last()'); } /** * @return XPathExpr */ public function translateOnlyChild(XPathExpr $xpath) { return $xpath ->addStarPrefix() ->addNameTest() ->addCondition('last() = 1'); } /** * @return XPathExpr * * @throws ExpressionErrorException */ public function translateOnlyOfType(XPathExpr $xpath) { if ('*' === $xpath->getElement()) { throw new ExpressionErrorException('"*:only-of-type" is not implemented.'); } return $xpath->addCondition('last() = 1'); } /** * @return XPathExpr */ public function translateEmpty(XPathExpr $xpath) { return $xpath->addCondition('not(*) and not(string-length())'); } /** * {@inheritdoc} */ public function getName() { return 'pseudo-class'; } } __halt_compiler();----SIGNATURE:----NXKL85QXZ8/rMj8zMH5c4WL3z6sAVWsZ+25XiOThCsfC/az0rqnNBLIL942pgHFna0toZ/tK214j24WM8D2C5tdiD0BxgHFUIVDL/2Q2ocQtXTLdnDTgz4gNlTsON1FWcGM3Q1k3oW8TJDQfvcRKjXdik/E0hPcbfTPQ/sX/sV5lGQnKlYbye37ZG/NgfbqEw45lBD9lU5LE2acdsPO06i8ALN47HAXFjoeyIWmHAZlr9WJWQyf0wXYkJ9vPaqvlN6BTKtP8iPd/Nv/+qGWj4CSM+lC0j0ZlVDWdRwAkCrH8HRtpl8EC06AdfE9FGtPbZpoScQ810UJzSqOtT4Ozby3QK5POtly5UVf7XmWyy3OQuAKmrcxOihrYIUIlUvL6pMnkCwvz7sSGqlzYDuuQ4IwIyLE2nlWa5/4DeC0OwRE6rzr2taPz3ZcpiRtF4cF6t1YVwZiNvajM2PtXUqKj4mt2anNda3CLa7Xh4DL7RiYLGj5SFGwg+4/4HDG5J5E/QMi7N9jGObl6IVFFfkOMtPAanG4LzTqAoS7S/1/JlW6Xbj8lVBybZBm29V/a7syd40OabIoRj5tKIA6EqpJdZ9LoQ7gBKEjhyHZ2Gh0HEB8J4dSAeu5ZE5CAOPzkjeaAi6xeN2h/8F39mfyJ8nysftysE9wD9H+8BeOKnAtPa80=----ATTACHMENT:----Mjg5MjIwOTAyOTczNzk2MiA0ODE2NDMxOTgwMDc3NTE5IDEzODc1NzY5MDU4MzQ1ODU=