本文整理汇总了PHP中PharData::compress方法的典型用法代码示例。如果您正苦于以下问题:PHP PharData::compress方法的具体用法?PHP PharData::compress怎么用?PHP PharData::compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PharData
的用法示例。
在下文中一共展示了PharData::compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __destruct
/**
* Archive cleanup
*/
public function __destruct()
{
// Compress the archive on exit
if ($this->compression != Compression::NONE()) {
// Due to the way Phar works, it MUST create a new archive with a different extension. We will allow this,
// then rename the new archive back to the original filename
$ext = uniqid();
$fn = substr($this->filename, 0, strrpos($this->filename, '.') ?: null);
$this->archive->compress((int) $this->compression->value(), $ext);
// New archive does not get created on empty databases
if (file_exists($fn . '.' . $ext)) {
rename($fn . '.' . $ext, $this->filename);
}
}
}
示例2: createArchive
public static function createArchive($arg, $origin_dir, $archive_file, $overwrite = false)
{
if (!extension_loaded('phar')) {
throw new pakeException(__CLASS__ . ' module requires "phar" extension');
}
if (false === $overwrite and file_exists($archive_file)) {
return true;
}
if (self::endsWith($archive_file, '.tar.gz')) {
$archive_file = substr($archive_file, 0, -3);
$compress = Phar::GZ;
$extension = '.tar.gz';
if (!extension_loaded('zlib')) {
throw new pakeException('GZip compression method is not available on this system (install "zlib" extension)');
}
} elseif (self::endsWith($archive_file, '.tgz')) {
$archive_file = substr($archive_file, 0, -3) . 'tar';
$compress = Phar::GZ;
$extension = '.tgz';
if (!extension_loaded('zlib')) {
throw new pakeException('GZip compression method is not available on this system (install "zlib" extension)');
}
} elseif (self::endsWith($archive_file, '.tar.bz2')) {
$archive_file = substr($archive_file, 0, -4);
$compress = Phar::BZ2;
$extension = '.tar.bz2';
if (!extension_loaded('bz2')) {
throw new pakeException('BZip2 compression method is not available on this system (install "bzip2" extension)');
}
} elseif (self::endsWith($archive_file, '.tar') or self::endsWith($archive_file, '.zip')) {
$compress = Phar::NONE;
} else {
throw new pakeException("Only .zip, .tar, .tar.gz and .tar.bz2 archives are supported");
}
$files = pakeFinder::get_files_from_argument($arg, $origin_dir, true);
pake_echo_action('file+', $archive_file);
try {
$arc = new PharData($archive_file);
foreach ($files as $file) {
$full_path = $origin_dir . '/' . $file;
pake_echo_action('archive', '-> ' . $file);
if (is_dir($full_path)) {
$arc->addEmptyDir($file);
} else {
$arc->addFile($full_path, $file);
}
}
if (Phar::NONE !== $compress) {
$new_name = substr($archive_file, 0, -4) . $extension;
pake_echo_action('file+', $new_name);
$arc->compress($compress, $extension);
unset($arc);
pake_remove($archive_file, '/');
}
} catch (PharException $e) {
unset($arc);
pake_remove($archive_file);
throw $e;
}
}
示例3: test_load_extension
/**
* @covers common\classes\AutoLoader::load_extension
*/
public function test_load_extension()
{
$extensions = glob(ROOT_PATH . DS . 'extensions' . DS . '*');
foreach ($extensions as $extension) {
$name = ucwords(explode('.', basename($extension))[0]);
self::assertTrue(AutoLoader::load_extension($name));
}
self::assertFalse(AutoLoader::load_extension('NotExistedClass'));
$name = 'fakeextension';
$extension_file = ROOT_PATH . DS . 'extensions' . DS . $name;
$extension_build_dir = ROOT_PATH . DS . 'tests' . DS . 'resource' . DS . $name;
$extension_file_tar = "{$extension_file}.tar";
$extension_file_gz = "{$extension_file}.tar.gz";
if (file_exists($extension_file_gz)) {
Phar::unlinkArchive($extension_file_gz);
}
$phar = new PharData($extension_file_tar);
$phar->buildFromDirectory($extension_build_dir);
$phar->compress(Phar::GZ);
if (file_exists($extension_file_tar)) {
unlink($extension_file_tar);
}
self::assertTrue(AutoLoader::load_extension($name));
unlink($extension_file_gz);
}
示例4: archive
/**
* {@inheritdoc}
*/
public function archive($sources, $target, $format, array $excludes = array())
{
$sources = realpath($sources);
// Phar would otherwise load the file which we don't want
if (file_exists($target)) {
unlink($target);
}
try {
$filename = substr($target, 0, strrpos($target, $format) - 1);
// Check if compress format
if (isset(static::$compressFormats[$format])) {
// Current compress format supported base on tar
$target = $filename . '.tar';
}
$phar = new \PharData($target, null, null, static::$formats[$format]);
$files = new ArchivableFilesFinder($sources, $excludes);
$phar->buildFromIterator($files, $sources);
if (isset(static::$compressFormats[$format])) {
// Check can be compressed?
if (!$phar->canCompress(static::$compressFormats[$format])) {
throw new \RuntimeException(sprintf('Can not compress to %s format', $format));
}
// Delete old tar
unlink($target);
// Compress the new tar
$phar->compress(static::$compressFormats[$format]);
// Make the correct filename
$target = $filename . '.' . $format;
}
return $target;
} catch (\UnexpectedValueException $e) {
$message = sprintf("Could not create archive '%s' from '%s': %s", $target, $sources, $e->getMessage());
throw new \RuntimeException($message, $e->getCode(), $e);
}
}
示例5: testAutoRollback
public function testAutoRollback()
{
// Setup
$this->autoRollbackHelper();
$this->backupFile->buildFromDirectory($this->archivedDir);
$this->backupFile->addEmptyDir("testDirectory");
$this->backupFile->compress(\Phar::GZ, '.tgz');
$newFile = $this->backupPath . '/' . uniqid() . '_code.tgz';
copy($this->backupFileName, $newFile);
if (file_exists($this->backupFileName)) {
unset($this->backupFile);
unlink($this->backupFileName);
}
$gtzFile = str_replace('tar', 'tgz', $this->backupFileName);
if (file_exists($gtzFile)) {
unlink($gtzFile);
}
$this->backupFileName = $newFile;
// Change the contents of a.txt
$this->autoRollbackHelper(1);
$this->assertEquals('foo changed', file_get_contents($this->archivedDir . 'a.txt'));
$this->backupInfo->expects($this->once())->method('getBlacklist')->willReturn(['excluded']);
// Rollback process
$this->rollBack->execute($this->backupFileName);
// Assert that the contents of a.txt has been restored properly
$this->assertEquals('foo', file_get_contents($this->archivedDir . 'a.txt'));
}
示例6: backupArchive
/**
* @param string $project
* @return array $return
*/
public function backupArchive($project)
{
// Exception if not defined
if (!isset($this->config[$project]['archive'])) {
throw new \Exception('No "Archive config" for this project', 1);
}
// Get backup settings
$settings = $this->getArchiveSettings($project);
// Get backup file prefix
$backupFilePrefix = '';
if (!empty($settings['backup_file_prefix'])) {
$backupFilePrefix = $settings['backup_file_prefix'];
}
// Set filename
$filename = $backupFilePrefix . date('Ymd_His') . '.tar';
// Data required to backup Database
$path = $this->getBackupPath($project, 'archive');
// Create Archive
$phar = new \PharData($path . '/' . $filename);
$phar->buildFromIterator(new \ArrayIterator($this->getArchiveFilesList($project)));
// Compress and unlink none compress archive
$phar->compress(\Phar::GZ);
unlink($path . '/' . $filename);
return $this->getBackupInfo($path, $filename);
}
示例7: imgCreate
public function imgCreate($tag, $dkFileData)
{
file_put_contents('Dockerfile', $dkFileData);
$dkfiletar = new PharData('Dockerfile.tar');
$dkfiletar->addFile('Dockerfile');
//执行此行代码后生成Dockerfile.tar.gz文件
$dkfiletar->compress(Phar::GZ);
$this->cmObj->curlPostFile(DOCKER_URL . '/build?t=' . $tag . '&nocache=1', 'Dockerfile.tar.gz', array('Content-Type:application/tar'));
return $this->cmObj->curlHttpCode();
}
示例8: compress
/**
* Create tgz archive.
*/
public function compress()
{
$tarFile = $this->rootDir . '/' . $this->tmpName . '.tar';
$tgzFile = $this->rootDir . '/' . $this->tmpName . '.tgz';
$phar = new \PharData($tarFile);
foreach ($this->files as $file) {
$phar->addFile($file[0], $file[1]);
}
// Compress .tar file to .tgz
$phar->compress(\Phar::GZ, '.tgz');
rename($tgzFile, $this->rootDir . '/' . $this->name);
// Both files (.tar and .tgz) exist. Remove the temporary .tar archive
unlink($tarFile);
}
示例9: build_extension
private static function build_extension($name)
{
$name = strtolower($name);
$extension_file = ROOT_PATH . DS . 'extensions' . DS . $name;
$extension_build_dir = ROOT_PATH . DS . 'build' . DS . $name;
$extension_file_tar = "{$extension_file}.tar";
$extension_file_gz = "{$extension_file}.tar.gz";
if (file_exists($extension_file_gz)) {
\Phar::unlinkArchive($extension_file_gz);
}
$phar = new \PharData($extension_file_tar);
$phar->buildFromDirectory($extension_build_dir);
$phar->compress(\Phar::GZ);
if (file_exists($extension_file_tar)) {
unlink($extension_file_tar);
}
}
示例10: setUpBeforeClass
/**
* Create an empty.box in the temp dir that we can use to test
* compression/decompression and adding metadata.json to it.
*
* PHP's PharData does NOT work with vfsStream so we're required
* to put this on the actual filesystem.
*/
public static function setUpBeforeClass()
{
$fixturesPath = $GLOBALS['PHPUNIT_FIXTURES_DIR'] . DIRECTORY_SEPARATOR . 'empty.box';
$p = new \PharData("tmp.tar");
$emptyBoxFiles = array('box.ovf', 'box-disk1.vmdk', 'metadata.json', 'Vagrantfile');
foreach ($emptyBoxFiles as $file) {
$p->addFile("{$fixturesPath}/{$file}", basename($file));
}
$p->compress(\Phar::GZ);
unset($p);
// Windows: make $p release the tmp.tar file
if (!unlink("tmp.tar")) {
fwrite(STDERR, "unlink('tmp.tar') failed in " . getcwd() . "\n");
system('ls -la');
}
rename("tmp.tar.gz", "empty.box");
self::$emptyPackageBox = file_get_contents("empty.box");
}
示例11: clean
public function clean()
{
# Maximum size of log file allowed, in bytes ( 100000000 = 100 MB)
$max_size = 100000000;
chdir(LOG_PATH);
foreach (glob("*.log") as $_file) {
if (filesize($_file) >= $max_size) {
$tar = new \PharData(basename($_file, ".log") . '-error-log-archive.tar');
$tar->addFile($_file);
$tar->compress(\Phar::GZ);
# Move tarball to archives folder once complete
if (is_readable('archive/' . $_file . '-error-log-archive.tar')) {
rename($_file . '-error-log-archive.tar', 'archive/' . $_file . '-error-log-archive.tar');
} else {
rename($_file . '-error-log-archive.tar', 'archive/' . $_file . '_' . time() . '-error-log-archive.tar');
}
}
}
}
示例12: unlink
function __c3_build_html_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_HTML();
$writer->process($codeCoverage, $path . 'html');
if (file_exists($path . '.tar')) {
unlink($path . '.tar');
}
$phar = new PharData($path . '.tar');
$phar->setSignatureAlgorithm(Phar::SHA1);
$files = $phar->buildFromDirectory($path . 'html');
array_map('unlink', $files);
if (in_array('GZ', Phar::getSupportedCompression())) {
if (file_exists($path . '.tar.gz')) {
unlink($path . '.tar.gz');
}
$phar->compress(\Phar::GZ);
// close the file so that we can rename it
unset($phar);
unlink($path . '.tar');
rename($path . '.tar.gz', $path . '.tar');
}
return $path . '.tar';
}
示例13: cmd_artifact
public function cmd_artifact(array $params = array())
{
\System\Directory::check(BASE_DIR . static::DIR_PACKAGES);
$target = BASE_DIR . static::DIR_PACKAGES . '/artifact.tar';
$result = $target . '.gz';
if (isset($params[0])) {
$target = $params[0];
}
if (file_exists($target)) {
unlink($target);
}
if (file_exists($result)) {
unlink($result);
}
$iter = new \RecursiveDirectoryIterator(BASE_DIR);
$iter->setFlags(\FileSystemIterator::SKIP_DOTS);
$iter = new ProjectDirectoryRecursiveIterator($iter);
$iter = new \RecursiveIteratorIterator($iter);
$archive = new \PharData($target);
$archive->buildFromIterator($iter, BASE_DIR);
$archive->compress(\Phar::GZ);
unlink($target);
}
示例14: run
/**
* @inheritdoc
*/
public function run(&$cmdParams, &$params)
{
$res = true;
$taskRunner = $this->taskRunner;
$toBeAdded = [];
$srcList = !empty($cmdParams[0]) ? $cmdParams[0] : [];
$destFile = !empty($cmdParams[1]) ? $taskRunner->parsePath($cmdParams[1]) : '';
$srcBaseDir = !empty($cmdParams[2]) ? $taskRunner->parsePath($cmdParams[2]) : '';
$format = !empty($cmdParams[3]) ? strtolower($cmdParams[3]) : self::CMP_GZ;
$options = !empty($cmdParams[4]) ? $cmdParams[4] : [];
if (!empty($srcBaseDir) && !is_dir($srcBaseDir)) {
Log::throwException('compress: srcBaseDir has to be a directory');
}
if (empty($destFile) || file_exists($destFile) && is_dir($destFile)) {
Log::throwException('compress: Destination has to be a file');
}
switch ($format) {
case self::CMP_NONE:
$extension = '.tar';
$compression = \Phar::NONE;
$doCompress = false;
break;
case self::CMP_GZ:
$extension = '.tar.gz';
$compression = \Phar::GZ;
$doCompress = true;
break;
case self::CMP_BZ2:
$extension = '.tar.bz2';
$compression = \Phar::BZ2;
$doCompress = true;
break;
default:
$extension = '';
$compression = false;
$doCompress = false;
Log::throwException('compress: Invalid format specified: ' . $format);
break;
}
// if $srcList is specified but it is a string, we convert it to an array
if (!empty($srcList) && is_string($srcList)) {
$srcList = explode(',', $srcList);
}
foreach ($srcList as $srcPath) {
$parsedPath = $taskRunner->parseStringAliases(trim($srcPath));
if (!empty($srcBaseDir)) {
$toBeAdded[$parsedPath] = $srcBaseDir . DIRECTORY_SEPARATOR . $parsedPath;
} else {
$toBeAdded[] = $parsedPath;
}
}
$this->controller->stdout("Creating archive: ");
$this->controller->stdout($destFile, Console::FG_BLUE);
$archive = null;
$destDir = dirname($destFile);
$destBaseFile = $destDir . DIRECTORY_SEPARATOR . basename($destFile, '.tar');
if (!$this->controller->dryRun) {
if (!is_dir($destDir)) {
FileHelper::createDirectory($destDir);
}
@unlink($destFile);
@unlink($destBaseFile);
try {
$archive = new \PharData($destFile);
} catch (\Exception $e) {
Log::throwException($e->getMessage());
}
} else {
$this->controller->stdout(' [dry run]', Console::FG_YELLOW);
}
$this->controller->stdout("\n");
$this->controller->stdout("Adding to archive: ");
foreach ($toBeAdded as $srcRelPath => $srcFullPath) {
if (file_exists($srcFullPath)) {
$this->controller->stdout("\n - " . $srcFullPath);
if (!$this->controller->dryRun) {
if (is_dir($srcFullPath)) {
$files = FileHelper::findFiles($srcFullPath, $options);
$archive->buildFromIterator(new ArrayIterator($files), !empty($srcBaseDir) ? $srcBaseDir : $srcFullPath);
} elseif (FileHelper::filterPath($srcFullPath, $options)) {
$archive->addFile($srcFullPath, !empty($srcBaseDir) ? $srcRelPath : basename($srcFullPath));
}
} else {
$this->controller->stdout(' [dry run]', Console::FG_YELLOW);
}
} else {
$this->controller->stderr("\n{$srcFullPath} does not exists!\n", Console::FG_RED);
}
}
$this->controller->stdout("\n");
if ($doCompress) {
$this->controller->stdout("Compressing archive: ");
$this->controller->stdout($destBaseFile . $extension, Console::FG_CYAN);
if (!$this->controller->dryRun) {
@unlink($destBaseFile . $extension);
try {
$archive->compress($compression, $extension);
//.........这里部分代码省略.........
示例15: packTargz
/**
* Pack to a tar.gz archive
*
* @param string $path
* @param string $target
* return bool
*/
public function packTargz($source, $target)
{
try {
$a = new PharData($target . '.tar');
$a->buildFromDirectory($source);
$a->compress(Phar::GZ);
unset($a);
Phar::unlinkArchive($target . '.tar');
return true;
} catch (Exception $e) {
return false;
}
}