/**
  * (non-PHPdoc).
  *
  * @see \Mathielen\ImportEngine\Storage\Format\Discovery\FormatDiscoverStrategyInterface::getFormat()
  */
 public function getFormat(StorageSelection $selection)
 {
     $mimeType = $this->mimetypeDiscoverer->discoverMimeType($selection->getId());
     list($mimeType, $subInformation) = array_pad(explode(' ', $mimeType), 2, null);
     $type = $this->mimeTypeToFormat($mimeType, $selection->getId(), $subInformation);
     return $type;
 }
 public function getConnection(StorageSelection $selection = null)
 {
     $id = $selection ? $selection->getId() : null;
     if (!$id || !isset($this->connections[$id])) {
         $id = 'default';
     }
     return $this->connections[$id];
 }
Пример #3
0
 /**
  * @return StorageInterface
  */
 public function getStorage(StorageSelection $selection)
 {
     if (!isset($this->storageCache[$selection])) {
         $provider = $this->get($selection->getProviderId());
         $storage = $provider->storage($selection);
         $this->storageCache[$selection] = $storage;
     }
     return $this->storageCache[$selection];
 }
 /**
  * (non-PHPdoc).
  *
  * @see \Mathielen\ImportEngine\Storage\Provider\StorageProviderInterface::storage()
  */
 public function storage(StorageSelection $selection)
 {
     $callable = $selection->getImpl();
     $arguments = array();
     if (is_array($callable) && isset($callable['arguments'])) {
         $arguments = $callable['arguments'];
         unset($callable['arguments']);
     } elseif (!is_callable($callable)) {
         throw new \InvalidArgumentException('StorageSelection must contain a callable or an extended callable (with arguments) as impl');
     }
     return new ServiceStorage($callable, $arguments);
 }
 /**
  * (non-PHPdoc).
  *
  * @see \Mathielen\ImportEngine\Storage\Factory\StorageFactoryInterface::factor()
  */
 public function factor(StorageSelection $selection)
 {
     $file = $selection->getImpl();
     if (!$file instanceof \SplFileInfo) {
         throw new InvalidConfigurationException('StorageSelection does not contain a SplFileInfo as impl property but this is mandatory for a LocalFileStorage.');
     }
     if (!$file->isFile() || !$file->isReadable()) {
         throw new InvalidConfigurationException('StorageSelection references a File that does not exists or is not readable.');
     }
     $format = $selection->getMetadata('format');
     if (!$format) {
         $format = $this->formatDiscoverStrategyInterface->getFormat($selection);
         if (!$format) {
             throw new InvalidConfigurationException('Could not discover format!');
         }
         if ($this->logger) {
             $this->logger->info("File {$file} was discovered as format '{$format}'", ['selection' => $selection->toArray()]);
         }
     }
     $localFile = new LocalFileStorage($file, $format);
     return $localFile;
 }
 /**
  * (non-PHPdoc).
  *
  * @see \Mathielen\ImportEngine\Storage\Format\Discovery\FormatDiscoverStrategyInterface::getFormat()
  */
 public function getFormat(StorageSelection $selection)
 {
     $ext = pathinfo($selection->getId(), PATHINFO_EXTENSION);
     $type = $this->discoverFormat($ext, $selection->getId());
     return $type;
 }