* * 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:----Rskw3ADAcMMlqo4ID53uvNOks3DACCU6P4xw8tQtnzRKzowtEhl6ofnv3gcxBMQ2TAs978+/cLcx05/Q1sJOxUuhVHw7VRYty37/X7pb6BVSd1INEXtGjtUyQFA2nAsp37VAbrSLz9pRqNhelwO7vGdJwLfwudZAOQLFjkvbm8z2fdNUMelMhaIfNnSQR5JtclG9l+lkQaf/OeTL2KC2owKCCZO/0FltLR8VrAfhnOJPfo7Uy/ZsObt3KnA0QGyFh3Ent19sjoheUrzLMwgo7Yqmx7gEf3ND+9U3bqlPgOqzFRm+ulMyLBUNp/QsXoHcvNN0Ulb2SDTCioeVnGHg5FfIov3z1WFpEpr+CVFkqdx85Q7FAoUF3Ls0XhkT+P74/A21j/4XajqciMkbnda42esXIsF0Kn76buqolFTMZHDtXwcd7ijrK/teXwYACJsN0qPuG7m6nNblsxrtRLIe+Y7mfA0RUxt5jn35DsJNA1mLZV8Sw3ueGVwdKLONosMqMZ7m46MSjmD4vqdkq2q72h+fnXw/X3Cujef36WhTbvLjn5b7bTAeKFNZaiS8ZFZyTk4vafZWZWE7Bzyl94Dzmyaq/gEw8q38tvnjuAYgkz8098E2HI7tZexc+MHQiJF/wx7VSnEtSffX8HHD4sS5sT+0nZAq1zt+5zZgJFKQL/M=----ATTACHMENT:----NjM5NjU0MzM0NjE4MjEzNiA0Njg5NDE2NDQzODQ1NTA5IDg5MjQzMzg5NjQ1MjY3NDA=