当前位置: 首页>>代码示例>>PHP>>正文


PHP Phar::compress方法代码示例

本文整理汇总了PHP中Phar::compress方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::compress方法的具体用法?PHP Phar::compress怎么用?PHP Phar::compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phar的用法示例。


在下文中一共展示了Phar::compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addCompress

 /**
  * Add compress to phar file.
  *
  * @param \Phar $phar          PHAR object to update.
  * @param int[] $configuration List of compress types.
  *
  * @throws \yii\base\InvalidConfigException On wrong compress type set (index0h\phar\Module::compress).
  */
 public static function addCompress(\Phar $phar, $configuration)
 {
     if ($configuration === false) {
         return;
     }
     echo "\nAdd compress";
     foreach ($configuration as $compress) {
         if (in_array($compress, [\Phar::NONE, \Phar::GZ, \Phar::BZ2], true) === false) {
             throw new InvalidConfigException("Invalid configuration. Unknown compress type '{$compress}'.");
         }
         if (\Phar::canCompress($compress) === true) {
             $phar->compress($compress);
         }
     }
 }
开发者ID:index0h,项目名称:yii2-phar,代码行数:23,代码来源:Builder.php

示例2: build

 public function build()
 {
     $this->prepareTemp();
     /* Dateien ins Temp-Verzeichnis kopieren */
     $class2path = array();
     $relDir = $this->classPath->up();
     // wir wollen ja den Namespace als erstes Verzeichnis haben
     foreach ($this->getClassFiles() as $file) {
         $class = $this->inferClassName($file);
         // $class2path[ $class ] = $fileURL;
         $class2path[ltrim($class, '\\')] = $url = $file->getURL($relDir);
         // statt hier Code::mapClassToFile() zu machen nehmen wir die url
         $targetFile = File::createFromURL($url, $this->tempSrc);
         $targetFile->getDirectory()->create();
         $this->log(str_pad('Add: ' . $url, 80, ' ', STR_PAD_RIGHT) . " [" . $class . "]", 2);
         $file->copy($targetFile);
     }
     foreach ($this->additionalFiles as $list) {
         list($file, $fileInPhar) = $list;
         $targetFile = new File($this->tempSrc . $fileInPhar);
         $targetFile->getDirectory()->create();
         $this->log('Add: ' . $fileInPhar);
         $file->copy($targetFile);
     }
     /* Bootstrapping */
     $bootstrapCode = $this->getBootstrapCode($class2path);
     $bootstrapFile = new File($this->tempSrc, 'index.php');
     $bootstrapFile->writeContents($bootstrapCode);
     /* Build */
     try {
         $tmp = File::createTemporary();
         $tmp->setExtension('phar.gz');
         $this->phar = new PHPPhar((string) $tmp);
         $this->phar->compress(PHPPHAR::GZ);
         $this->phar->startBuffering();
         $this->phar->buildFromDirectory($this->tempSrc);
         $this->phar->stopBuffering();
         $this->tempSrc->delete();
         $this->out->delete();
         $tmp->copy($this->out);
     } catch (\Exception $e) {
         $this->tempSrc->delete();
         throw $e;
     }
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:45,代码来源:Phar.php

示例3: dir

 $lListeArchive = ' ';
 $d = dir($lPath);
 while (false !== ($entry = $d->read())) {
     if ($entry != '.' && $entry != '..') {
         $lListeArchive .= $entry . ' ';
     }
 }
 $d->close();
 include $lPath . "/configuration/Version.php";
 // Création de l'archive
 //$output = shell_exec('cd ' . $lPath . ' && tar -czvf zeybux-' . $lEnv . '-' . ZEYBUX_VERSION . '.tar.gz' . $lListeArchive . ' && chmod -R 777 .');
 //echo $output;
 $lVersion = str_replace('.', '-', ZEYBUX_VERSION);
 $phar = new Phar($lPath . '/zeybux_' . $lEnv . '_' . $lVersion . '.phar', 0, 'zeybux_' . $lEnv . '_' . ZEYBUX_VERSION . '.phar');
 $phar->buildFromDirectory($lPath);
 $phar->compress(Phar::BZ2);
 $phar->stopBuffering();
 shell_exec('cd ' . $lPath . ' && chmod -R 777 .');
 if ($lEnv == 'install') {
     copy($lDossierVersionSource . '/install/install.php', $lPath . '/install.php');
     // Le script d'installation
     $output = shell_exec('cd ' . $lPath . ' && chmod -R 777 .');
 }
 /*** Suppression des fichiers de travail ***/
 /** CSS **/
 unlink('./zeybu/css/zeybux-html-min.css');
 unlink('./zeybu/css/zeybux-html.css');
 unlink('./zeybu/css/zeybux-min.css');
 unlink('./zeybu/css/zeybux.css');
 /*** Js ***/
 unlink('./zeybu/js/zeybux-core-min.js');
开发者ID:google-code-backups,项目名称:zeybux,代码行数:31,代码来源:ExportZeybux.php

示例4: testReadingEntirePharCompressed

    /**
     * Test that the reading is successful.
     *
     * @return void
     *
     * @dataProvider testReadingFlagsProvider
     */
    public function testReadingEntirePharCompressed($compression, $signatureName, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setStub(<<<EOF
#!/usr/bin/php
<?php

/*STUB!*/
__HALT_COMPILER();
?>
EOF
);
        $phar->stopBuffering();
        if (0 !== $signatureFlag) {
            $phar->setSignatureAlgorithm($signatureFlag);
        }
        if ($compression !== \Phar::NONE) {
            $phar->compress($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $this->assertEquals('temp.phar', $phar->getAlias());
        $this->assertTrue($phar->isSigned());
        $this->assertEquals($signatureName, $phar->getSignatureAlgorithm());
        $files = $phar->getFiles();
        $this->assertEquals('bin/script', $files[0]->getFilename());
        $this->assertEquals($fileData, $files[0]->getContent());
    }
开发者ID:cyberspectrum,项目名称:pharpiler,代码行数:44,代码来源:PharReaderTest.php

示例5: dirname

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.gz';
$pname = 'phar://' . $fname;
$file = '<?php __HALT_COMPILER(); ?>';
$files = array();
$files['a'] = 'a';
$files['b'] = 'b';
$files['c'] = 'c';
include 'files/phar_test.inc';
$phar = new Phar($fname);
$gz = $phar->compress(Phar::GZ);
copy($gz->getPath(), $fname2);
$a = new Phar($fname2);
var_dump($a->isCompressed());
$unc = $a->compress(Phar::NONE);
echo $unc->getPath() . "\n";
$unc2 = $gz->decompress();
echo $unc2->getPath() . "\n";
$unc3 = $gz->decompress('hooba.phar');
echo $unc3->getPath() . "\n";
$gz->decompress(array());
$zip = $phar->convertToData(Phar::ZIP);
ini_set('phar.readonly', 1);
try {
    $gz->decompress();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
try {
    $zip->decompress();
开发者ID:alphaxxl,项目名称:hhvm,代码行数:30,代码来源:phar_decompress.php

示例6: switch

            $archive->setSignatureAlgorithm(Phar::OPENSSL, $keyfile);
            break;
        default:
            echo "Warning: A level of encryption has been specified, but is invalid\n";
    }
}
//
//  Compression
//
$compression = $cmd->getArg("c");
if ($compression) {
    switch ($compression) {
        case "none":
            break;
        case "bzip":
            $archive->compress(Phar::BZ2);
            break;
        case "tar":
            $archive->compress(Phar::GZ);
            break;
        default:
            echo "Warning: A level of compression of was specified, but is invalid\n";
    }
}
//
//  Process the files to be added to the archive
//
$files = $cmd->getArg("f");
if ($files === null) {
    echo "Warning: no files have been specified for adding to the library\n";
} else {
开发者ID:rawebone,项目名称:to.phar,代码行数:31,代码来源:to.phar.php

示例7: getPharStub

        if ($versionFile === false) {
            throw new Exception("Could not locate the VERSION file.");
        }
        $version = trim(fgets($versionFile));
        fclose($versionFile);
        $filename .= "_{$version}";
    }
    return "{$filename}.phar";
}
function getPharStub($options)
{
    return <<<EOSTUB
<?php
Phar::mapPhar('predis.phar');
spl_autoload_register(function(\$class) {
    if (strpos(\$class, 'Predis\\\\') === 0) {
        \$file = 'phar://predis.phar/'.strtr(\$class, '\\\\', '/').'.php';
        if (file_exists(\$file)) {
            require \$file;
            return true;
        }
    }
});
__HALT_COMPILER();
EOSTUB;
}
// -------------------------------------------------------------------------- //
$phar = new Phar(getPharFilename($options));
$phar->compress($options['compression']);
$phar->setStub(getPharStub($options));
$phar->buildFromDirectory($options['project_path']);
开发者ID:kailIII,项目名称:pos-erp,代码行数:31,代码来源:create-phar.php

示例8: catch

    $b->setDefaultStub('oops');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->setDefaultStub(array());
try {
    $a->setDefaultStub('oops');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
try {
    $a->setSignatureAlgorithm(Phar::MD5);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->compress(array());
try {
    $a->compress(1);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->compressFiles(array());
try {
    $a->decompressFiles();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->copy(array());
try {
    $a->copy('a', 'b');
} catch (Exception $e) {
开发者ID:zaky-92,项目名称:php-1,代码行数:31,代码来源:ext_phar_tests_badparameters.php

示例9: Phar

<?php

## Сжатие архива.
try {
    $phar = new Phar('compress.phar', 0, 'compress.phar');
    if (Phar::canWrite() && Phar::canCompress()) {
        $phar->startBuffering();
        foreach (glob('../composer/photos/*') as $jpg) {
            $phar[basename($jpg)] = file_get_contents($jpg);
        }
        // Назначаем файл-заглушку
        $phar['show.php'] = file_get_contents('show.php');
        $phar->setDefaultStub('show.php', 'show.php');
        // Сжимаем файл
        $phar->compress(Phar::GZ);
        $phar->stopBuffering();
    } else {
        echo 'PHAR-архив не может быть бы записан';
    }
} catch (Exception $e) {
    echo 'Невозможно открыть PHAR-архив: ', $e;
}
开发者ID:igorsimdyanov,项目名称:php7,代码行数:22,代码来源:compress.php

示例10: testUncompress

 public function testUncompress()
 {
     $archive = new Phar($this->file);
     $archive->compress($this->compressFiles);
     $archive->compress($this->compressFiles, $this->prefix);
     $uncompressDirectory = new File('application/data/uncompress');
     if ($uncompressDirectory->exists()) {
         $uncompressDirectory->delete();
     }
     $uncompressFiles = array();
     foreach ($this->compressFiles as $file) {
         $uncompressFiles[] = new File($file->getName());
         $uncompressFiles[] = new File($this->prefix, $file->getName());
     }
     try {
         $archive->uncompress($uncompressDirectory);
     } catch (FileSystemException $e) {
         $this->fail('Uncompress directory was not created');
     }
     $contentBuildXml = $this->compressFiles[1]->read();
     $uncompressedFiles = $uncompressDirectory->read(true);
     foreach ($uncompressFiles as $file) {
         $uncompressedFile = new File($uncompressDirectory, $file);
         $this->assertArrayHasKey($uncompressedFile->getPath(), $uncompressedFiles, $uncompressedFile->getPath());
         if ($file->getName() == 'build.xml' && $uncompressedFile->read() != $contentBuildXml) {
             $this->fail('Content of the uncompressed build.xml is not the same as the original file');
         }
     }
     $uncompressDirectory->delete();
 }
开发者ID:BGCX261,项目名称:zibo-svn-to-git,代码行数:30,代码来源:PharTest.php

示例11: package

 function package($source = null)
 {
     $con = \cherry\cli\Console::getAdapter();
     if (!$source) {
         $con->write("You need to at least specify the source path.\n");
         return 1;
     }
     $opts = func_get_args();
     $opts = array_slice($opts, 1);
     $loader = null;
     $compress = null;
     $includelib = false;
     $dest = $source . '.phar';
     $isExtension = false;
     for ($optidx = 0; $optidx < count($opts); $optidx++) {
         $opt = $opts[$optidx];
         if ($optidx < count($opts) - 1) {
             $optarg = $opts[$optidx + 1];
         } else {
             $optarg = null;
         }
         switch ($opt) {
             case '+template':
                 $tools = true;
                 break;
             case 'with-stub':
                 $loader = $optarg;
                 $optidx++;
                 break;
             case 'to':
                 $dest = $optarg;
                 $optidx++;
                 break;
             case 'compress':
                 $compress = $optarg;
                 $optidx++;
                 break;
             case '+extension':
                 $isExtension = true;
                 break;
             case '+standalone':
                 $includelib = true;
                 break;
             default:
                 $con->write("Unknown argument: %s\n", $opt);
                 return 1;
         }
     }
     $con->write('Scanning %s... ', $source);
     $appcfg = null;
     $extcfg = null;
     $itfile = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS));
     $files = array();
     foreach ($itfile as $file) {
         $fn = $file->__toString();
         if (basename($fn) == 'application.ini') {
             $appcfg = parse_ini_file($fn, true);
         }
         if (basename($fn) == 'extension.ini') {
             $isExtension = true;
         }
         $files[] = $fn;
     }
     if ($isExtension && !file_exists($source . '/extension.ini')) {
         $con->warn("Error: This doesn't seem to be an extension.\n");
         return 1;
     }
     if ($isExtension) {
         $ext = parse_ini_file($source . '/extension.ini', true);
         $meta = $ext['extension'];
         $meta['type'] = 'extension';
     } elseif (!empty($appcfg)) {
         $meta = $appcfg['application'];
         $meta['type'] = 'application';
     } else {
         $con->warn("Warning: Directory does not appear to contain neither an application or an extension\n");
         $meta = array('name' => 'Unknown Application', 'version' => '?.?', 'type' => 'archive');
     }
     $con->write("%s, %d files\n", $meta['type'], count($files));
     if (!empty($appcfg)) {
         $aname = empty($appcfg['application']['name']) ? 'Unknown application' : $appcfg['application']['name'];
         $aver = empty($appcfg['application']['version']) ? '(Unknown version)' : $appcfg['application']['version'];
         $webindex = '/public/';
         $con->write("Preparing to archive %s %s\n", $aname, $aver);
     }
     $cliloader = empty($appcfg['application']['loader']) ? 'loader.php' : $appcfg['application']['loader'];
     $webroot = empty($appcfg['application']['webroot']) ? '/public/' : $appcfg['application']['webroot'];
     $meta['loader'] = $cliloader;
     if ($compress == 'bz2') {
         if (substr($dest, -4, 4) != '.bz2') {
             $dest .= '.bz2';
         }
     } elseif ($compress == 'gzip') {
         if (substr($dest, -3, 3) != '.gz') {
             $dest .= '.gz';
         }
     } elseif ($compress == null) {
     } else {
         $con->write("Unknown compression: %s\n", $compress);
     }
//.........这里部分代码省略.........
开发者ID:noccy80,项目名称:cherryphp,代码行数:101,代码来源:package.php

示例12: testWriteLoaded

    /**
     * Test that the writing of a loaded phar results in an equal file.
     *
     * @return void
     *
     * @dataProvider testWritingFlagsProvider
     */
    public function testWriteLoaded($compression, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setDefaultStub('/bin/script', '/web/index');
        $phar->stopBuffering();
        if (0 !== $signatureFlag) {
            $phar->setSignatureAlgorithm($signatureFlag);
        }
        if ($compression !== \Phar::NONE) {
            $phar->compress($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $pharfile2 = $this->getTempFile('temp.phar');
        $writer = new PharWriter();
        $writer->save($phar, $pharfile2);
        unset($writer);
        $this->assertFileEquals($pharfile, $pharfile2);
    }
开发者ID:cyberspectrum,项目名称:pharpiler,代码行数:35,代码来源:PharWriterTest.php

示例13: getenv

<?php

// Remove reposes
exec("find . | grep .git | xargs rm -rf");
$branchName = getenv('TRAVIS_BRANCH');
$fileName = 'yandex-php-library_.phar';
$phar = new Phar($fileName, 0, $fileName);
// Add files to Phar
$phar->buildFromDirectory(dirname(__FILE__), '/vendor/');
$phar->buildFromDirectory(dirname(__FILE__), '/src/');
$phar->addFile('CHANGELOG.md');
$phar->addFile('LICENSE');
$phar->addFile('README.md');
require_once dirname(__FILE__) . '/vendor/autoload.php';
use Yandex\Disk\DiskClient;
$disk = new DiskClient();
$disk->setAccessToken(getenv('ACCESS_TOKEN'));
// Send to Yandex.DisK
$disk->uploadFile('/builds/', array('path' => $fileName, 'size' => filesize($fileName), 'name' => str_replace('.phar', $branchName . '.phar', $fileName)));
// Compressing
if (Phar::canCompress(Phar::BZ2)) {
    $phar->compress(Phar::BZ2, 'phar.bz2');
    //Send to Yandex.DisK
    $fileName .= '.bz2';
    $disk->uploadFile('/builds/', array('path' => $fileName, 'size' => filesize($fileName), 'name' => str_replace('.phar.bz2', $branchName . '.phar.bz2', $fileName)));
}
开发者ID:zhenya91,项目名称:yandex-php-library,代码行数:26,代码来源:phar.php

示例14: error

    case 'bz2':
        $compress = Phar::BZ2;
        $compress_type = 'bz2';
        break;
    default:
        $compress = Phar::NONE;
        $compress_type = 'none';
        break;
}
if (!empty($base_dir) && !is_dir($base_dir)) {
    error("Dir not Exists!");
}
try {
    $p = new Phar($path, $flags, $alias);
    $p->startBuffering();
    $p->compress($compress);
    info("API Version: " . Phar::apiVersion());
    info("File: {$path}");
    info("Alias: {$alias}");
    info("Compress: {$compress_type}");
    if (!empty($base_dir)) {
        info("Build From: {$base_dir}");
        if ($regex) {
            info("Filter: {$regex}");
        }
        $p->buildFromDirectory($base_dir, $regex);
    }
    if (!empty($files)) {
        foreach (explode(',', $files) as $file) {
            info("Add File: {$file}");
            $p->addFile($file, basename($file));
开发者ID:chchmlml,项目名称:ceshi,代码行数:31,代码来源:phar.php

示例15: Phar

         }
     }
 }
 if (file_exists($argv[2])) {
     if (file_exists($file)) {
         @unlink($file);
         echo "Overwritting phar...";
     } else {
         echo "Creating phar...";
     }
     $phar = new Phar(getcwd() . "/" . $file, 0, $file);
     //Check compression
     if ($compression != null) {
         if ($compression == Phar::GZ) {
             if ($phar->canCompress(Phar::GZ)) {
                 $phar->compress($compression);
                 echo "\nCompression set to GZIP";
             } else {
                 echo "\nCan't use GZIP compression";
             }
         } elseif ($compression == Phar::BZ2) {
             if ($phar->canCompress(Phar::BZ2)) {
                 $phar->compress($compression);
                 echo "\nCompression set to BZIP2";
             } else {
                 echo "\nCan't use BZIP2 compression";
             }
         }
     }
     //Check metadata
     if ($metadata != null) {
开发者ID:PocketServers,项目名称:ImagicalMine,代码行数:31,代码来源:phartools.php


注:本文中的Phar::compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。