scratch – Blame information for rev 87

Subversion Repositories:
Rev:
Rev Author Line No. Line
87 office 1 <?php
2  
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11  
12 namespace Symfony\Component\CssSelector\XPath\Extension;
13  
14 use Symfony\Component\CssSelector\XPath\XPathExpr;
15  
16 /**
17 * XPath expression translator combination extension.
18 *
19 * This component is a port of the Python cssselect library,
20 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
21 *
22 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
23 *
24 * @internal
25 */
26 class CombinationExtension extends AbstractExtension
27 {
28 /**
29 * {@inheritdoc}
30 */
31 public function getCombinationTranslators()
32 {
33 return array(
34 ' ' => array($this, 'translateDescendant'),
35 '>' => array($this, 'translateChild'),
36 '+' => array($this, 'translateDirectAdjacent'),
37 '~' => array($this, 'translateIndirectAdjacent'),
38 );
39 }
40  
41 /**
42 * @param XPathExpr $xpath
43 * @param XPathExpr $combinedXpath
44 *
45 * @return XPathExpr
46 */
47 public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath)
48 {
49 return $xpath->join('/descendant-or-self::*/', $combinedXpath);
50 }
51  
52 /**
53 * @param XPathExpr $xpath
54 * @param XPathExpr $combinedXpath
55 *
56 * @return XPathExpr
57 */
58 public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath)
59 {
60 return $xpath->join('/', $combinedXpath);
61 }
62  
63 /**
64 * @param XPathExpr $xpath
65 * @param XPathExpr $combinedXpath
66 *
67 * @return XPathExpr
68 */
69 public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
70 {
71 return $xpath
72 ->join('/following-sibling::', $combinedXpath)
73 ->addNameTest()
74 ->addCondition('position() = 1');
75 }
76  
77 /**
78 * @param XPathExpr $xpath
79 * @param XPathExpr $combinedXpath
80 *
81 * @return XPathExpr
82 */
83 public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
84 {
85 return $xpath->join('/following-sibling::', $combinedXpath);
86 }
87  
88 /**
89 * {@inheritdoc}
90 */
91 public function getName()
92 {
93 return 'combination';
94 }
95 }