Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Behat\Mink\Selector; Chris@0: Chris@0: use Symfony\Component\CssSelector\CssSelector as CSS; Chris@0: use Symfony\Component\CssSelector\CssSelectorConverter; Chris@0: Chris@0: /** Chris@0: * CSS selector engine. Transforms CSS to XPath. Chris@0: * Chris@0: * @author Konstantin Kudryashov Chris@0: */ Chris@0: class CssSelector implements SelectorInterface Chris@0: { Chris@0: /** Chris@0: * Translates CSS into XPath. Chris@0: * Chris@0: * @param string|array $locator current selector locator Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function translateToXPath($locator) Chris@0: { Chris@0: if (!is_string($locator)) { Chris@0: throw new \InvalidArgumentException('The CssSelector expects to get a string as locator'); Chris@0: } Chris@0: Chris@0: // Symfony 2.8+ API Chris@0: if (class_exists('Symfony\Component\CssSelector\CssSelectorConverter')) { Chris@0: $converter = new CssSelectorConverter(); Chris@0: Chris@0: return $converter->toXPath($locator); Chris@0: } Chris@0: Chris@0: // old static API for Symfony 2.7 and older Chris@0: return CSS::toXPath($locator); Chris@0: } Chris@0: }