Example #1
0
 protected function parseVisibility(PointcutTokenCursor $cursor)
 {
     $tok = $cursor->current();
     $visibility = 0;
     while ($tok->isOneOf([PointcutToken::T_PUBLIC, PointcutToken::T_PROTECTED, PointcutToken::T_PRIVATE])) {
         $visibility |= MetaInfo::getVisibilityModifier((string) $tok);
         $tok = $cursor->consume();
         if ($tok->is(PointcutToken::T_PIPE)) {
             $tok = $cursor->consume();
         }
     }
     if ($visibility != 0) {
         $cursor->move(-1);
     }
     return $visibility;
 }
Example #2
0
 public function parseFile($file, $key = NULL)
 {
     $mtime = filemtime($file);
     $hash = md5($file) . dechex(strlen($file));
     $sql = 'SELECT * FROM "meta_file" WHERE "hash" = :hash AND "mtime" >= :mtime LIMIT 1';
     $stmt = $this->pdo->prepare($sql);
     $stmt->bindValue('hash', $hash);
     $stmt->bindValue('mtime', $mtime);
     $stmt->execute();
     $row = $stmt->fetch(\PDO::FETCH_ASSOC);
     if ($row !== false) {
         return new MetaFile($row['hash'], $row['location'], $row['mtime'], unserialize(gzdecode($row['storage'])), unserialize(gzdecode($row['buffer'])));
     }
     $storage = new ArraySourceStorage();
     $parser = new SourceParser();
     $buffer = $parser->parse(SourceStream::fromUrl($file), $storage);
     $this->insertFileStmt->execute(['hash' => $hash, 'location' => $file, 'mtime' => $mtime, 'key' => $key, 'storage' => gzencode(serialize($storage), 1), 'buffer' => gzencode(serialize($buffer), 1)]);
     foreach ($storage->getTypes() as $type) {
         $typeInfo = new ParsedTypeInfo($type, [], []);
         $this->insertTypeStmt->execute(['name' => $typeInfo->getName(), 'file' => $hash, 'mod' => MetaInfo::getTypeModifiers($typeInfo), 'mtime' => $mtime, 'data' => gzencode(serialize($type), 1)]);
         foreach ($type->getSupertypes() as $supertype) {
             $this->insertSupertypeStmt->execute(['super' => $supertype, 'sub' => $typeInfo->getName()]);
         }
         foreach ($typeInfo->getAnnotationCandidates() as $anno) {
             $this->insertTypeAnnotationStmt->execute(['type' => $typeInfo->getName(), 'anno' => $anno]);
         }
         foreach ($storage->getFields($type) as $field) {
             $fieldInfo = new ParsedFieldInfo($typeInfo, $field);
             $this->insertFieldStmt->execute(['type' => $type->getName(), 'field' => $fieldInfo->getName(), 'mod' => MetaInfo::getFieldModifiers($fieldInfo)]);
             foreach ($fieldInfo->getAnnotationCandidates() as $anno) {
                 $this->insertFieldAnnotationStmt->execute(['type' => $typeInfo->getName(), 'field' => $field->getName(), 'anno' => $anno]);
             }
         }
         foreach ($storage->getMethods($type) as $method) {
             $methodInfo = new ParsedMethodInfo($typeInfo, $method);
             $this->insertMethodStmt->execute(['type' => $type->getName(), 'method' => $methodInfo->getName(), 'mod' => MetaInfo::getMethodModifiers($methodInfo)]);
             foreach ($methodInfo->getAnnotationCandidates() as $anno) {
                 $this->insertMethodAnnotationStmt->execute(['type' => $type->getName(), 'method' => $methodInfo->getName(), 'anno' => $anno]);
             }
         }
         $comment = new DocComment($type->getComment());
         foreach ($comment->getTagValues('merge') as $group) {
             $this->insertMergeGroupStmt->execute(['type' => $typeInfo->getName(), 'group' => trim($group)]);
         }
         $this->typeCache[strtolower($type->getName())] = new ParsedTypeInfo($type, $storage->getFields($type), $storage->getMethods($type));
     }
     return new MetaFile($hash, $file, $mtime, $storage, $buffer);
 }