private function fileCompress()
    {
        if ($this->file && $this->file->getTmp()) {
            $compression = $this->file->getCompression();
            if ($compression && in_array($compression, ['tar.gz', 'tar.bz2', 'zip'])) {
                // Discern new tmp file name (with compression applied).
                $target   = $this->fileGenerateTmp($compression);
                $fileName = $this->getFileName();
                try {
                    switch ($compression) {
                        case 'tar.gz':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::GZ, $compression);
                            $target = $phar->getRealPath();
                            break;

                        case 'tar.bz2':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::BZ2, $compression);
                            $target = $phar->getRealPath();
                            break;

                        default:
                        case 'zip':
                            $zip = new \ZipArchive();
                            if (true !== $zip->open($target, \ZipArchive::CREATE)) {
                                throw new ContactClientException(
                                    'Cound not open zip '.$target,
                                    Codes::HTTP_INTERNAL_SERVER_ERROR,
                                    null,
                                    Stat::TYPE_ERROR,
                                    false
                                );
                            }
                            $zip->addFile($this->file->getTmp(), $fileName);
                            $zip->close();
                            break;
                    }
                    $this->file->setTmp($target);
                    $this->setLogs($target, 'fileCompressed');
                } catch (\Exception $e) {
                    throw new ContactClientException(
                        'Could not create compressed file '.$target,
                        Codes::HTTP_INTERNAL_SERVER_ERROR,
                        $e,
                        Stat::TYPE_ERROR,
                        false
                    );
                }
            } else {
                $this->setLogs(false, 'fileCompressed');
            }
        }

        return $this;
    }
private function fileCompress()
    {
        if ($this->file && $this->file->getTmp()) {
            $compression = $this->file->getCompression();
            if ($compression && in_array($compression, ['tar.gz', 'tar.bz2', 'zip'])) {
                // Discern new tmp file name (with compression applied).
                $target   = $this->fileGenerateTmp($compression);
                $fileName = $this->getFileName();
                try {
                    switch ($compression) {
                        case 'tar.gz':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::GZ, $compression);
                            $target = $phar->getRealPath();
                            break;

                        case 'tar.bz2':
                            $phar = new \PharData($target);
                            $phar->addFile($this->file->getTmp(), $fileName);
                            $phar->compress(\Phar::BZ2, $compression);
                            $target = $phar->getRealPath();
                            break;

                        default:
                        case 'zip':
                            $zip = new \ZipArchive();
                            if (true !== $zip->open($target, \ZipArchive::CREATE)) {
                                throw new ContactClientException(
                                    'Cound not open zip '.$target,
                                    Codes::HTTP_INTERNAL_SERVER_ERROR,
                                    null,
                                    Stat::TYPE_ERROR,
                                    false
                                );
                            }
                            $zip->addFile($this->file->getTmp(), $fileName);
                            $zip->close();
                            break;
                    }
                    $this->file->setTmp($target);
                    $this->setLogs($target, 'fileCompressed');
                } catch (\Exception $e) {
                    throw new ContactClientException(
                        'Could not create compressed file '.$target,
                        Codes::HTTP_INTERNAL_SERVER_ERROR,
                        $e,
                        Stat::TYPE_ERROR,
                        false
                    );
                }
            } else {
                $this->setLogs(false, 'fileCompressed');
            }
        }

        return $this;
    }
private function fileCompress ( ) { if ( $ this -> file && $ this -> file -> getTmp ( ) ) { $ compression = $ this -> file -> getCompression ( ) ; if ( $ compression && in_array ( $ compression , [ 'tar.gz' , 'tar.bz2' , 'zip' ] ) ) { // Discern new tmp file name (with compression applied). $ target = $ this -> fileGenerateTmp ( $ compression ) ; $ fileName = $ this -> getFileName ( ) ; try { switch ( $ compression ) { case 'tar.gz' : $ phar = new \ PharData ( $ target ) ; $ phar -> addFile ( $ this -> file -> getTmp ( ) , $ fileName ) ; $ phar -> compress ( \ Phar :: GZ , $ compression ) ; $ target = $ phar -> getRealPath ( ) ; break ; case 'tar.bz2' : $ phar = new \ PharData ( $ target ) ; $ phar -> addFile ( $ this -> file -> getTmp ( ) , $ fileName ) ; $ phar -> compress ( \ Phar :: BZ2 , $ compression ) ; $ target = $ phar -> getRealPath ( ) ; break ; default : case 'zip' : $ zip = new \ ZipArchive ( ) ; if ( true !== $ zip -> open ( $ target , \ ZipArchive :: CREATE ) ) { throw new ContactClientException ( 'Cound not open zip ' . $ target , Codes :: HTTP_INTERNAL_SERVER_ERROR , null , Stat :: TYPE_ERROR , false ) ; } $ zip -> addFile ( $ this -> file -> getTmp ( ) , $ fileName ) ; $ zip -> close ( ) ; break ; } $ this -> file -> setTmp ( $ target ) ; $ this -> setLogs ( $ target , 'fileCompressed' ) ; } catch ( \ Exception $ e ) { throw new ContactClientException ( 'Could not create compressed file ' . $ target , Codes :: HTTP_INTERNAL_SERVER_ERROR , $ e , Stat :: TYPE_ERROR , false ) ; } } else { $ this -> setLogs ( false , 'fileCompressed' ) ; } } return $ this ; }
Perform compression on the temp file.

@return $this

@throws ContactClientException
Perform compression on the temp file .