本文整理汇总了PHP中Composer\Util\Filesystem::removeDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::removeDirectory方法的具体用法?PHP Filesystem::removeDirectory怎么用?PHP Filesystem::removeDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Util\Filesystem
的用法示例。
在下文中一共展示了Filesystem::removeDirectory方法的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();
}
示例2: ensureDirectoryExistsAndClear
/**
* Makes sure the given directory exists and has no content.
*
* @param string $directory
*/
protected function ensureDirectoryExistsAndClear($directory)
{
if (is_dir($directory)) {
$this->fs->removeDirectory($directory);
}
mkdir($directory, 0777, true);
}
示例3: tearDown
protected function tearDown()
{
if (is_dir($this->workingDir)) {
$this->fs->removeDirectory($this->workingDir);
}
// reset the static version cache
$refl = new \ReflectionProperty('Composer\\Util\\Git', 'version');
$refl->setAccessible(true);
$refl->setValue(null, null);
}
示例4: complete
/**
* Remove asset directories if the package is of type
* project or library
*/
public function complete()
{
$type = $this->getConfigKey('Placeholders', 'type')['value'];
$wp_types = ['wordpress-theme', 'wordpress-plugin'];
if (in_array($type, $wp_types)) {
return;
}
$base_dir = $this->getConfigKey('BaseDir');
$fs = new Util\Filesystem();
$this->io->write("Removing assets directories");
$fs->removeDirectory("{$base_dir}/assets");
$fs->removeDirectory("{$base_dir}/w-org-assets");
}
示例5: postCreateProject
public static function postCreateProject(Event $event)
{
$config = $event->getComposer()->getConfig();
$rootPath = dirname($config->get('vendor-dir'));
// cleanup
@unlink($rootPath . '/.travis.yml');
rename($rootPath . '/plugins_example', $rootPath . '/plugins');
rename($rootPath . '/website_example', $rootPath . '/website');
$filesystem = new Filesystem();
$filesystem->removeDirectory($rootPath . '/update');
$filesystem->removeDirectory($rootPath . '/build');
$filesystem->removeDirectory($rootPath . '/tests');
$filesystem->removeDirectory($rootPath . '/.svn');
$filesystem->removeDirectory($rootPath . '/.git');
}
示例6: tearDown
public function tearDown()
{
if (is_dir($this->tmpdir)) {
$fs = new Filesystem();
$fs->removeDirectory($this->tmpdir);
}
}
示例7: 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;
}
示例8: 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;
}
示例9: 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()));
}
}
}
示例10: 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']);
}
}
示例11: 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();
}
示例12: 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();
}
示例13: 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));
}
示例14: tearDown
protected function tearDown()
{
if (is_dir($this->workingDir)) {
$fs = new Filesystem();
$fs->removeDirectory($this->workingDir);
}
}
示例15: extractTo
/**
* Installs PEAR source files according to package.xml definitions and removes extracted files
*
* @param string $target target install location. all source installation would be performed relative to target path.
* @param array $roles types of files to install. default role for PEAR source files are 'php'.
* @param array $vars used for replacement tasks
* @throws \RuntimeException
* @throws \UnexpectedValueException
*
*/
public function extractTo($target, array $roles = array('php' => '/', 'script' => '/bin'), $vars = array())
{
$extractionPath = $target . '/tarball';
try {
$archive = new \PharData($this->file);
$archive->extractTo($extractionPath, null, true);
if (!is_file($this->combine($extractionPath, '/package.xml'))) {
throw new \RuntimeException('Invalid PEAR package. It must contain package.xml file.');
}
$fileCopyActions = $this->buildCopyActions($extractionPath, $roles, $vars);
$this->copyFiles($fileCopyActions, $extractionPath, $target, $roles, $vars);
$this->filesystem->removeDirectory($extractionPath);
} catch (\Exception $exception) {
throw new \UnexpectedValueException(sprintf('Failed to extract PEAR package %s to %s. Reason: %s', $this->file, $target, $exception->getMessage()), 0, $exception);
}
}