| 1 | <?php |
||
| 10 | abstract class AbstractFileDriver implements AdvancedDriverInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var FileLocatorInterface|FileLocator |
||
| 14 | */ |
||
| 15 | private $locator; |
||
| 16 | |||
| 17 | public function __construct(FileLocatorInterface $locator) |
||
| 21 | |||
| 22 | public function loadMetadataForClass(\ReflectionClass $class) |
||
| 23 | { |
||
| 24 | if (null === $path = $this->locator->findFileForClass($class, $this->getExtension())) { |
||
| 25 | return null; |
||
| 26 | } |
||
| 27 | |||
| 28 | return $this->loadMetadataFromFile($class, $path); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritDoc} |
||
| 33 | */ |
||
| 34 | public function getAllClassNames() |
||
| 35 | { |
||
| 36 | if (!$this->locator instanceof AdvancedFileLocatorInterface) { |
||
| 37 | throw new \RuntimeException('Locator "%s" must be an instance of "AdvancedFileLocatorInterface".'); |
||
| 38 | } |
||
| 39 | |||
| 40 | return $this->locator->findAllClasses($this->getExtension()); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Parses the content of the file, and converts it to the desired metadata. |
||
| 45 | * |
||
| 46 | * @param \ReflectionClass $class |
||
| 47 | * @param string $file |
||
| 48 | * |
||
| 49 | * @return \Metadata\ClassMetadata|null |
||
| 50 | */ |
||
| 51 | abstract protected function loadMetadataFromFile(\ReflectionClass $class, $file); |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns the extension of the file. |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | abstract protected function getExtension(); |
||
| 59 | } |
||
| 60 |