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


PHP PharData类代码示例

本文整理汇总了PHP中PharData的典型用法代码示例。如果您正苦于以下问题:PHP PharData类的具体用法?PHP PharData怎么用?PHP PharData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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);
 }
开发者ID:spotlab,项目名称:safeguard,代码行数:29,代码来源:Guardian.php

示例2: extractTo

 /**
  * @inheritDoc
  */
 public function extractTo($dir)
 {
     $phar = new \PharData($this->file);
     $result = $phar->extractTo($dir, null, true);
     $phar = null;
     return $result;
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:10,代码来源:PharArchiveReader.php

示例3: 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);
     }
 }
开发者ID:alcaeus,项目名称:composer,代码行数:38,代码来源:PharArchiver.php

示例4: 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);
 }
开发者ID:one-more,项目名称:peach_framework,代码行数:28,代码来源:AutoloaderTest.php

示例5: __construct

 /**
  * Files constructor.
  * @param $target
  */
 public function __construct($target)
 {
     $this->tarFilename = sys_get_temp_dir() . '/' . uniqid() . '.tar';
     $phar = new \PharData($this->tarFilename);
     $phar->buildFromDirectory($target);
     $this->tarStream = fopen($this->tarFilename, 'r');
 }
开发者ID:jarkt,项目名称:dockercloud-php-client,代码行数:11,代码来源:Files.php

示例6: copyDirToArchive

 public static function copyDirToArchive($dir, $archive, $basename = null, $excludeDirs = null)
 {
     $dir = rtrim($dir, '/\\');
     $basename = $basename ?: basename($dir);
     rex_dir::create(dirname($archive));
     $files = array();
     $iterator = rex_finder::factory($dir)->recursive()->filesOnly();
     if ($excludeDirs) {
         $iterator->ignoreDirs($excludeDirs, false);
     }
     foreach ($iterator as $path => $file) {
         $subpath = str_replace($dir, $basename, $path);
         $subpath = str_replace('\\', '/', $subpath);
         $files[$subpath] = $path;
     }
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         $zip->open($archive, ZipArchive::CREATE);
         foreach ($files as $path => $realpath) {
             $zip->addFile($realpath, $path);
         }
         $zip->close();
     } else {
         $phar = new PharData($archive, 0, null, Phar::ZIP);
         $phar->buildFromIterator(new ArrayIterator($files));
         $phar->compressFiles(Phar::GZ);
         foreach ($files as $path => $realpath) {
             if (filesize($realpath) == 0) {
                 $phar[$path]->decompress();
             }
         }
     }
 }
开发者ID:redaxo,项目名称:redaxo4,代码行数:33,代码来源:archive.php

示例7: extract

 /**
  * Load and extract our application development files
  *
  * @return  void
  */
 public static function extract()
 {
     /* Are we IN_DEV (and does it matter)? */
     if (static::$checkInDev) {
         if (!defined('\\IPS\\IN_DEV') or !\IPS\IN_DEV) {
             return;
         }
     }
     /* Attempt to load our application */
     $thisApp = NULL;
     $applications = \IPS\Application::applications();
     foreach ($applications as $application) {
         if ($application->directory === static::$appDir) {
             $thisApp = $application;
         }
     }
     if (!$thisApp) {
         \IPS\Log::i(\LOG_ERR)->write('Error : Application ' . static::$appDir . ' not found', 'devpackager_error');
         return;
     }
     /* Set our paths */
     $appPath = join(\DIRECTORY_SEPARATOR, [\IPS\ROOT_PATH, 'applications', $thisApp->directory]);
     $devPath = join(\DIRECTORY_SEPARATOR, [$appPath, 'dev']);
     $devTar = join(\DIRECTORY_SEPARATOR, [$appPath, 'data', 'dev.tar']);
     /* Load and extract our tarball */
     try {
         if (!is_dir($devPath)) {
             mkdir($devPath, 0777, true);
         }
         $devFiles = new \PharData($devTar, 0, NULL, \Phar::TAR);
         $devFiles->extractTo($devPath, NULL, TRUE);
     } catch (\Exception $e) {
         \IPS\Log::i(\LOG_ERR)->write('Error : ' . $e->getMessage() . "\n" . $e->getTraceAsString(), 'devpackager_error');
     }
 }
开发者ID:alobimday,项目名称:IPS-Faker,代码行数:40,代码来源:DevFiles.php

示例8: create

 /**
  * Create package.
  */
 public function create(array $args = array())
 {
     $archBasename = $this->pkg->getSimpleName() . '-' . $this->pkg->getPrettyVersion();
     /* Work around bug  #67417 [NEW]: ::compress modifies archive basename
        creates temp file and rename it */
     $tempName = getcwd() . '/pkl-tmp.tar';
     if (file_exists($tempName)) {
         unlink($tempName);
     }
     $arch = new \PharData($tempName);
     $pkgDir = $this->pkg->getRootDir();
     foreach ($this->pkg->getFiles() as $file) {
         if (is_file($file)) {
             $name = str_replace($pkgDir, '', $file);
             $arch->addFile($file, $name);
         }
     }
     if (file_exists($tempName)) {
         @unlink($tempName . '.gz');
     }
     $arch->compress(\Phar::GZ);
     unset($arch);
     rename($tempName . '.gz', $archBasename . '.tgz');
     unlink($tempName);
     if ($this->cb) {
         $cb = $this->cb;
         $cb($this->pkg);
     }
 }
开发者ID:staabm,项目名称:pickle,代码行数:32,代码来源:Release.php

示例9: action

 public function action($parent)
 {
     $c = $parent->config;
     $util = new Utility();
     if (strpos($_POST['path'], '/') === 0 || strpos($_POST['path'], '../') !== false || strpos($_POST['path'], './') === 0) {
         $this->r = array('wrong path', 400);
         return;
     }
     $path = $c['current_path'] . $_POST['path'];
     $info = pathinfo($path);
     $base_folder = $c['current_path'] . $util->fix_dirname($_POST['path']) . "/";
     switch ($info['extension']) {
         case "zip":
             $zip = new \ZipArchive();
             if ($zip->open($path) === true) {
                 //make all the folders
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $OnlyFileName = $zip->getNameIndex($i);
                     $FullFileName = $zip->statIndex($i);
                     if (substr($FullFileName['name'], -1, 1) == "/") {
                         $util->create_folder($base_folder . $FullFileName['name']);
                     }
                 }
                 //unzip into the folders
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $OnlyFileName = $zip->getNameIndex($i);
                     $FullFileName = $zip->statIndex($i);
                     if (!(substr($FullFileName['name'], -1, 1) == "/")) {
                         $fileinfo = pathinfo($OnlyFileName);
                         if (in_array(strtolower($fileinfo['extension']), $ext)) {
                             copy('zip://' . $path . '#' . $OnlyFileName, $base_folder . $FullFileName['name']);
                         }
                     }
                 }
                 $zip->close();
             } else {
                 $this->r = array('Could not extract. File might be corrupt.', 500);
                 return;
             }
             break;
         case "gz":
             $p = new \PharData($path);
             $p->decompress();
             // creates files.tar
             break;
         case "tar":
             // unarchive from the tar
             $phar = new \PharData($path);
             $phar->decompressFiles();
             $files = array();
             $util->check_files_extensions_on_phar($phar, $files, '', $ext);
             $phar->extractTo($current_path . fix_dirname($_POST['path']) . "/", $files, true);
             break;
         default:
             $this->r = array('This extension is not supported. Valid: zip, gz, tar.', 400);
             return;
             break;
     }
 }
开发者ID:Kingtreemonkey,项目名称:FileManager,代码行数:59,代码来源:Extract.php

示例10: gzipFolder

 static function gzipFolder($folder) {
     try {
         $a = new PharData($folder . '_archive.zip');
         $a->buildFromDirectory($folder);
     } catch (Exception $e) {
         return false;
     } return true;
 }
开发者ID:salatproduction,项目名称:XLSX-2-HTML-SQL-Converter-Standalone,代码行数:8,代码来源:functions.class.php

示例11: __construct

 /**
  * @param string $package path to package file
  */
 function __construct($package, \Pyrus\Package $parent)
 {
     $package = realpath($package);
     if (!$package) {
         throw new Phar\Exception('Phar package ' . $package . ' does not exist');
     }
     $pxml = false;
     $this->archive = $package;
     try {
         if (\Phar::isValidPharFilename($package, 1)) {
             $phar = new \Phar($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME);
             $pxml = 'phar://' . $package . '/' . $phar->getMetaData();
         } else {
             $phar = new \PharData($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME);
             if ($phar->getMetaData()) {
                 $pxml = 'phar://' . $package . '/' . $phar->getMetaData();
             }
         }
     } catch (\Exception $e) {
         throw new Phar\Exception('Could not open Phar archive ' . $package, $e);
     }
     $package = str_replace('\\', '/', $package);
     try {
         if ($pxml === false) {
             $info = pathinfo($package);
             $internal = $info['filename'];
             if (isset($phar[$internal . '/.xmlregistry'])) {
                 if ($phar instanceof \PharData) {
                     $iterate = new \PharData('phar://' . $package . '/' . $internal . '/.xmlregistry');
                 } else {
                     $iterate = new \Phar('phar://' . $package . '/' . $internal . '/.xmlregistry');
                 }
                 foreach (new \RecursiveIteratorIterator($iterate, \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
                     $filename = $file->getFileName();
                     // default to new package.xml
                     if (preg_match('@^(.+)\\-package.xml$@', $filename)) {
                         $pxml = $file->getPathName();
                         break;
                     }
                 }
             } else {
                 foreach (array('package2.xml', $internal . '/' . 'package2.xml', 'package.xml', $internal . '/' . 'package.xml') as $checkfile) {
                     if (isset($phar[$checkfile])) {
                         $this->_BCpackage = true;
                         $pxml = $phar[$checkfile]->getPathName();
                         break;
                     }
                 }
             }
         }
         if ($pxml === false) {
             throw new Phar\Exception('No package.xml in archive');
         }
     } catch (\Exception $e) {
         throw new Phar\Exception('Could not extract Phar archive ' . $package, $e);
     }
     parent::__construct(new \Pyrus\PackageFile($pxml, 'Pyrus\\PackageFile\\v2'), $parent);
 }
开发者ID:peopleplan,项目名称:Pyrus,代码行数:61,代码来源:Phar.php

示例12: getArchivers

 protected function getArchivers($use_cache = true)
 {
     $arcs = array('create' => array(), 'extract' => array());
     $obj = $this;
     // php 5.3 compatibility
     if (class_exists('ZipArchive')) {
         $arcs['extract']['application/zip'] = array('cmd' => function ($archive, $path) use($obj) {
             $zip = new \ZipArchive();
             if ($zip->open($archive)) {
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $stat = $zip->statIndex($i);
                     if (empty($stat['size'])) {
                         // directory
                         continue;
                     }
                     $filename = $stat['name'];
                     if (!$obj->tyghIsUTF8($filename) && function_exists('iconv')) {
                         $newfile = iconv('cp866', 'utf-8', $filename);
                     } else {
                         $newfile = $filename;
                     }
                     $obj->tyghMkdir(dirname($path . '/' . $newfile));
                     copy('zip://' . $archive . '#' . $filename, $path . '/' . $newfile);
                 }
                 $zip->close();
                 return true;
             }
             return false;
         }, 'ext' => 'zip');
         $arcs['create']['application/zip'] = array('cmd' => function ($archive, $files) use($obj) {
             $zip = new \ZipArchive();
             if ($zip->open($archive, \ZipArchive::CREATE) === true) {
                 $base_path = dirname($archive);
                 foreach ($files as $file) {
                     $path = $base_path . DIRECTORY_SEPARATOR . $file;
                     if (is_file($path)) {
                         $zip->addFile($path, $file);
                     } elseif (is_dir($path)) {
                         foreach ($obj->tyghGetFiles($path) as $_file) {
                             $zip->addFile($path . DIRECTORY_SEPARATOR . $_file, $_file);
                         }
                     }
                 }
                 $zip->close();
                 return true;
             }
             return false;
         }, 'ext' => 'zip');
     }
     if (class_exists('PharData')) {
         $arcs['extract']['application/x-gzip'] = array('cmd' => function ($archive, $path) {
             $phar = new \PharData($archive);
             $phar->extractTo($path, null, true);
         }, 'ext' => 'tgz');
     }
     return $arcs;
 }
开发者ID:askzap,项目名称:ultimate,代码行数:57,代码来源:Volume.php

示例13: Parse

 /**
  * Parse a tarball of .gcov files.
  **/
 public function Parse($handle)
 {
     global $CDASH_BACKUP_DIRECTORY;
     // This function receives an open file handle, but we really just need
     // the path to this file so that we can extract it.
     $meta_data = stream_get_meta_data($handle);
     $filename = $meta_data["uri"];
     fclose($handle);
     // Create a new directory where we can extract our tarball.
     $pathParts = pathinfo($filename);
     $dirName = $CDASH_BACKUP_DIRECTORY . "/" . $pathParts['filename'];
     mkdir($dirName);
     // Extract the tarball.
     $phar = new PharData($filename);
     $phar->extractTo($dirName);
     // Find the data.json file and extract the source directory from it.
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirName), RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->getFilename() == "data.json") {
             $jsonContents = file_get_contents($fileinfo->getRealPath());
             $jsonDecoded = json_decode($jsonContents, true);
             if (is_null($jsonDecoded) || !array_key_exists("Source", $jsonDecoded) || !array_key_exists("Binary", $jsonDecoded)) {
                 $this->DeleteDirectory($dirName);
                 return false;
             }
             $this->SourceDirectory = $jsonDecoded['Source'];
             $this->BinaryDirectory = $jsonDecoded['Binary'];
             break;
         }
     }
     if (empty($this->SourceDirectory) || empty($this->BinaryDirectory)) {
         $this->DeleteDirectory($dirName);
         return false;
     }
     // Check if any Labels.json files were included
     $iterator->rewind();
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->getFilename() == "Labels.json") {
             $this->ParseLabelsFile($fileinfo);
         }
     }
     // Recursively search for .gcov files and parse them.
     $iterator->rewind();
     foreach ($iterator as $fileinfo) {
         if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) == "gcov") {
             $this->ParseGcovFile($fileinfo);
         }
     }
     // Insert coverage summary (removing any old results first)
     //$this->CoverageSummary->RemoveAll();
     $this->CoverageSummary->Insert();
     $this->CoverageSummary->ComputeDifference();
     // Delete the directory when we're done.
     $this->DeleteDirectory($dirName);
     return true;
 }
开发者ID:josephsnyder,项目名称:CDash,代码行数:59,代码来源:GcovTar_handler.php

示例14: 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();
 }
开发者ID:yonchin,项目名称:Docker-Web,代码行数:10,代码来源:DockerImage.class.php

示例15: extract

 /**
  * TODO: Is it possible to extract directly from the stream? With stream filters?
  *
  * @param $target
  */
 public function extract($target)
 {
     if (!isset($this->target)) {
         $this->target = sys_get_temp_dir() . '/' . uniqid() . '.tar';
         $this->saveTar($this->target);
         $this->removeTarget = true;
     }
     $phar = new \PharData($this->target);
     $phar->extractTo($target);
 }
开发者ID:jarkt,项目名称:docker-php-client,代码行数:15,代码来源:Files.php


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