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 Symfony\Component\CssSelector\Parser\Shortcut; Chris@0: Chris@0: use Symfony\Component\CssSelector\Node\ClassNode; Chris@0: use Symfony\Component\CssSelector\Node\ElementNode; Chris@0: use Symfony\Component\CssSelector\Node\SelectorNode; Chris@0: use Symfony\Component\CssSelector\Parser\ParserInterface; Chris@0: Chris@0: /** Chris@0: * CSS selector class parser shortcut. Chris@0: * Chris@0: * This component is a port of the Python cssselect library, Chris@0: * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. Chris@0: * Chris@0: * @author Jean-François Simon Chris@0: * Chris@0: * @internal Chris@0: */ Chris@0: class ClassParser implements ParserInterface Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function parse($source) Chris@0: { Chris@0: // Matches an optional namespace, optional element, and required class Chris@0: // $source = 'test|input.ab6bd_field'; Chris@0: // $matches = array (size=4) Chris@0: // 0 => string 'test|input.ab6bd_field' (length=22) Chris@0: // 1 => string 'test' (length=4) Chris@0: // 2 => string 'input' (length=5) Chris@0: // 3 => string 'ab6bd_field' (length=11) Chris@0: if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) { Chris@17: return [ Chris@0: new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])), Chris@17: ]; Chris@0: } Chris@0: Chris@17: return []; Chris@0: } Chris@0: }