public function testUseDefinedDefaultStorage()
 {
     $this->storageManager->add('core', new MemoryStorage());
     $this->storageManager->add('storage', new LocalStorage());
     $this->storageManager->setDefault('storage');
     $this->assertEquals('storage', $this->storageManager->getDefault());
 }
Example #2
0
 /**
  * Upload Photo
  *
  * @param PhotoSourceInterface $photoSource
  * @param array $options Options available
  * <pre>
  * transform: options for transforming photo before saving
  * storage: storage system to save photo
  * </pre>
  * @return int|bool Photo ID if successful or false otherwise
  */
 public function upload(PhotoSourceInterface $photoSource, array $options = array())
 {
     $photoSource->process($this->options);
     if ($photoSource->isValid() == false) {
         // No need to go further if source is invalid
         return false;
     }
     $options = array_merge(array('transform' => array(), 'storage_name' => $this->storageManager->getDefault()), $options);
     $saveName = $this->generateOriginalSaveName($photoSource->getName());
     $storage = $this->getStorageManager()->get($options['storage_name']);
     $fileMime = $photoSource->getMime();
     if ($options['transform']) {
         // If we are to perform photo transformation during upload,
         // transformation specs are applied and the new photo is saved
         // as the original image
         list($uploadPath, $fileSize) = $this->transformPhoto($storage, FileUtils::createTempFile($photoSource->getFile(), $this->options['tmp_dir']), $saveName, $fileMime, $options['transform']);
     } else {
         // Just upload as is
         $fileSize = filesize($photoSource->getFile());
         $uploadPath = $storage->upload($photoSource->getFile(), $saveName, $options);
     }
     if ($uploadPath && $this->dataStore != null) {
         // Persist uploaded photo data
         return (int) $this->dataStore->addPhoto(array('storageName' => $options['storage_name'], 'filePath' => $uploadPath, 'fileSize' => $fileSize, 'fileName' => $photoSource->getName(), 'fileExtension' => FileUtils::getExtension($photoSource->getName()), 'fileMime' => $fileMime));
     }
     return false;
 }