protected static function createArchiveForPhar(array $files, $archiveFileName)
    {
        if (preg_match('~^(.+)\.(tar\.(gz|bz2))$~i', $archiveFileName, $match)) {
            $ext = $match[2];
            $basename = $match[1];
        } else {
            $ext = pathinfo($archiveFileName, PATHINFO_EXTENSION);
            $basename = dirname($archiveFileName).'/'.basename($archiveFileName, '.'.$ext);
        }
        $tar = new PharData($basename.'.tar', 0, null, Phar::TAR);

        try {
            foreach ($files as $localName => $filename) {
                if (is_null($filename)) {
                    if (!in_array($localName, ['/', ''], true)) {
                        if ($tar->addEmptyDir($localName) === false) {
                            return false;
                        }
                    }
                } else {
                    if ($tar->addFile($filename, $localName) === false) {
                        return false;
                    }
                }
            }
        } catch (Exception $e) {
            return false;
        }

        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $tar->compress(Phar::GZ, $ext);
                break;
            case 'bz2':
            case 'tbz2':
                $tar->compress(Phar::BZ2, $ext);
                break;
        }
        $tar = null;

        return count($files);
    }
protected static function createArchiveForPhar(array $files, $archiveFileName)
    {
        if (preg_match('~^(.+)\.(tar\.(gz|bz2))$~i', $archiveFileName, $match)) {
            $ext = $match[2];
            $basename = $match[1];
        } else {
            $ext = pathinfo($archiveFileName, PATHINFO_EXTENSION);
            $basename = dirname($archiveFileName).'/'.basename($archiveFileName, '.'.$ext);
        }
        $tar = new PharData($basename.'.tar', 0, null, Phar::TAR);

        try {
            foreach ($files as $localName => $filename) {
                if (is_null($filename)) {
                    if (!in_array($localName, ['/', ''], true)) {
                        if ($tar->addEmptyDir($localName) === false) {
                            return false;
                        }
                    }
                } else {
                    if ($tar->addFile($filename, $localName) === false) {
                        return false;
                    }
                }
            }
        } catch (Exception $e) {
            return false;
        }

        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $tar->compress(Phar::GZ, $ext);
                break;
            case 'bz2':
            case 'tbz2':
                $tar->compress(Phar::BZ2, $ext);
                break;
        }
        $tar = null;

        return count($files);
    }
protected static function createArchiveForPhar ( array $ files , $ archiveFileName ) { if ( preg_match ( '~^(.+)\.(tar\.(gz|bz2))$~i' , $ archiveFileName , $ match ) ) { $ ext = $ match [ 2 ] ; $ basename = $ match [ 1 ] ; } else { $ ext = pathinfo ( $ archiveFileName , PATHINFO_EXTENSION ) ; $ basename = dirname ( $ archiveFileName ) . '/' . basename ( $ archiveFileName , '.' . $ ext ) ; } $ tar = new PharData ( $ basename . '.tar' , 0 , null , Phar :: TAR ) ; try { foreach ( $ files as $ localName => $ filename ) { if ( is_null ( $ filename ) ) { if ( ! in_array ( $ localName , [ '/' , '' ] , true ) ) { if ( $ tar -> addEmptyDir ( $ localName ) === false ) { return false ; } } } else { if ( $ tar -> addFile ( $ filename , $ localName ) === false ) { return false ; } } } } catch ( Exception $ e ) { return false ; } switch ( strtolower ( pathinfo ( $ archiveFileName , PATHINFO_EXTENSION ) ) ) { case 'gz' : case 'tgz' : $ tar -> compress ( Phar :: GZ , $ ext ) ; break ; case 'bz2' : case 'tbz2' : $ tar -> compress ( Phar :: BZ2 , $ ext ) ; break ; } $ tar = null ; return count ( $ files ) ; }
Creates an archive via Phar library
@param array $files
@param $archiveFileName
@return bool
Creates an archive via Phar library