本文整理汇总了PHP中Composer\Util\Filesystem::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::remove方法的具体用法?PHP Filesystem::remove怎么用?PHP Filesystem::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Util\Filesystem
的用法示例。
在下文中一共展示了Filesystem::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testComposerInstallAndUpdate
/**
* Tests a simple composer install without core, but adding core later.
*/
public function testComposerInstallAndUpdate()
{
$exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php';
$this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.');
$this->composer('install');
$this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . 'core', 'Drupal core is installed.');
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.');
$this->fs->remove($exampleScaffoldFile);
$this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.');
$this->composer('drupal-scaffold');
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.');
foreach (['8.0.1', '8.1.x-dev'] as $version) {
// We touch a scaffold file, so we can check the file was modified after
// the scaffold update.
touch($exampleScaffoldFile);
$mtime_touched = filemtime($exampleScaffoldFile);
// Requiring a newer version triggers "composer update"
$this->composer('require --update-with-dependencies drupal/core:"' . $version . '"');
clearstatcache();
$mtime_after = filemtime($exampleScaffoldFile);
$this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')');
}
// We touch a scaffold file, so we can check the file was modified after
// the custom commandscaffold update.
touch($exampleScaffoldFile);
clearstatcache();
$mtime_touched = filemtime($exampleScaffoldFile);
$this->composer('drupal-scaffold');
clearstatcache();
$mtime_after = filemtime($exampleScaffoldFile);
$this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by custom command.');
}
示例2: tearDown
public function tearDown()
{
if (is_dir($this->workingDir)) {
$this->fs->removeDirectory($this->workingDir);
}
if (is_file($this->testFile)) {
$this->fs->remove($this->testFile);
}
}
示例3: tearDown
protected function tearDown()
{
$this->package = null;
$this->composer = null;
$this->io = null;
$fs = new Filesystem();
$fs->remove(sys_get_temp_dir() . '/composer-test-repo-cache');
$fs->remove(sys_get_temp_dir() . '/composer-test/vendor');
}
示例4: complete
/**
* Remove style.css and functions.php if the package type
* is not a wordpress-theme
*/
public function complete()
{
$type = $this->getConfigKey('Placeholders', 'type')['value'];
if ($type === 'wordpress-theme') {
return;
}
$fs = new Util\Filesystem();
$base_dir = $this->getConfigKey('BaseDir');
$this->io->write("Removing theme files");
$fs->remove("{$base_dir}/style.css");
$fs->remove("{$base_dir}/functions.php");
}
示例5: remove
/**
* Remove (unlink) the destination file
*
* @param string $source
* @param string $dest
*
* @throws \ErrorException
*/
public function remove($source, $dest)
{
$sourcePath = $this->getSourceDir() . '/' . ltrim($this->removeTrailingSlash($source), '\\/');
$destPath = $this->getDestDir() . '/' . ltrim($dest, '\\/');
// If source doesn't exist, check if it's a glob expression, otherwise we have nothing we can do
if (!file_exists($sourcePath)) {
// Handle globing
$matches = glob($sourcePath);
if (!empty($matches)) {
foreach ($matches as $match) {
$newDest = substr($destPath . '/' . basename($match), strlen($this->getDestDir()));
$newDest = ltrim($newDest, ' \\/');
$this->remove(substr($match, strlen($this->getSourceDir()) + 1), $newDest);
}
}
return;
}
// MP Avoid removing whole folders in case the modman file is not 100% well-written
// e.g. app/etc/modules/Testmodule.xml app/etc/modules/ installs correctly,
// but would otherwise delete the whole app/etc/modules folder!
if (basename($sourcePath) !== basename($destPath)) {
$destPath .= '/' . basename($source);
}
$this->filesystem->remove($destPath);
$this->addRemovedFile($destPath);
}
示例6: tearDown
protected function tearDown()
{
parent::tearDown();
$fs = new Filesystem();
$fs->remove($this::TEST_PATH);
}
示例7: cleanPackage
/**
* Clean a package, based on its rules.
*
* @param BasePackage $package The package to clean
* @return bool True if cleaned
*/
protected function cleanPackage(BasePackage $package)
{
// Only clean 'dist' packages
if ($package->getInstallationSource() !== 'dist') {
return false;
}
$vendorDir = $this->config->get('vendor-dir');
$targetDir = $package->getTargetDir();
$packageName = $package->getPrettyName();
$packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName;
$rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null;
if (!$rules) {
return;
}
$dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir));
if (!is_dir($dir)) {
return false;
}
foreach ((array) $rules as $part) {
// Split patterns for single globs (should be max 260 chars)
$patterns = explode(' ', trim($part));
foreach ($patterns as $pattern) {
try {
foreach (glob($dir . '/' . $pattern) as $file) {
$this->filesystem->remove($file);
}
} catch (\Exception $e) {
$this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage());
}
}
}
return true;
}
示例8: cleanPackage
/**
* Clean a package, based on its rules.
*
* @param BasePackage $package The package to clean
* @return bool True if cleaned
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function cleanPackage(BasePackage $package)
{
$vendorDir = $this->config->get('vendor-dir');
$targetDir = $package->getTargetDir();
$packageName = $package->getPrettyName();
$packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName;
$rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null;
if (!$rules) {
$this->io->writeError('Rules not found: ' . $packageName);
return false;
}
$dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir));
if (!is_dir($dir)) {
$this->io->writeError('Vendor dir not found: ' . $vendorDir . '/' . $packageDir);
return false;
}
//$this->io->write('Rules: ' . print_r($rules, true));
foreach ((array) $rules as $part) {
// Split patterns for single globs (should be max 260 chars)
$patterns = (array) $part;
foreach ($patterns as $pattern) {
try {
foreach (glob($dir . '/' . $pattern) as $file) {
$this->filesystem->remove($file);
//$this->io->write('File removed: ' . $file);
}
} catch (\Exception $e) {
$this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage());
}
}
}
return true;
}
示例9: 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;
}
示例10: tryCleanup
/**
* Try to cleanup a file/dir, output on exception
*/
private function tryCleanup(string $path, string $errorMsg)
{
try {
$this->filesystem->remove($path);
} catch (\RuntimeException $ex) {
$this->io->write($errorMsg);
}
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
$remoteFilesystem = new RemoteFilesystem($this->getIO());
$config = Factory::createConfig();
$cacheDir = $config->get('cache-dir');
$rollbackDir = $config->get('home');
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
$tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
if (!is_writable($tmpDir)) {
throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
}
if (!is_writable($localFilename)) {
throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written');
}
if ($input->getOption('rollback')) {
return $this->rollback($output, $rollbackDir, $localFilename);
}
$latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false));
$updateVersion = $input->getArgument('version') ?: $latestVersion;
if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
$output->writeln('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
return 1;
}
if (Composer::VERSION === $updateVersion) {
$output->writeln('<info>You are already using composer version ' . $updateVersion . '.</info>');
return 0;
}
$tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
$backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
$output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
$remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
$remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename);
if (!file_exists($tempFilename)) {
$output->writeln('<error>The download of the new composer version failed for an unexpected reason</error>');
return 1;
}
if ($input->getOption('clean-backups')) {
$files = $this->getOldInstallationFiles($rollbackDir);
if (!empty($files)) {
$fs = new Filesystem();
foreach ($files as $file) {
$output->writeln('<info>Removing: ' . $file . '</info>');
$fs->remove($file);
}
}
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
$output->writeln('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
return 1;
}
if (file_exists($backupFile)) {
$output->writeln('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
} else {
$output->writeln('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
}
}
示例12: cleanup
/**
* Deletes all files and directories that matches patterns.
*/
public function cleanup()
{
if ($this->isEnabled() && $this->hasPattern() && realpath($this->installDir)) {
$paths = iterator_to_array($this->finder->in($this->installDir));
/* @var \SplFileInfo $path */
foreach ($paths as $path) {
$this->filesystem->remove($path);
}
}
}
示例13: complete
/**
* Complete the setup task.
*
* @since 0.1.0
*
* @return void
*/
public function complete()
{
$filesystem = new Filesystem();
foreach ($this->getRootFiles() as $file) {
try {
$filesystem->remove(SetupHelper::getFile($file));
} catch (Exception $exception) {
$this->io->writeError(sprintf('Could not remove file "%1$s". Reason: %2$s', SetupHelper::getFile($file), $exception->getMessage()));
}
}
}
示例14: complete
/**
* Override the default task due to static directory references
*/
public function complete()
{
$fs = new Util\Filesystem();
$base_dir = $this->getConfigKey('BaseDir');
foreach ($this->getRootFiles() as $file) {
try {
$fs->remove("{$base_dir}/{$file}");
} catch (Exception $exception) {
$this->io->writeError(sprintf(_('Could not remove file "%1$s". Reason: %2$s'), $file, $exception->getMessage()));
}
}
}
示例15: complete
/**
* Renames the plugin file to {{package}}.php,
* removes it, if the package is not of type wordpress-plugin
*/
public function complete()
{
$fs = new Util\Filesystem();
$base_dir = $this->getConfigKey('BaseDir');
$type = $this->getConfigKey('Placeholders', 'type')['value'];
$package = $this->getConfigKey('Placeholders', 'package_key')['value'];
$plugin_file = "{$base_dir}/plugin.php";
if ('wordpress-plugin' === $type) {
$fs->copyThenRemove($plugin_file, "{$base_dir}/{$package}.php");
return;
}
$this->io->write("Removing plugin file");
$fs->remove($plugin_file);
}