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
12namespace Symfony\Component\CssSelector;
13
14@trigger_error('The '.__NAMESPACE__.'\CssSelector class is deprecated since Symfony 2.8 and will be removed in 3.0. Use directly the \Symfony\Component\CssSelector\CssSelectorConverter class instead.', E_USER_DEPRECATED);
15
16/**
17 * CssSelector is the main entry point of the component and can convert CSS
18 * selectors to XPath expressions.
19 *
20 * $xpath = CssSelector::toXpath('h1.foo');
21 *
22 * This component is a port of the Python cssselect library,
23 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
24 *
25 * Copyright (c) 2007-2012 Ian Bicking and contributors. See AUTHORS
26 * for more details.
27 *
28 * All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions are
32 * met:
33 *
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 *
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
40 * distribution.
41 *
42 * 3. Neither the name of Ian Bicking nor the names of its contributors may
43 * be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IAN BICKING OR
50 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
51 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
52 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
53 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
54 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
55 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
56 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 *
58 * @author Fabien Potencier <fabien@symfony.com>
59 *
60 * @deprecated as of 2.8, will be removed in 3.0. Use the \Symfony\Component\CssSelector\CssSelectorConverter class instead.
61 */
62class CssSelector
63{
64    private static $html = true;
65
66    /**
67     * Translates a CSS expression to its XPath equivalent.
68     * Optionally, a prefix can be added to the resulting XPath
69     * expression with the $prefix parameter.
70     *
71     * @param mixed  $cssExpr The CSS expression
72     * @param string $prefix  An optional prefix for the XPath expression
73     *
74     * @return string
75     */
76    public static function toXPath($cssExpr, $prefix = 'descendant-or-self::')
77    {
78        $converter = new CssSelectorConverter(self::$html);
79
80        return $converter->toXPath($cssExpr, $prefix);
81    }
82
83    /**
84     * Enables the HTML extension.
85     */
86    public static function enableHtmlExtension()
87    {
88        self::$html = true;
89    }
90
91    /**
92     * Disables the HTML extension.
93     */
94    public static function disableHtmlExtension()
95    {
96        self::$html = false;
97    }
98}
99