Пример #1
0
 /**
  * @param $container
  * @param $name
  *
  * @return string
  */
 private static function removeContainerFromName($container, $name)
 {
     $name = static::asLocalPath($name);
     if (empty($container)) {
         return $name;
     }
     $container = FileUtilities::fixFolderPath($container);
     return substr($name, strlen($container) + 1);
 }
Пример #2
0
 /**
  * @param array  $data Array of sub-folder and file paths that are relative to the root folder
  * @param string $root root folder from which to delete
  * @param  bool  $force
  *
  * @return array
  * @throws \DreamFactory\Core\Exceptions\BadRequestException
  */
 protected function deleteFolderContent($data, $root = '', $force = false)
 {
     $root = FileUtilities::fixFolderPath($root);
     $out = [];
     if (!empty($data)) {
         foreach ($data as $key => $resource) {
             $path = ArrayUtils::get($resource, 'path');
             $name = ArrayUtils::get($resource, 'name');
             if (!empty($path)) {
                 $fullPath = $path;
             } else {
                 if (!empty($name)) {
                     $fullPath = $root . '/' . $name;
                 } else {
                     throw new BadRequestException('No path or name provided for resource.');
                 }
             }
             switch (ArrayUtils::get($resource, 'type')) {
                 case 'file':
                     $out[$key] = ['name' => $name, 'path' => $path, 'type' => 'file'];
                     try {
                         $this->driver->deleteFile($this->container, $fullPath);
                     } catch (\Exception $ex) {
                         $out[$key]['error'] = ['message' => $ex->getMessage()];
                     }
                     break;
                 case 'folder':
                     $out[$key] = ['name' => $name, 'path' => $path, 'type' => 'folder'];
                     try {
                         $this->driver->deleteFolder($this->container, $fullPath, $force);
                     } catch (\Exception $ex) {
                         $out[$key]['error'] = ['message' => $ex->getMessage()];
                     }
                     break;
             }
         }
     }
     return $out;
 }
 /**
  * @param array $config
  *
  * @throws InvalidArgumentException
  * @throws DfException
  */
 public function __construct($config)
 {
     $storageType = strtolower(ArrayUtils::get($config, 'storage_type'));
     $credentials = $config;
     $this->container = ArrayUtils::get($config, 'container');
     Session::replaceLookups($credentials, true);
     switch ($storageType) {
         case 'rackspace cloudfiles':
             $authUrl = ArrayUtils::get($credentials, 'url', 'https://identity.api.rackspacecloud.com/');
             $region = ArrayUtils::get($credentials, 'region', 'DFW');
             break;
         default:
             $authUrl = ArrayUtils::get($credentials, 'url');
             $region = ArrayUtils::get($credentials, 'region');
             break;
     }
     $username = ArrayUtils::get($credentials, 'username');
     $password = ArrayUtils::get($credentials, 'password');
     $apiKey = ArrayUtils::get($credentials, 'api_key');
     $tenantName = ArrayUtils::get($credentials, 'tenant_name');
     if (empty($authUrl)) {
         throw new InvalidArgumentException('Object Store authentication URL can not be empty.');
     }
     if (empty($username)) {
         throw new InvalidArgumentException('Object Store username can not be empty.');
     }
     $secret = ['username' => $username];
     if (empty($apiKey)) {
         if (empty($password)) {
             throw new InvalidArgumentException('Object Store credentials must contain an API key or a password.');
         }
         $secret['password'] = $password;
     } else {
         $secret['apiKey'] = $apiKey;
     }
     if (!empty($tenantName)) {
         $secret['tenantName'] = $tenantName;
     }
     if (empty($region)) {
         throw new InvalidArgumentException('Object Store region can not be empty.');
     }
     try {
         switch ($storageType) {
             case 'rackspace cloudfiles':
                 $pos = stripos($authUrl, '/v');
                 if (false !== $pos) {
                     $authUrl = substr($authUrl, 0, $pos);
                 }
                 $authUrl = FileUtilities::fixFolderPath($authUrl) . 'v2.0';
                 $os = new Rackspace($authUrl, $secret);
                 break;
             default:
                 $os = new OpenStack($authUrl, $secret);
                 break;
         }
         $this->blobConn = $os->ObjectStore('cloudFiles', $region);
         if (!$this->containerExists($this->container)) {
             $this->createContainer(['name' => $this->container]);
         }
     } catch (\Exception $ex) {
         throw new DfException('Failed to launch OpenStack service: ' . $ex->getMessage());
     }
 }
Пример #4
0
 /**
  * @param $container
  * @param $path
  *
  * @return string
  */
 private static function removeContainerFromPath($container, $path)
 {
     if (empty($container)) {
         return $path;
     }
     $container = FileUtilities::fixFolderPath($container);
     return substr($path, strlen($container));
 }