コード例 #1
0
 /**
  * Get the best storage based on request and/or parameters.
  *
  * @param  UploadContext                                    $context
  * @throws \SRIO\RestUploadBundle\Exception\UploadException
  * @throws \RuntimeException
  * @return FileStorage
  */
 public function getStorage(UploadContext $context)
 {
     if (count($this->storages) == 0) {
         throw new UploadException('No storage found');
     }
     if (($storageName = $context->getStorageName()) !== null || ($storageName = $this->defaultStorage) !== null) {
         if (!array_key_exists($storageName, $this->storages)) {
             throw new \RuntimeException(sprintf('Storage with name %s do not exists', $storageName));
         }
         return $this->storages[$storageName];
     }
     return current($this->storages);
 }