You are here

public function AbstractClassMetadataFactory::getMetadataFor in Plug 7

Gets the class metadata descriptor for a class.

Parameters

string $className The name of the class.:

Return value

ClassMetadata

Throws

ReflectionException

MappingException

Overrides ClassMetadataFactory::getMetadataFor

1 call to AbstractClassMetadataFactory::getMetadataFor()
AbstractClassMetadataFactory::getAllMetadata in lib/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
Forces the factory to load the metadata of all classes known to the underlying mapping driver.

File

lib/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php, line 187

Class

AbstractClassMetadataFactory
The ClassMetadataFactory is used to create ClassMetadata objects that contain all the metadata mapping informations of a class which describes how a class should be mapped to a relational database.

Namespace

Doctrine\Common\Persistence\Mapping

Code

public function getMetadataFor($className) {
  if (isset($this->loadedMetadata[$className])) {
    return $this->loadedMetadata[$className];
  }

  // Check for namespace alias
  if (strpos($className, ':') !== false) {
    list($namespaceAlias, $simpleClassName) = explode(':', $className, 2);
    $realClassName = $this
      ->getFqcnFromAlias($namespaceAlias, $simpleClassName);
  }
  else {
    $realClassName = ClassUtils::getRealClass($className);
  }
  if (isset($this->loadedMetadata[$realClassName])) {

    // We do not have the alias name in the map, include it
    return $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
  }
  $loadingException = null;
  try {
    if ($this->cacheDriver) {
      if (($cached = $this->cacheDriver
        ->fetch($realClassName . $this->cacheSalt)) !== false) {
        $this->loadedMetadata[$realClassName] = $cached;
        $this
          ->wakeupReflection($cached, $this
          ->getReflectionService());
      }
      else {
        foreach ($this
          ->loadMetadata($realClassName) as $loadedClassName) {
          $this->cacheDriver
            ->save($loadedClassName . $this->cacheSalt, $this->loadedMetadata[$loadedClassName], null);
        }
      }
    }
    else {
      $this
        ->loadMetadata($realClassName);
    }
  } catch (MappingException $loadingException) {
    if (!($fallbackMetadataResponse = $this
      ->onNotFoundMetadata($realClassName))) {
      throw $loadingException;
    }
    $this->loadedMetadata[$realClassName] = $fallbackMetadataResponse;
  }
  if ($className !== $realClassName) {

    // We do not have the alias name in the map, include it
    $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
  }
  return $this->loadedMetadata[$className];
}