Exemplo n.º 1
0
 public function getNamespaceContext()
 {
     $context = NULL;
     if (!$this->ref->isInternal()) {
         $file = $this->ref->getFileName();
         if (is_file($file) && is_readable($file)) {
             $parser = new SourceParser();
             $storage = new ArraySourceStorage();
             $parser->parse(SourceStream::fromUrl($file), $storage);
             $type = NULL;
             foreach ($storage->getTypes() as $tmp) {
                 if ($tmp->getName() === $this->ref->getName()) {
                     $type = $tmp;
                     break;
                 }
             }
             if ($type instanceof ParsedType) {
                 $context = $type->getNamespaceContext();
             }
         }
     }
     if ($context === NULL) {
         return new NamespaceContext($this->ref->getNamespaceName());
     }
     return $context;
 }
Exemplo n.º 2
0
 public function getNodes()
 {
     $nodes = [];
     foreach ($this->files as $file) {
         $entry = $this->path . DIRECTORY_SEPARATOR . $file . '.php';
         if (!is_file($entry)) {
             throw new \InvalidArgumentException(sprintf('Type "%s" not found at "%s"', $file, $entry));
         }
         $info = new \SplFileInfo($entry);
         $parser = new SourceParser();
         $storage = new ArraySourceStorage();
         $buffer = $parser->parse(SourceStream::fromUrl($info->getPathname()), $storage);
         foreach ($storage->getTypes() as $type) {
             $nodes[] = $this->createNode($type, $buffer, $info);
         }
     }
     return $nodes;
 }
Exemplo n.º 3
0
 public function getNodes()
 {
     $nodes = [];
     foreach ($this->it as $entry) {
         if ($entry->isFile() && 'php' == pathinfo($entry->getFilename(), PATHINFO_EXTENSION)) {
             $name = pathinfo($entry->getFilename(), PATHINFO_FILENAME);
             foreach ($this->exclude as $pattern) {
                 $pattern = "'^" . strtr($pattern, ['.' => '\\.', '*' => '[^/\\\\]+', '**' => '.+']) . "\$'i";
                 if (preg_match($pattern, $name)) {
                     continue 2;
                 }
             }
             $storage = new ArraySourceStorage();
             $parser = new SourceParser();
             $buffer = $parser->parse(SourceStream::fromUrl($entry->getPathname()), $storage);
             foreach ($storage->getTypes() as $type) {
                 $nodes[] = $this->createNode($type, $buffer, clone $entry);
             }
         }
     }
     return $nodes;
 }
Exemplo n.º 4
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);
 }