/**
  * Create a driver from a Doctrine metadata driver
  *
  * @param MappingDriver $omDriver
  * @return DriverInterface
  */
 public static function fromMetadataDriver(MappingDriver $omDriver)
 {
     if ($omDriver instanceof MappingDriverChain) {
         $drivers = array();
         foreach ($omDriver->getDrivers() as $nestedOmDriver) {
             $drivers[] = self::fromMetadataDriver($nestedOmDriver);
         }
         return new DriverChain($drivers);
     }
     if ($omDriver instanceof DoctrineAnnotationDriver) {
         return new AnnotationDriver($omDriver->getReader());
     }
     if ($omDriver instanceof DoctrineFileDriver) {
         $reflClass = new \ReflectionClass($omDriver);
         $driverName = $reflClass->getShortName();
         if ($omDriver instanceof SimplifiedYamlDriver || $omDriver instanceof SimplifiedXmlDriver) {
             $driverName = str_replace('Simplified', '', $driverName);
         }
         $class = 'Prezent\\Doctrine\\Translatable\\Mapping\\Driver\\' . $driverName;
         if (class_exists($class)) {
             return new $class($omDriver->getLocator());
         }
     }
     throw new \InvalidArgumentException('Cannot adapt Doctrine driver of class ' . get_class($omDriver));
 }
Exemple #2
0
 /**
  * Create a driver from a Doctrine metadata driver.
  *
  * @param MappingDriver $omDriver
  *
  * @return DriverInterface
  */
 protected function fromMetadataDriver(MappingDriver $omDriver)
 {
     if ($omDriver instanceof MappingDriverChain) {
         $drivers = array();
         foreach ($omDriver->getDrivers() as $nestedOmDriver) {
             $drivers[] = $this->fromMetadataDriver($nestedOmDriver);
         }
         return new DriverChain($drivers);
     }
     if ($omDriver instanceof DoctrineAnnotationDriver) {
         return new MergeableDriver($this->createAnnotationDriver($omDriver->getReader()));
     }
     if ($omDriver instanceof DoctrineFileDriver) {
         $reflClass = new \ReflectionClass($omDriver);
         $driverName = $reflClass->getShortName();
         if (strpos($driverName, 'Simplified') !== false) {
             $driverName = str_replace('Simplified', '', $driverName);
         }
         return new MergeableDriver(call_user_func(array(static::class, 'create' . $driverName), $omDriver->getLocator()));
     }
     throw new \InvalidArgumentException('Cannot adapt Doctrine driver of class ' . get_class($omDriver));
 }