Chumper\Zipper\Zipper::make PHP Method

make() public method

Create a new zip Archive if the file does not exists opens a zip archive if the file exists
public make ( $pathToFile, Chumper\Zipper\Repositories\RepositoryInterface | string $type = 'zip' )
$pathToFile string The file to open
$type Chumper\Zipper\Repositories\RepositoryInterface | string The type of the archive, defaults to zip, possible are zip, phar
    public function make($pathToFile, $type = 'zip')
    {
        $new = $this->createArchiveFile($pathToFile);
        $this->filePath = $pathToFile;
        $name = 'Chumper\\Zipper\\Repositories\\' . ucwords($type) . 'Repository';
        if (is_subclass_of($name, 'Chumper\\Zipper\\Repositories\\RepositoryInterface')) {
            $this->repository = new $name($pathToFile, $new);
        } else {
            //TODO $type should be a class name and not a string
            $this->repository = $type;
        }
        return $this;
    }

Usage Example

 /**
  * Creates a new zip file and returns the complete file path.
  *
  * @return string
  */
 public function handle()
 {
     if ($this->batch->files->count() > 0) {
         $fileName = $this->generateFileName($this->batch->name);
         $zip = $this->zipper->make($fileName);
         foreach ($this->batch->files as $file) {
             if ($file instanceof Upload) {
                 $zip->add($file->getCompletePath());
             }
         }
         $path = $zip->getFilePath();
         $zip->close();
         return $path;
     }
     return false;
 }
All Usage Examples Of Chumper\Zipper\Zipper::make