* * 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:----GX4wLZvgW/51922NF+nJl0c+Pz22LvGQb4Wehsl0yQaqb2HRqzDEMcOlomJZ077PRhjkuDjRoAA4r0qVK/ntSChGHGj6Qp/LQUyanHyTLR8lyyXQFu7gZGmiZ8b8VDRreYya5PfbYwnv/fc5gpTL3PiAtDczURbXiINFJiqqSz3o1UlTPBXcR6FzoC66ArNeZl8mUDijf9jiSJvGOmOD0ibsUlnhPHBYd6PjTZXQqbUujkPacRBauxioJZwENjlPlA22fGAKzttCI4ZOPSqy1rtre23EjFVT9iqEp5dFWPzK1pmacW+eEpqgQDwdJk8kNO8HU8mDl98H8eGOwNgT8/u/LsYigHrsPzTKj3zTb1lhg0IeIoOkfvSFGI0/ge3lZPgzuCTBmuTowgSagU5ePVcYzFi9yZ0w9Iks0zmbpI7J1B7S0d0u4Fw1t7wKwZQ/5Bic1L0vOAbXMDGVsYZKfGhmMHEXvvBMFf1LdpbF0w/Xdligjz/Z+2nMNomiMUkXvx/ihkUWv7hMQfqO0i1x4qk6UynCwBR3jSlZ2UFnYDzM17K6HxZthlyWmbW1ULypFyRdunyIStqDZSmuIIvObyTjwbAQ6wwi1OqYR7w2+G3FvhYX/3dtMqs4VKe5Ab/Q18Lk9JyX+pqe6NSx83silPLYsdsfSzWy5DeGO1oWPq8=----ATTACHMENT:----MTgyODI4NDc1MTg4MDA1MiAzNjY0NzYyNTk4Mzc2NDQwIDI0MTU3ODY4NDYzNTk3Mzc=