Mercurial > hg > isophonics-drupal-site
annotate vendor/behat/mink/src/Selector/CssSelector.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 /* |
Chris@0 | 4 * This file is part of the Mink package. |
Chris@0 | 5 * (c) Konstantin Kudryashov <ever.zet@gmail.com> |
Chris@0 | 6 * |
Chris@0 | 7 * For the full copyright and license information, please view the LICENSE |
Chris@0 | 8 * file that was distributed with this source code. |
Chris@0 | 9 */ |
Chris@0 | 10 |
Chris@0 | 11 namespace Behat\Mink\Selector; |
Chris@0 | 12 |
Chris@0 | 13 use Symfony\Component\CssSelector\CssSelector as CSS; |
Chris@0 | 14 use Symfony\Component\CssSelector\CssSelectorConverter; |
Chris@0 | 15 |
Chris@0 | 16 /** |
Chris@0 | 17 * CSS selector engine. Transforms CSS to XPath. |
Chris@0 | 18 * |
Chris@0 | 19 * @author Konstantin Kudryashov <ever.zet@gmail.com> |
Chris@0 | 20 */ |
Chris@0 | 21 class CssSelector implements SelectorInterface |
Chris@0 | 22 { |
Chris@0 | 23 /** |
Chris@0 | 24 * Translates CSS into XPath. |
Chris@0 | 25 * |
Chris@0 | 26 * @param string|array $locator current selector locator |
Chris@0 | 27 * |
Chris@0 | 28 * @return string |
Chris@0 | 29 */ |
Chris@0 | 30 public function translateToXPath($locator) |
Chris@0 | 31 { |
Chris@0 | 32 if (!is_string($locator)) { |
Chris@0 | 33 throw new \InvalidArgumentException('The CssSelector expects to get a string as locator'); |
Chris@0 | 34 } |
Chris@0 | 35 |
Chris@0 | 36 // Symfony 2.8+ API |
Chris@0 | 37 if (class_exists('Symfony\Component\CssSelector\CssSelectorConverter')) { |
Chris@0 | 38 $converter = new CssSelectorConverter(); |
Chris@0 | 39 |
Chris@0 | 40 return $converter->toXPath($locator); |
Chris@0 | 41 } |
Chris@0 | 42 |
Chris@0 | 43 // old static API for Symfony 2.7 and older |
Chris@0 | 44 return CSS::toXPath($locator); |
Chris@0 | 45 } |
Chris@0 | 46 } |