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


PHP PharData::addEmptyDir方法代码示例

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


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

示例1: 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'));
 }
开发者ID:Dalerion83,项目名称:magento2-community-edition,代码行数:27,代码来源:RollbackTest.php

示例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;
     }
 }
开发者ID:JasonWayne,项目名称:markdown-resume,代码行数:60,代码来源:pakeArchive.class.php

示例3: addDirectory

 /**
  * @param $directoryPath
  * @return $this
  * @throws \ErrorException
  *
  * This method creates an empty directory
  */
 public function addDirectory($directoryPath)
 {
     $directoryInArchive = $this->formatDirectoryPath($directoryPath);
     if (!empty($directoryInArchive)) {
         try {
             $this->tar->addEmptyDir($directoryInArchive);
         } catch (\Exception $e) {
             throw new \ErrorException($this->translator->trans("The directory %dir has not been created in the archive", ["%dir" => $directoryInArchive]));
         }
     }
     return $this;
 }
开发者ID:margery,项目名称:thelia,代码行数:19,代码来源:TarArchiveBuilder.php

示例4: create

 public function create($execution, $format, $hrefs)
 {
     $this->dirs = array();
     $this->files = array();
     $this->sc401 = false;
     $this->add_hrefs($hrefs);
     if ($this->sc401) {
         return 401;
     } else {
         if (count($this->dirs) === 0 && count($this->files) === 0) {
             return 404;
         }
     }
     $target = H5ai::normalize_path(sys_get_temp_dir(), true) . "h5ai-selection-" . microtime(true) . rand() . "." . $format;
     try {
         if ($execution === "shell") {
             if ($format === "tar") {
                 $cmd = Archive::$TAR_CMD;
             } else {
                 if ($format === "zip") {
                     $cmd = Archive::$ZIP_CMD;
                 } else {
                     return null;
                 }
             }
             $cmd = str_replace("[ROOTDIR]", "\"" . $this->h5ai->getRootAbsPath() . "\"", $cmd);
             $cmd = str_replace("[TARGET]", "\"" . $target . "\"", $cmd);
             $cmd = str_replace("[DIRS]", count($this->dirs) ? "\"" . implode("\"  \"", array_values($this->dirs)) . "\"" : "", $cmd);
             $cmd = str_replace("[FILES]", count($this->files) ? "\"" . implode("\"  \"", array_values($this->files)) . "\"" : "", $cmd);
             `{$cmd}`;
         } else {
             if ($execution === "php") {
                 $archive = new PharData($target);
                 foreach ($this->dirs as $archivedDir) {
                     $archive->addEmptyDir($archivedDir);
                 }
                 foreach ($this->files as $realFile => $archivedFile) {
                     $archive->addFile($realFile, $archivedFile);
                     // very, very slow :/
                 }
             }
         }
     } catch (Exeption $err) {
         return 500;
     }
     return @filesize($target) ? $target : null;
 }
开发者ID:rsertelon,项目名称:h5ai,代码行数:47,代码来源:Archive.php

示例5: create

 public function create($execution, $format, $hrefs)
 {
     $this->dirs = array();
     $this->files = array();
     $this->add_hrefs($hrefs);
     if (count($this->dirs) === 0 && count($this->files) === 0) {
         return 404;
     }
     $target = $this->app->get_cache_abs_path() . "/package-" . sha1(microtime(true) . rand()) . "." . $format;
     try {
         if ($execution === "shell") {
             if ($format === "tar") {
                 $cmd = Archive::$TAR_CMD;
             } else {
                 if ($format === "zip") {
                     $cmd = Archive::$ZIP_CMD;
                 } else {
                     return null;
                 }
             }
             // $cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_root_abs_path() . "\"", $cmd);
             $cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_abs_path() . "\"", $cmd);
             $cmd = str_replace("[TARGET]", "\"" . $target . "\"", $cmd);
             $cmd = str_replace("[DIRS]", count($this->dirs) ? "\"" . implode("\"  \"", array_values($this->dirs)) . "\"" : "", $cmd);
             $cmd = str_replace("[FILES]", count($this->files) ? "\"" . implode("\"  \"", array_values($this->files)) . "\"" : "", $cmd);
             shell_exec($cmd);
         } else {
             if ($execution === "php") {
                 $archive = new PharData($target);
                 foreach ($this->dirs as $archived_dir) {
                     $archive->addEmptyDir($archived_dir);
                 }
                 foreach ($this->files as $real_file => $archived_file) {
                     $archive->addFile($real_file, $archived_file);
                     // very, very slow :/
                 }
             }
         }
     } catch (Exeption $err) {
         return 500;
     }
     return @filesize($target) ? $target : null;
 }
开发者ID:avidys,项目名称:camunda.org,代码行数:43,代码来源:Archive.php

示例6: download

 /**
  * テンプレート一覧からのダウンロード
  *
  * @param Application $app
  * @param Request $request
  * @param $id
  */
 public function download(Application $app, Request $request, $id)
 {
     /** @var $Template \Eccube\Entity\Template */
     $Template = $app['eccube.repository.template']->find($id);
     if (!$Template) {
         throw new NotFoundHttpException();
     }
     // 該当テンプレートのディレクトリ
     $config = $app['config'];
     $templateCode = $Template->getCode();
     $targetRealDir = $config['root_dir'] . '/app/template/' . $templateCode;
     $targetHtmlRealDir = $config['root_dir'] . '/html/template/' . $templateCode;
     // 一時ディレクトリ
     $uniqId = sha1(Str::random(32));
     $tmpDir = $config['template_temp_realdir'] . '/' . $uniqId;
     $appDir = $tmpDir . '/app';
     $htmlDir = $tmpDir . '/html';
     // ファイル名
     $tarFile = $config['template_temp_realdir'] . '/' . $uniqId . '.tar';
     $tarGzFile = $tarFile . '.gz';
     $downloadFileName = $Template->getCode() . '.tar.gz';
     // 該当テンプレートを一時ディレクトリへコピーする.
     $fs = new Filesystem();
     $fs->mkdir(array($appDir, $htmlDir));
     $fs->mirror($targetRealDir, $appDir);
     $fs->mirror($targetHtmlRealDir, $htmlDir);
     // tar.gzファイルに圧縮する.
     $phar = new \PharData($tarFile);
     $phar->buildFromDirectory($tmpDir);
     // appディレクトリがない場合は, 空ディレクトリを追加
     // @see https://github.com/EC-CUBE/ec-cube/issues/742
     if (empty($phar['app'])) {
         $phar->addEmptyDir('app');
     }
     $phar->compress(\Phar::GZ);
     // ダウンロード完了後にファイルを削除する.
     // http://stackoverflow.com/questions/15238897/removing-file-after-delivering-response-with-silex-symfony
     $app->finish(function (Request $request, Response $response, \Silex\Application $app) use($tmpDir, $tarFile, $tarGzFile) {
         $app['monolog']->addDebug('remove temp file: ' . $tmpDir);
         $app['monolog']->addDebug('remove temp file: ' . $tarFile);
         $app['monolog']->addDebug('remove temp file: ' . $tarGzFile);
         $fs = new Filesystem();
         $fs->remove($tmpDir);
         $fs->remove($tarFile);
         $fs->remove($tarGzFile);
     });
     return $app->sendFile($tarGzFile)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $downloadFileName);
 }
开发者ID:hiroyasu55,项目名称:ec-cube,代码行数:55,代码来源:TemplateController.php

示例7: tarData

 public function tarData($tarFile, $cron)
 {
     $log = vglobal('log');
     $log->info('BackUp - Start ZipArchive');
     $dbFiles = $this->getFilesStructure();
     $destination = $this->tempDir . '/' . $tarFile . '.tar';
     $tar = new PharData($destination);
     $count = 0;
     foreach ($dbFiles as $id => $path) {
         if (is_dir($path)) {
             $tar->addEmptyDir($path . '/');
         } elseif (is_file($path)) {
             $tar->addFile($path, $path);
         }
         $this->markFile($id);
         if ($count == $this->ajaxFilesLimit && $cron == FALSE) {
             $percentage = $this->getPercentage();
             exit(json_encode(['percentage' => $percentage]));
         }
         $count++;
     }
     //$tar->compress(Phar::GZ);
 }
开发者ID:awflu,项目名称:YetiForceCRM,代码行数:23,代码来源:Module.php

示例8: dirname

<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar';
$phar = new PharData($fname);
$phar->addEmptyDir('blah/');
$phar->addFromString('test/', '');
copy($fname, $fname2);
$phar = new PharData($fname2);
var_dump($phar['blah']->isDir(), $phar['test']->isDir());
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar');
__halt_compiler();
?>
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:bug46060.php

示例9: PharData

 $fname = IA_ROOT . "/data/tmp.tar";
 $phar = new PharData($fname);
 $phar->addFromString('/manifest.xml', $manifest);
 if ($mDefine) {
     $phar->addFromString('/module.php', $mDefine);
 }
 if ($pDefine) {
     $phar->addFromString('/processor.php', $pDefine);
 }
 if ($rDefine) {
     $phar->addFromString('/receiver.php', $rDefine);
 }
 if ($sDefine) {
     $phar->addFromString('/site.php', $sDefine);
 }
 $phar->addEmptyDir('/template');
 if ($m['application']['setting']) {
     $phar->addFromString("/template/setting.html", "{template 'common/header'}\r\n这里定义页面内容\r\n{template 'common/footer'}");
 }
 if ($m['icon']) {
     $phar->addFile($m['icon'], '/icon.jpg');
     @unlink($m['icon']);
 }
 if ($m['preview']) {
     $phar->addFile($m['preview'], '/preview.jpg');
     @unlink($m['preview']);
 }
 header('content-type: application/tar');
 header('content-disposition: attachment; filename="' . $ident . '.tar"');
 readfile($fname);
 unset($phar);
开发者ID:alextiannus,项目名称:wormwood_wechat,代码行数:31,代码来源:designer.ctrl.php

示例10: _zipFile

 /**
  * Archiving the file
  *
  * @param unknown $filePath
  * @param string $preFix
  * @param string $debug
  * @throws Exception
  */
 private static function _zipFile($files, $preFix = '', $debug = false)
 {
     $tarFilePath = self::$_outputFileDir . '/' . self::FILE_NAME . '.tar';
     $start = self::_log('== Archiving the file: ' . $tarFilePath, __CLASS__ . '::' . __FUNCTION__, $preFix);
     $csvFilePath = '/tmp/' . md5('ProductToMagento_CSV_' . trim(UDate::now())) . '.csv';
     $tarFile = new PharData($tarFilePath);
     //add csv file
     self::_log('Generating the CSV file: ' . $csvFilePath, '', $preFix . self::TAB);
     $objWriter = PHPExcel_IOFactory::createWriter($files['phpExcel'], 'CSV');
     $objWriter->save($csvFilePath);
     self::_log('Adding the CSV file to: ' . $tarFilePath, '', $preFix . self::TAB);
     $tarFile->addFile($csvFilePath, self::FILE_NAME . '.csv');
     //add image files
     if (isset($files['imageFiles']) && count($files['imageFiles']) > 0) {
         $imageDir = self::$_imageDirName;
         $tarFile->addEmptyDir($imageDir);
         foreach ($files['imageFiles'] as $index => $imageFile) {
             self::_log('Processing file: ' . $index, '', $preFix . self::TAB . self::TAB);
             if (!isset($imageFile['filePath'])) {
                 self::_log('No File Path SET. SKIP ', '', $preFix . self::TAB . self::TAB . self::TAB);
                 continue;
             }
             if (!is_file($imageFile['filePath'])) {
                 self::_log('File NOT FOUND: ' . $imageFile['filePath'], '', $preFix . self::TAB . self::TAB . self::TAB);
                 continue;
             }
             $tarFile->addFile($imageFile['filePath'], $imageDir . '/' . $imageFile['fileName']);
             self::_log('Added File:' . $imageFile['fileName'] . ', from path: ' . $imageFile['filePath'], '', $preFix . self::TAB . self::TAB . self::TAB);
         }
     } else {
         self::_log('No image files to add.', '', $preFix . self::TAB);
     }
     // COMPRESS archive.tar FILE. COMPRESSED FILE WILL BE archive.tar.gz
     self::_log('Compressing file: ' . $tarFilePath, '', $preFix . self::TAB . self::TAB . self::TAB);
     $tarFile->compress(Phar::GZ);
     // NOTE THAT BOTH FILES WILL EXISTS. SO IF YOU WANT YOU CAN UNLINK archive.tar
     self::_log('REMOVING the orginal file: ' . $tarFilePath, '', $preFix . self::TAB);
     unlink($tarFilePath);
     self::_log('REMOVED', '', $preFix . self::TAB . self::TAB);
     //remving temp csv file
     self::_log('REMOVING the tmp csv file: ' . $csvFilePath, '', $preFix . self::TAB);
     unlink($csvFilePath);
     self::_log('REMOVED', '', $preFix . self::TAB . self::TAB);
     self::_log('== Archived', __CLASS__ . '::' . __FUNCTION__, $preFix, $start);
 }
开发者ID:larryu,项目名称:magento-b2b,代码行数:53,代码来源:ProductToMagento.php


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