コード例 #1
0
ファイル: AnnotationDriver.php プロジェクト: bedrest/bedrest
 /**
  * {@inheritDoc}
  *
  * This has been lifted pretty much wholesale from Doctrine ORM, so credit where credit is due.
  * @see Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver
  */
 public function getAllClassNames()
 {
     if (!$this->paths) {
         throw Exception::pathsRequired();
     }
     $classes = array();
     $includedFiles = array();
     foreach ($this->paths as $path) {
         if (!is_dir($path)) {
             throw Exception::invalidPath($path);
         }
         $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY), '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach ($iterator as $file) {
             $sourceFile = realpath($file[0]);
             require_once $sourceFile;
             $includedFiles[] = $sourceFile;
         }
     }
     $declared = get_declared_classes();
     foreach ($declared as $className) {
         $rc = new \ReflectionClass($className);
         $sourceFile = $rc->getFileName();
         if (in_array($sourceFile, $includedFiles) && $this->isService($className)) {
             $classes[] = $className;
         }
     }
     return $classes;
 }
コード例 #2
0
 /**
  * Returns ServiceMetadata for the specified class.
  *
  * @param  string                                   $className
  * @throws \BedRest\Service\Mapping\Exception
  * @return \BedRest\Service\Mapping\ServiceMetadata
  */
 public function getMetadataFor($className)
 {
     if (!$this->isService($className)) {
         throw Exception::classIsNotMappedService($className);
     }
     if (!isset($this->loadedMetadata[$className])) {
         $this->loadMetadata($className);
     }
     if ($this->cache) {
         $cacheId = $this->cachePrefix . $className . $this->cacheSuffix;
         if (($cached = $this->cache->fetch($cacheId)) !== false) {
             $this->loadedMetadata[$className] = $cached;
         } else {
             $this->loadMetadata($className);
             $this->cache->save($cacheId, $this->loadedMetadata[$className], null);
         }
     } else {
         $this->loadMetadata($className);
     }
     return $this->loadedMetadata[$className];
 }