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


PHP Filesystem::ensureDirectoryExists方法代码示例

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


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

示例1: initialize

 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (Filesystem::isLocalPath($this->url)) {
         $this->repoDir = $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', $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 --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($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:composer-fork,项目名称:composer,代码行数:35,代码来源:HgDriver.php

示例2: 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

示例3: 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

示例4: 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

示例5: setUp

 public function setUp()
 {
     $this->filesystem = new Filesystem();
     $this->process = new ProcessExecutor();
     $this->testDir = sys_get_temp_dir() . '/composer_archiver_test_' . mt_rand();
     $this->filesystem->ensureDirectoryExists($this->testDir);
 }
开发者ID:alancleaver,项目名称:composer,代码行数:7,代码来源:ArchiverTest.php

示例6: setUp

 protected function setUp()
 {
     $this->rootDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-contao';
     $this->fs = new Filesystem();
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->fs->ensureDirectoryExists($this->rootDir . '/system');
 }
开发者ID:Jobu,项目名称:core,代码行数:7,代码来源:RunonceManagerTest.php

示例7: copyFile

 private function copyFile($from, $to)
 {
     if (!is_file($from)) {
         throw new \RuntimeException('Invalid PEAR package. package.xml defines file that is not located inside tarball.');
     }
     $this->filesystem->ensureDirectoryExists(dirname($to));
     if (!copy($from, $to)) {
         throw new \RuntimeException(sprintf('Failed to copy %s to %s', $from, $to));
     }
 }
开发者ID:rodchyn,项目名称:composer,代码行数:10,代码来源:PearPackageExtractor.php

示例8: downloadManagerDownload

 public function downloadManagerDownload($package, $path)
 {
     $this->filesystem->ensureDirectoryExists($path);
     foreach ($this->typo3Files as $file) {
         $dir = dirname($file);
         if ($dir) {
             $this->filesystem->ensureDirectoryExists($path . '/' . $dir);
         }
         file_put_contents($path . '/' . $file, $file);
     }
 }
开发者ID:netresearch,项目名称:composer-installers,代码行数:11,代码来源:TestCase.php

示例9: generate

    /**
     * @param string $destination
     * @param array $references
     */
    public function generate($destination, array $references)
    {
        $this->filesystem->ensureDirectoryExists(dirname($destination));
        $referencesPhp = var_export($references, true);
        $text = <<<EOF
<?php
namespace ComposerRevisions;

class Revisions
{
    public static \$byName = {$referencesPhp};
}
EOF;
        file_put_contents($destination, $text);
    }
开发者ID:mcuelenaere,项目名称:composer-revision-plugin,代码行数:19,代码来源:ReferenceClassGenerator.php

示例10: testExcludeFromClassmap

 public function testExcludeFromClassmap()
 {
     $package = new Package('a', '1.0', '1.0');
     $package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')), 'psr-4' => array('Acme\\Fruit\\' => 'src-fruit/', 'Acme\\Cake\\' => array('src-cake/', 'lib-cake/')), 'classmap' => array('composersrc/'), 'exclude-from-classmap' => array('/composersrc/excludedTests/', '/composersrc/ClassToExclude.php', '/composersrc/*/excluded/excsubpath', '**/excsubpath')));
     $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array()));
     $this->fs->ensureDirectoryExists($this->workingDir . '/composer');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src/Lala/Test');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib');
     file_put_contents($this->workingDir . '/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
     file_put_contents($this->workingDir . '/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\\Test; class ClassMapMainTest {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-fruit');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-cake');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib-cake');
     file_put_contents($this->workingDir . '/src-cake/ClassMapBar.php', '<?php namespace Acme\\Cake; class ClassMapBar {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/tests');
     file_put_contents($this->workingDir . '/composersrc/foo.php', '<?php class ClassMapFoo {}');
     // this classes should not be found in the classmap
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/excludedTests');
     file_put_contents($this->workingDir . '/composersrc/excludedTests/bar.php', '<?php class ClassExcludeMapFoo {}');
     file_put_contents($this->workingDir . '/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/long/excluded/excsubpath');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/foo.php', '<?php class ClassExcludeMapFoo2 {}');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/bar.php', '<?php class ClassExcludeMapBar {}');
     $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
     // Assert that autoload_classmap.php was correctly generated.
     $this->assertAutoloadFiles('classmap', $this->vendorDir . '/composer', 'classmap');
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-composer,代码行数:28,代码来源:AutoloadGeneratorTest.php

示例11: persistConfig

 /**
  * Persist the stored configuration.
  *
  * @since 0.1.0
  *
  * @param Event $event Event that was triggered.
  */
 public static function persistConfig(Event $event)
 {
     $filesystem = new Filesystem();
     $path = Paths::getPath('git_composter');
     $filesystem->ensureDirectoryExists($path);
     file_put_contents(Paths::getPath('git_config'), static::getConfig());
 }
开发者ID:php-composter,项目名称:php-composter,代码行数:14,代码来源:Plugin.php

示例12: copyFile

 private function copyFile($from, $to, $tasks, $vars)
 {
     if (!is_file($from)) {
         throw new \RuntimeException('Invalid PEAR package. package.xml defines file that is not located inside tarball.');
     }
     $this->filesystem->ensureDirectoryExists(dirname($to));
     if (0 == count($tasks)) {
         $copied = copy($from, $to);
     } else {
         $content = file_get_contents($from);
         $replacements = array();
         foreach ($tasks as $task) {
             $pattern = $task['from'];
             $varName = $task['to'];
             if (isset($vars[$varName])) {
                 if ($varName === 'php_bin' && false === strpos($to, '.bat')) {
                     $replacements[$pattern] = preg_replace('{\\.bat$}', '', $vars[$varName]);
                 } else {
                     $replacements[$pattern] = $vars[$varName];
                 }
             }
         }
         $content = strtr($content, $replacements);
         $copied = file_put_contents($to, $content);
     }
     if (false === $copied) {
         throw new \RuntimeException(sprintf('Failed to copy %s to %s', $from, $to));
     }
 }
开发者ID:Flesh192,项目名称:magento,代码行数:29,代码来源:PearPackageExtractor.php

示例13: initialize

 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         $fs = new Filesystem();
         $fs->ensureDirectoryExists(dirname($this->repoDir));
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir) . '" directory is not writable by the current user.');
         }
         // 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->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:nickelc,项目名称:composer,代码行数:37,代码来源:GitDriver.php

示例14: testCoreIsCwd

 /**
  * Test that a Contao installation can be found within current working directory.
  */
 public function testCoreIsCwd()
 {
     $plugin = $this->clearTest();
     $this->fs->ensureDirectoryExists($this->testRoot . '/system');
     $package = new RootPackage('test/package', '1.0.0.0', '1.0.0');
     $this->assertEquals($this->testRoot, $plugin->getContaoRoot($package));
 }
开发者ID:Jobu,项目名称:core,代码行数:10,代码来源:GetContaoRootTest.php

示例15: testUninstall

 public function testUninstall()
 {
     $this->fs->ensureDirectoryExists($this->pluginDir);
     $installer = new GingerInstaller($this->io, $this->composer);
     $repository = new ComposerRepositoryMock();
     $package = new Package('gingerwfms/wf-configurator-backend', '1.0.0', '1.0.0');
     $package->setType('ginger-backend-plugin');
     $package->setExtra(array('plugin-namespace' => 'WfConfiguratorBackend'));
     $repository->addPackage($package);
     $gate = new Gate();
     $mockBus = new CqrsBusMock();
     $pluginNamespace = '';
     $pluginName = '';
     $pluginType = '';
     $pluginVersion = '';
     $mockBus->mapCommand('GingerPluginInstaller\\Cqrs\\UninstallPluginCommand', function (UninstallPluginCommand $command) use(&$pluginNamespace, &$pluginName, &$pluginType, &$pluginVersion) {
         $pluginNamespace = $command->getPluginNamespace();
         $pluginName = $command->getPluginName();
         $pluginType = $command->getPluginType();
         $pluginVersion = $command->getPluginVersion();
     });
     $gate->attach($mockBus);
     $gate->setDefaultBusName($mockBus->getName());
     Bootstrap::getServiceManager()->setAllowOverride(true);
     Bootstrap::getServiceManager()->setService('malocher.cqrs.gate', $gate);
     $installer->uninstall($repository, $package);
     $this->assertSame('WfConfiguratorBackend', $pluginNamespace);
     $this->assertSame('gingerwfms/wf-configurator-backend', $pluginName);
     $this->assertSame('ginger-backend-plugin', $pluginType);
     $this->assertSame('1.0.0', $pluginVersion);
 }
开发者ID:gingerwfms,项目名称:ginger-plugin-installer,代码行数:31,代码来源:GingerInstallerTest.php


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