public function testNotMatching()
 {
     $parser = new AllInstancesSelectorParser();
     $this->assertFalse($parser->match('Article'));
     $this->assertFalse($parser->match('Article()'));
     $this->assertFalse($parser->match('Article(1)'));
 }
Beispiel #2
0
    /**
     * @return Parser
     */
    public static function create()
    {
        $idSelectorParser = new IdSelectorParser();
        $allInstancesSelectorParser = new AllInstancesSelectorParser();
        $namedSelectorParser = new NamedSelectorParser();
        $propertyAccessParser = new PropertyAccessParser();
        $arrayAccessParser = new ArrayAccessParser();
        $methodCallParser = new MethodCallParser();
        $lexer = new SimpleLexer('/
                # ID selector
                ([\\\\_a-zA-Z0-9]+\\([0-9]+\\))

                # All instances selector
                |([\\\\_a-zA-Z0-9]+\\(\\*\\))

                # Named selector
                |([\\\\_a-zA-Z0-9]+)

                # Method call
                |(\\.[_a-zA-Z0-9]+\\(\\))

                # Property access
                |(\\.[_a-zA-Z0-9]+)

                # Array access
                |(\\[[_a-zA-Z0-9]+\\])
            /x', array(self::T_UNKNOWN => 'T_UNKNOWN', self::T_ID_SELECTOR => 'T_ID_SELECTOR', self::T_ALL_INSTANCES_SELECTOR => 'T_ALL_INSTANCES_SELECTOR', self::T_NAMED_SELECTOR => 'T_NAMED_SELECTOR', self::T_METHOD_CALL => 'T_METHOD_CALL', self::T_PROPERTY_ACCESS => 'T_PROPERTY_ACCESS', self::T_ARRAY_ACCESS => 'T_ARRAY_ACCESS'), function ($part) use($idSelectorParser, $allInstancesSelectorParser, $namedSelectorParser, $propertyAccessParser, $methodCallParser, $arrayAccessParser) {
            if ($idSelectorParser->match($part)) {
                return array(self::T_ID_SELECTOR, $part);
            }
            if ($allInstancesSelectorParser->match($part)) {
                return array(self::T_ALL_INSTANCES_SELECTOR, $part);
            }
            if ($namedSelectorParser->match($part)) {
                return array(self::T_NAMED_SELECTOR, $part);
            }
            if ($methodCallParser->match($part)) {
                return array(self::T_METHOD_CALL, $part);
            }
            if ($propertyAccessParser->match($part)) {
                return array(self::T_PROPERTY_ACCESS, $part);
            }
            if ($arrayAccessParser->match($part)) {
                return array(self::T_ARRAY_ACCESS, $part);
            }
            return array(self::T_UNKNOWN, $part);
        });
        return new self($lexer);
    }