Drupal investigation

CssSelector.php 3.4KB

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