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


PHP Util\Filesystem类代码示例

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


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

示例1: dump

 /**
  * Builds the archives of the repository.
  *
  * @param array $packages List of packages to dump
  */
 public function dump(array $packages)
 {
     $helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
     $directory = $helper->getDirectory($this->outputDir);
     $this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
     $format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
     $endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
     $includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
     $composerConfig = Factory::createConfig();
     $factory = new Factory();
     $io = new ConsoleIO($this->input, $this->output, $this->helperSet);
     $io->loadConfiguration($composerConfig);
     /* @var \Composer\Downloader\DownloadManager $downloadManager */
     $downloadManager = $factory->createDownloadManager($io, $composerConfig);
     /* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
     $archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
     $archiveManager->setOverwriteFiles(false);
     shuffle($packages);
     /* @var \Composer\Package\CompletePackage $package */
     foreach ($packages as $package) {
         if ($helper->isSkippable($package)) {
             continue;
         }
         $this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
         try {
             if ('pear-library' === $package->getType()) {
                 // PEAR packages are archives already
                 $filesystem = new Filesystem();
                 $packageName = $archiveManager->getPackageFilename($package);
                 $path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
                 if (!file_exists($path)) {
                     $downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
                     $filesystem->ensureDirectoryExists($downloadDir);
                     $downloadManager->download($package, $downloadDir, false);
                     $filesystem->ensureDirectoryExists($directory);
                     $filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
                     $filesystem->removeDirectory($downloadDir);
                 }
                 // Set archive format to `file` to tell composer to download it as is
                 $archiveFormat = 'file';
             } else {
                 $path = $archiveManager->archive($package, $format, $directory);
                 $archiveFormat = $format;
             }
             $archive = basename($path);
             $distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
             $package->setDistType($archiveFormat);
             $package->setDistUrl($distUrl);
             if ($includeArchiveChecksum) {
                 $package->setDistSha1Checksum(hash_file('sha1', $path));
             }
             $package->setDistReference($package->getSourceReference());
         } catch (\Exception $exception) {
             if (!$this->skipErrors) {
                 throw $exception;
             }
             $this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
         }
     }
 }
开发者ID:robertgit,项目名称:satis,代码行数:65,代码来源:ArchiveBuilder.php

示例2: archive

 /**
  * {@inheritdoc}
  */
 public function archive($sources, $target, $format, array $excludes = array())
 {
     $fs = new Filesystem();
     $sources = $fs->normalizePath($sources);
     $zip = new ZipArchive();
     $res = $zip->open($target, ZipArchive::CREATE);
     if ($res === true) {
         $files = new ArchivableFilesFinder($sources, $excludes);
         foreach ($files as $file) {
             /** @var $file \SplFileInfo */
             $filepath = strtr($file->getPath() . "/" . $file->getFilename(), '\\', '/');
             $localname = str_replace($sources . '/', '', $filepath);
             if ($file->isDir()) {
                 $zip->addEmptyDir($localname);
             } else {
                 $zip->addFile($filepath, $localname);
             }
         }
         if ($zip->close()) {
             return $target;
         }
     }
     $message = sprintf("Could not create archive '%s' from '%s': %s", $target, $sources, $zip->getStatusString());
     throw new \RuntimeException($message);
 }
开发者ID:neon64,项目名称:composer,代码行数:28,代码来源:ZipArchiver.php

示例3: initialize

 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $this->repoDir = $this->config->get('home') . '/cache.git/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         // update the repo if it is a valid git repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
             if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) {
                 $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs = new Filesystem();
             $fs->removeDirectory($this->repoDir);
             // added in git 1.7.1, prevents prompting the user
             putenv('GIT_ASKPASS=echo');
             $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
             if (0 !== $this->process->execute($command, $output)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
开发者ID:rufinus,项目名称:composer,代码行数:33,代码来源:GitDriver.php

示例4: testIntegration

 /**
  * @dataProvider getTestFiles
  */
 public function testIntegration(\SplFileInfo $testFile)
 {
     $testData = $this->parseTestFile($testFile);
     $cmd = 'php ' . __DIR__ . '/../../../bin/composer --no-ansi ' . $testData['RUN'];
     $proc = new Process($cmd);
     $exitcode = $proc->run();
     if (isset($testData['EXPECT'])) {
         $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-ERROR'])) {
         $this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-ERROR-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-EXIT-CODE'])) {
         $this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
     }
     // Clean up.
     $fs = new Filesystem();
     if (isset($testData['test_dir']) && is_dir($testData['test_dir'])) {
         $fs->removeDirectory($testData['test_dir']);
     }
 }
开发者ID:rufinus,项目名称:composer,代码行数:30,代码来源:AllFunctionalTest.php

示例5: testBuildPhar

 public function testBuildPhar()
 {
     if (defined('HHVM_VERSION')) {
         $this->markTestSkipped('Building the phar does not work on HHVM.');
     }
     $target = dirname(self::$pharPath);
     $fs = new Filesystem();
     $fs->removeDirectory($target);
     $fs->ensureDirectoryExists($target);
     chdir($target);
     $it = new \RecursiveDirectoryIterator(__DIR__ . '/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
     $ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($ri as $file) {
         $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
         if ($file->isDir()) {
             $fs->ensureDirectoryExists($targetPath);
         } else {
             copy($file->getPathname(), $targetPath);
         }
     }
     $proc = new Process('php ' . escapeshellarg('./bin/compile'), $target);
     $exitcode = $proc->run();
     if ($exitcode !== 0 || trim($proc->getOutput())) {
         $this->fail($proc->getOutput());
     }
     $this->assertTrue(file_exists(self::$pharPath));
 }
开发者ID:alancleaver,项目名称:composer,代码行数:27,代码来源:AllFunctionalTest.php

示例6: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filesystem = new Filesystem();
     $packageName = $this->getPackageFilename($name = $this->argument('name'));
     if (!($targetDir = $this->option('dir'))) {
         $targetDir = $this->container->path();
     }
     $sourcePath = $this->container->get('path.packages') . '/' . $name;
     $filesystem->ensureDirectoryExists($targetDir);
     $target = realpath($targetDir) . '/' . $packageName . '.zip';
     $filesystem->ensureDirectoryExists(dirname($target));
     $exludes = [];
     if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) {
         $jsonFile = new JsonFile($composerJsonPath);
         $jsonData = $jsonFile->read();
         if (!empty($jsonData['archive']['exclude'])) {
             $exludes = $jsonData['archive']['exclude'];
         }
         if (!empty($jsonData['archive']['scripts'])) {
             system($jsonData['archive']['scripts'], $return);
             if ($return !== 0) {
                 throw new \RuntimeException('Can not executes scripts.');
             }
         }
     }
     $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.zip';
     $filesystem->ensureDirectoryExists(dirname($tempTarget));
     $archiver = new PharArchiver();
     $archivePath = $archiver->archive($sourcePath, $tempTarget, 'zip', $exludes);
     rename($archivePath, $target);
     $filesystem->remove($tempTarget);
     return $target;
 }
开发者ID:4nxiety,项目名称:pagekit,代码行数:36,代码来源:ArchiveCommand.php

示例7: tearDown

 public function tearDown()
 {
     if (is_dir($this->tmpdir)) {
         $fs = new Filesystem();
         $fs->removeDirectory($this->tmpdir);
     }
 }
开发者ID:AppChecker,项目名称:composer,代码行数:7,代码来源:RepositoryManagerTest.php

示例8: tearDown

 protected function tearDown()
 {
     if (is_dir($this->root)) {
         $fs = new Filesystem();
         $fs->removeDirectory($this->root);
     }
 }
开发者ID:teguhsaputra,项目名称:composer,代码行数:7,代码来源:CacheTest.php

示例9: checkDuplicates

 /**
  * Duplicates search packages
  *
  * @param string $templatePath
  * @param array $vars
  */
 protected function checkDuplicates($templatePath, array $vars = array())
 {
     /**
      * Incorrect paths for backward compatibility
      */
     $oldLocations = array('module' => 'local/modules/{$name}/', 'component' => 'local/components/{$name}/', 'theme' => 'local/templates/{$name}/');
     $packageType = substr($vars['type'], strlen('bitrix') + 1);
     $oldLocation = str_replace('{$name}', $vars['name'], $oldLocations[$packageType]);
     if (in_array($oldLocation, static::$checkedDuplicates)) {
         return;
     }
     if ($oldLocation !== $templatePath && file_exists($oldLocation) && $this->io && $this->io->isInteractive()) {
         $this->io->writeError('    <error>Duplication of packages:</error>');
         $this->io->writeError('    <info>Package ' . $oldLocation . ' will be called instead package ' . $templatePath . '</info>');
         while (true) {
             switch ($this->io->ask('    <info>Delete ' . $oldLocation . ' [y,n,?]?</info> ', '?')) {
                 case 'y':
                     $fs = new Filesystem();
                     $fs->removeDirectory($oldLocation);
                     break 2;
                 case 'n':
                     break 2;
                 case '?':
                 default:
                     $this->io->writeError(['    y - delete package ' . $oldLocation . ' and to continue with the installation', '    n - don\'t delete and to continue with the installation']);
                     $this->io->writeError('    ? - print help');
                     break;
             }
         }
     }
     static::$checkedDuplicates[] = $oldLocation;
 }
开发者ID:ksan5835,项目名称:rankproperties,代码行数:38,代码来源:BitrixInstaller.php

示例10: tearDown

    protected function tearDown()
    {
        parent::tearDown();

        $fs = new Filesystem();
        $fs->remove($this::TEST_PATH);
    }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:7,代码来源:PerforceTest.php

示例11: initialize

 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $this->repoDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         // update the repo if it is a valid git repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
             $this->process->execute('git remote update --prune origin', $output, $this->repoDir);
         } else {
             // clean up directory and do a fresh clone into it
             $fs = new Filesystem();
             $fs->removeDirectory($this->repoDir);
             $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
             if (0 !== $this->process->execute($command, $output)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
开发者ID:nlegoff,项目名称:composer,代码行数:29,代码来源:GitDriver.php

示例12: checkDuplicates

 /**
  * Duplicates search packages.
  *
  * @param string $path
  * @param array $vars
  */
 protected function checkDuplicates($path, array $vars = array())
 {
     $packageType = substr($vars['type'], strlen('bitrix') + 1);
     $localDir = explode('/', $vars['bitrix_dir']);
     array_pop($localDir);
     $localDir[] = 'local';
     $localDir = implode('/', $localDir);
     $oldPath = str_replace(array('{$bitrix_dir}', '{$name}'), array($localDir, $vars['name']), $this->locations[$packageType]);
     if (in_array($oldPath, static::$checkedDuplicates)) {
         return;
     }
     if ($oldPath !== $path && file_exists($oldPath) && $this->io && $this->io->isInteractive()) {
         $this->io->writeError('    <error>Duplication of packages:</error>');
         $this->io->writeError('    <info>Package ' . $oldPath . ' will be called instead package ' . $path . '</info>');
         while (true) {
             switch ($this->io->ask('    <info>Delete ' . $oldPath . ' [y,n,?]?</info> ', '?')) {
                 case 'y':
                     $fs = new Filesystem();
                     $fs->removeDirectory($oldPath);
                     break 2;
                 case 'n':
                     break 2;
                 case '?':
                 default:
                     $this->io->writeError(array('    y - delete package ' . $oldPath . ' and to continue with the installation', '    n - don\'t delete and to continue with the installation'));
                     $this->io->writeError('    ? - print help');
                     break;
             }
         }
     }
     static::$checkedDuplicates[] = $oldPath;
 }
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:38,代码来源:BitrixInstaller.php

示例13: initialize

 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $cacheDir = $this->config->get('cache-vcs-dir');
         $this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
         $fs = new Filesystem();
         $fs->ensureDirectoryExists($cacheDir);
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir . '" directory is not writable by the current user.');
         }
         // update the repo if it is a valid hg repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) {
             if (0 !== $this->process->execute('hg pull -u', $output, $this->repoDir)) {
                 $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs->removeDirectory($this->repoDir);
             if (0 !== $this->process->execute(sprintf('hg clone %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir)), $output, $cacheDir)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('hg --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:35,代码来源:HgDriver.php

示例14: getTargetPath

 /**
  * Get the target path for a rendered file from a template file.
  *
  * @since 0.1.0
  *
  * @param string $pathname The path and file name to the template file.
  *
  * @return string The target path and file name to use for the rendered file.
  */
 protected function getTargetPath($pathname)
 {
     $filesystem = new Filesystem();
     $templatesFolder = $this->getConfigKey('Folders', 'templates');
     $folderDiff = '/' . $filesystem->findShortestPath(SetupHelper::getRootFolder(), $templatesFolder);
     return (string) $this->removeTemplateExtension(str_replace($folderDiff, '', $pathname));
 }
开发者ID:brightnucleus,项目名称:boilerplate,代码行数:16,代码来源:MoveTemplateFilesToRootFolder.php

示例15: run

 /**
  * Runs the project configurator.
  *
  * @return void
  */
 public function run()
 {
     $namespace = $this->ask('Namespace', function ($namespace) {
         return $this->validateNamespace($namespace);
     }, 'App');
     $packageName = $this->ask('Package name', function ($packageName) {
         return $this->validatePackageName($packageName);
     }, $this->suggestPackageName($namespace));
     $license = $this->ask('License', function ($license) {
         return trim($license);
     }, 'proprietary');
     $description = $this->ask('Description', function ($description) {
         return trim($description);
     }, '');
     $file = new JsonFile('./composer.json');
     $config = $file->read();
     $config['name'] = $packageName;
     $config['license'] = $license;
     $config['description'] = $description;
     $config['autoload']['psr-4'] = [$namespace . '\\' => 'src/'];
     $config['autoload-dev']['psr-4'] = [$namespace . '\\Tests\\' => 'tests/'];
     unset($config['scripts']['post-root-package-install']);
     $config['extra']['branch-alias']['dev-master'] = '1.0-dev';
     $file->write($config);
     $this->composer->setPackage(Factory::create($this->io, null, true)->getPackage());
     // reload root package
     $filesystem = new Filesystem();
     $filesystem->removeDirectory('./app/Distribution');
 }
开发者ID:gerryvdm,项目名称:symfony-skeleton,代码行数:34,代码来源:ProjectConfigurator.php


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