Пример #1
0
 /**
  * Handles GET actions.
  *
  * @return \DreamFactory\Core\Utility\ServiceResponse
  */
 protected function handleGET()
 {
     if (empty($this->folderPath) && empty($this->filePath) && $this->request->getParameterAsBool(ApiOptions::AS_ACCESS_LIST)) {
         return ResourcesWrapper::wrapResources($this->getAccessList());
     }
     if (empty($this->filePath)) {
         //Resource is the root/container or a folder
         if ($this->request->getParameterAsBool('zip')) {
             $zipFileName = $this->driver->getFolderAsZip($this->container, $this->folderPath);
             FileUtilities::sendFile($zipFileName, true);
             unlink($zipFileName);
             // output handled by file handler, short the response here
             $this->setNativeFormat(null);
             $result = null;
         } elseif ($this->request->getParameterAsBool('include_properties')) {
             $result = $this->driver->getFolderProperties($this->container, $this->folderPath);
         } else {
             $result = $this->driver->getFolder($this->container, $this->folderPath, $this->request->getParameterAsBool('include_files', true), $this->request->getParameterAsBool('include_folders', true), $this->request->getParameterAsBool('full_tree', false));
             $asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
             $idField = $this->request->getParameter(ApiOptions::ID_FIELD, $this->getResourceIdentifier());
             $fields = $this->request->getParameter(ApiOptions::FIELDS, ApiOptions::FIELDS_ALL);
             $result = ResourcesWrapper::cleanResources($result, $asList, $idField, $fields, true);
         }
     } else {
         //Resource is a file
         if ($this->request->getParameterAsBool('include_properties', false)) {
             // just properties of the file itself
             $content = $this->request->getParameterAsBool('content', false);
             $result = $this->driver->getFileProperties($this->container, $this->filePath, $content);
         } else {
             $download = $this->request->getParameterAsBool('download', false);
             // stream the file, exits processing
             $this->streamFile($this->container, $this->filePath, $download);
             // output handled by file handler, short the response here
             $this->setNativeFormat(null);
             $result = null;
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * @param string $container
  * @param string $path
  * @param bool   $download
  *
  * @throws \DreamFactory\Core\Exceptions\NotFoundException
  */
 public function streamFile($container, $path, $download = false)
 {
     $file = static::addContainerToName($container, $path);
     if (!is_file($file)) {
         throw new NotFoundException("The specified file '" . $path . "' was not found in storage.");
     }
     FileUtilities::sendFile($file, $download);
 }
Пример #3
0
 /**
  * @param bool|true  $includeFiles
  * @param bool|false $includeData
  *
  * @return null
  * @throws \DreamFactory\Core\Exceptions\NotFoundException
  * @throws \Exception
  */
 public function exportAppAsPackage($includeFiles = true, $includeData = false)
 {
     /** @type App $app */
     $app = App::find($this->exportAppId);
     if (empty($app)) {
         throw new NotFoundException('App not found in database with app id - ' . $this->exportAppId);
     }
     $appName = $app->name;
     try {
         $this->initExportZipFile($appName);
         $this->packageAppDescription($app);
         $this->packageServices();
         $this->packageSchemas();
         if ($includeData) {
             $this->packageData();
         }
         if ($app->type === AppTypes::STORAGE_SERVICE && $includeFiles) {
             $this->packageAppFiles($app);
         }
         $this->zip->close();
         FileUtilities::sendFile($this->zipFilePath, true);
         return null;
     } catch (\Exception $e) {
         //Do necessary things here.
         throw $e;
     }
 }