public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) { if ($package instanceof AliasPackage) { return $repo->hasPackage($package) && $this->isPackageInstalled($repo, $package->getAliasOf()); } return $this->getInstaller($package->getType())->isInstalled($repo, $package); }
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } $repo->removePackage($package); }
/** * @test */ public function update() { $initial = $this->createPackageMock(); $target = $this->createPackageMock(); $this->installer->expects($this->once())->method('update')->with($this->repository, $initial, $target); $this->repository->expects($this->once())->method('hasPackage')->with($initial)->willReturn(true); $this->createSolver()->update($this->repository, $initial, $target); }
/** * {@inheritDoc} */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { return; } $this->removeBinaries($package); $repo->removePackage($package); }
/** * {@inheritDoc} */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125) return; throw new \InvalidArgumentException('Package is not installed: ' . $package); } $repo->removePackage($package); }
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } $repo->removePackage($package); $installPath = $this->getInstallPath($package); $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); }
/** * @param string $packageName * @param string $sourceDirectory * @param string $targetDirectory */ protected static function mirrorDirectory($packageName, $sourceDirectory, $targetDirectory) { $packages = static::$localRepository->findPackages($packageName, null); foreach ($packages as $package) { if (static::$installationManager->getInstaller($package->getType())->isInstalled(static::$localRepository, $package)) { static::getFileSystem()->mirror(static::$installationManager->getInstallPath($package) . '/' . ltrim($sourceDirectory, '/'), $targetDirectory, null, ['copy_on_windows']); return; } } }
private function isSymfonyPackagePresent(InstalledRepositoryInterface $repo, PackageInterface $package) { foreach ($repo->getPackages() as $installedPackage) { /* @var PackageInterface $installedPackage */ if ($installedPackage->getName() == 'symfony/symfony') { return true; } } return false; }
public function updateCode(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { if (!$repo->hasPackage($initial)) { throw new \InvalidArgumentException('Package is not installed: ' . $initial); } if ($initial->getInstallationSource() == 'source' && $initial->getSourceType() == 'git' && $target->getSourceType() == 'git') { $this->downloadManager->update($initial, $target, $this->getInstallPath($target)); } else { $this->installCode($target); } $repo->removePackage($initial); if (!$repo->hasPackage($target)) { $repo->addPackage(clone $target); } }
/** * {@inheritDoc} */ public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { // Debug $this->debug = $this->isDebug($package); // Composer stuff $this->initializeVendorDir(); $downloadPath = $this->getInstallPath($package); if (!is_readable($downloadPath) && $repo->hasPackage($package)) { $this->removeBinaries($package); } if (!$repo->hasPackage($package)) { $repo->addPackage(clone $package); } $this->downloadAndExtractFile($package); }
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } $this->removeCode($package); $this->removeBinaries($package); $repo->removePackage($package); $downloadPath = $this->getPackageBasePath($package); if (strpos($package->getName(), '/')) { $packageVendorDir = dirname($downloadPath); if (is_dir($packageVendorDir) && $this->filesystem->isDirEmpty($packageVendorDir)) { @rmdir($packageVendorDir); } } }
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'); }
/** * @test */ public function uninstallKeepSources() { $this->io->expects($this->once())->method('askConfirmation')->willReturn(false); /** @var SymlinkFilesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */ $filesystem = $this->getMock('\\LEtudiant\\Composer\\Util\\SymlinkFilesystem'); $filesystem->expects($this->once())->method('removeSymlink')->willReturn(true); $installer = $this->createInstaller($this->config, $filesystem); $package = $this->createPackageMock(); $this->repository->expects($this->once())->method('removePackage')->with($package); $this->dm->expects($this->never())->method('remove'); $this->dataManager->expects($this->once())->method('removePackageUsage')->with($package); $installer->uninstall($this->repository, $package); }
/** * @test */ public function uninstallDevelopment() { $this->io->expects($this->once())->method('askConfirmation')->willReturn(true); /** @var SymlinkFilesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */ $filesystem = $this->getMock('\\LEtudiant\\Composer\\Util\\SymlinkFilesystem'); $filesystem->expects($this->once())->method('removeSymlink')->willReturn(true); $library = new SharedPackageInstaller($this->io, $this->composer, $filesystem, $this->dataManager); $package = $this->createDevelopmentPackageMock(); $this->repository->expects($this->exactly(1))->method('hasPackage')->with($package)->will($this->onConsecutiveCalls(true, true)); $this->repository->expects($this->once())->method('removePackage')->with($package); $this->dm->expects($this->once())->method('remove')->with($package, $this->dependenciesDir . '/letudiant/foo-bar/dev-develop'); $this->dataManager->expects($this->once())->method('removePackageUsage')->with($package); $library->uninstall($this->repository, $package); }
public function testIgnoredBundles() { $packages = array($this->createPackage('foo/foo-bundle', 'symfony-bundle', array('psr-0' => array('Acme\\FooBundle' => ''))), $this->createPackage('acme/library-bundle', 'symfony-bundle', array('psr-0' => array('Acme\\LibraryBundle' => '')))); $rootPackage = new RootPackage('DemoPackage', 'dev-master', '1.x-dev'); $rootPackage->setExtra(array('checkbundles-ignore' => array('Acme\\LibraryBundle\\AcmeLibraryBundle'))); $this->composerMock->expects($this->any())->method('getPackage')->will($this->returnValue($rootPackage)); $this->localRepository->expects($this->any())->method('getPackages')->will($this->returnValue($packages)); $kernelHelper = $this->getMockBuilder('WillemJan\\Util\\KernelHelper')->disableOriginalConstructor()->setMethods(array('getBundlesForKernels'))->getMock(); $kernelHelper->expects($this->any())->method('getBundlesForKernels')->will($this->returnValue(array('Acme\\FooBundle\\AcmeFooBundle'))); $composerHelper = $this->getMockBuilder('WillemJan\\CheckBundles\\Util\\ComposerHelper')->setConstructorArgs(array($this->composerMock))->setMethods(array('getInstalledRepository', 'findBundleFiles'))->getMock(); $composerHelper->expects($this->any())->method('findBundleFiles')->will($this->returnCallback(function ($package) use($packages) { switch ($package->getName()) { case 'foo/foo-bundle': return array('AcmeFooBundle.php'); break; case 'acme/library-bundle': return array('AcmeLibraryBundle.php'); break; } return array('ShouldNotHappenBundle.php'); })); $composerHelper->expects($this->any())->method('getInstalledRepository')->will($this->returnValue($this->localRepository)); $this->assertEquals(array(), $composerHelper->getNonActiveSymfonyBundles($kernelHelper->getBundlesForKernels())); }
public function testVendorSubstringPath() { $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('psr-0' => array('Foo' => 'composer-test-autoload-src/src'), 'psr-4' => array('Acme\\Foo\\' => 'composer-test-autoload-src/src-psr4'))); $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array())); $this->fs->ensureDirectoryExists($this->vendorDir . '/a'); $expectedNamespace = <<<'EOF' <?php // autoload_namespaces.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( 'Foo' => array($baseDir . '/composer-test-autoload-src/src'), ); EOF; $expectedPsr4 = <<<'EOF' <?php // autoload_psr4.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( 'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'), ); EOF; $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring'); $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir . '/composer/autoload_namespaces.php')); $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir . '/composer/autoload_psr4.php')); }
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') { if ($this->classMapAuthoritative) { // Force scanPsr0Packages when classmap is authoritative $scanPsr0Packages = true; } $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); $cwd = getcwd(); $basePath = $filesystem->normalizePath($cwd); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $targetDir = $vendorPath . '/' . $targetDir; $filesystem->ensureDirectoryExists($targetDir); $useGlobalIncludePath = (bool) $config->get('use-include-path'); $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true'; $classMapAuthoritative = $config->get('classmap-authoritative'); $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); // add 5.2 compat $vendorPathCode = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $vendorPathToTargetDirCode = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathToTargetDirCode); $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); $autoloads = $this->parseAutoloads($packageMap, $mainPackage); // add custom psr-0 autoloading if the root package has a target dir $targetDirLoader = null; $mainAutoload = $mainPackage->getAutoload(); if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) { $levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir()))); $prefixes = implode(', ', array_map(function ($prefix) { return var_export($prefix, true); }, array_keys($mainAutoload['psr-0']))); $baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $basePath, true); $targetDirLoader = <<<EOF \tpublic static function autoload(\$class) { \t\t\$dir = {$baseDirFromTargetDirCode}.'/'; \t\t\$prefixes = array({$prefixes}); \t\tforeach (\$prefixes as \$prefix) { \t\t\tif (0 !== strpos(\$class, \$prefix)) { \t\t\t\tcontinue; \t\t\t} \t\t\t\$path = explode(DIRECTORY_SEPARATOR, self::getClassPath(\$class)); \t\t\t\$path = \$dir.implode('/', array_slice(\$path, {$levels})); \t\t\tif (!\$path = self::resolveIncludePath(\$path)) { \t\t\t\treturn false; \t\t\t} \t\t\trequire \$path; \t\t\treturn true; \t\t} \t} EOF; } $filesCode = ""; $autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files'])); foreach ($autoloads['files'] as $functionFile) { // don't include file if it is using PHP 5.3+ syntax // https://bitbucket.org/xrstf/composer-php52/issue/4 if ($this->isPHP53($functionFile)) { $filesCode .= '// require ' . $this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile) . "; // disabled because of PHP 5.3 syntax\n"; } else { $filesCode .= ' require ' . $this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile) . ";\n"; } } if (!$suffix) { $suffix = md5(uniqid('', true)); } $includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode); file_put_contents($vendorPath . '/autoload_52.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); file_put_contents($targetDir . '/autoload_real_52.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)); // use stream_copy_to_stream instead of copy // to work around https://bugs.php.net/bug.php?id=64634 $sourceLoader = fopen(__DIR__ . '/ClassLoader.php', 'r'); $targetLoader = fopen($targetDir . '/ClassLoader52.php', 'w+'); stream_copy_to_stream($sourceLoader, $targetLoader); fclose($sourceLoader); fclose($targetLoader); unset($sourceLoader, $targetLoader); }
/** * {@inheritDoc} */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125) return; throw new \InvalidArgumentException('Package is not installed: ' . $package); } $downloadPath = $this->getInstallPath($package); $this->removeCode($package); $this->removeBinaries($package); $repo->removePackage($package); if (strpos($package->getName(), '/')) { $packageVendorDir = dirname($downloadPath); if (is_dir($packageVendorDir) && !glob($packageVendorDir . '/*')) { @rmdir($packageVendorDir); } } }
public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) { return $repo->hasPackage($package); }
/** * Updates a package * * @param \Composer\Repository\InstalledRepositoryInterface $repo * @param \Composer\Package\PackageInterface $initial * @param \Composer\Package\PackageInterface $target * @throws \InvalidArgumentException */ public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { if (!$repo->hasPackage($initial)) { throw new CoreInstaller\PackageNotInstalledException($initial); } $this->getDriver()->update($initial, $target); $repo->removePackage($initial); if (!$repo->hasPackage($target)) { $repo->addPackage(clone $target); } }
/** * Uninstalls specific package. * * @param \Composer\Repository\InstalledRepositoryInterface $repo repository in which to check * @param \Composer\Package\PackageInterface $package package instance */ public function uninstall(\Composer\Repository\InstalledRepositoryInterface $repo, \Composer\Package\PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } if ($this->filesystem->someFilesExist($this->symlinks)) { $this->filesystem->removeSymlinks($this->symlinks); } $this->removeCode($package); $repo->removePackage($package); }
/** * @param InstalledRepositoryInterface $repo * @param PackageInterface $package * * @return bool */ public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) { // Just check if the sources folder and the link exist return $repo->hasPackage($package) && is_readable($this->getInstallPath($package)) && is_link($this->getPackageVendorSymlink($package)); }
/** * @param InstalledRepositoryInterface $repo * @param PackageInterface $package * * @throws FilesystemException */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if ($package->isDev()) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed : ' . $package->getPrettyName()); } $this->symlinkInstaller->uninstall($repo, $package); } else { $this->defaultInstaller->uninstall($repo, $package); } }
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') { if ($this->classMapAuthoritative) { // Force scanPsr0Packages when classmap is authoritative $scanPsr0Packages = true; } $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array('optimize' => (bool) $scanPsr0Packages)); $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); $basePath = $filesystem->normalizePath(realpath(getcwd())); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $useGlobalIncludePath = (bool) $config->get('use-include-path'); $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true'; $targetDir = $vendorPath . '/' . $targetDir; $filesystem->ensureDirectoryExists($targetDir); $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); $namespacesFile = <<<EOF <?php // autoload_namespaces.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; $psr4File = <<<EOF <?php // autoload_psr4.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; // Collect information from all packages. $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); $autoloads = $this->parseAutoloads($packageMap, $mainPackage); // Process the 'psr-0' base directories. foreach ($autoloads['psr-0'] as $namespace => $paths) { $exportedPaths = array(); foreach ($paths as $path) { $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); } $exportedPrefix = var_export($namespace, true); $namespacesFile .= " {$exportedPrefix} => "; $namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n"; } $namespacesFile .= ");\n"; // Process the 'psr-4' base directories. foreach ($autoloads['psr-4'] as $namespace => $paths) { $exportedPaths = array(); foreach ($paths as $path) { $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); } $exportedPrefix = var_export($namespace, true); $psr4File .= " {$exportedPrefix} => "; $psr4File .= "array(" . implode(', ', $exportedPaths) . "),\n"; } $psr4File .= ");\n"; $classmapFile = <<<EOF <?php // autoload_classmap.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; // add custom psr-0 autoloading if the root package has a target dir $targetDirLoader = null; $mainAutoload = $mainPackage->getAutoload(); if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) { $levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir()))); $prefixes = implode(', ', array_map(function ($prefix) { return var_export($prefix, true); }, array_keys($mainAutoload['psr-0']))); $baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $basePath, true); $targetDirLoader = <<<EOF public static function autoload(\$class) { \$dir = {$baseDirFromTargetDirCode} . '/'; \$prefixes = array({$prefixes}); foreach (\$prefixes as \$prefix) { if (0 !== strpos(\$class, \$prefix)) { continue; } \$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), {$levels})).'.php'; if (!\$path = stream_resolve_include_path(\$path)) { return false; } require \$path; return true; } } EOF; } $blacklist = null; if (!empty($autoloads['exclude-from-classmap'])) { $blacklist = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}'; } // flatten array $classMap = array(); if ($scanPsr0Packages) { $namespacesToScan = array(); // Scan the PSR-0/4 directories for class files, and add them to the class map foreach (array('psr-0', 'psr-4') as $psrType) { foreach ($autoloads[$psrType] as $namespace => $paths) { $namespacesToScan[$namespace][] = array('paths' => $paths, 'type' => $psrType); } } krsort($namespacesToScan); foreach ($namespacesToScan as $namespace => $groups) { foreach ($groups as $group) { $psrType = $group['type']; foreach ($group['paths'] as $dir) { $dir = $filesystem->normalizePath($filesystem->isAbsolutePath($dir) ? $dir : $basePath . '/' . $dir); if (!is_dir($dir)) { continue; } // $whitelist = sprintf( // '{%s/%s.+$}', // preg_quote($dir), // ($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($namespace, '\\', '/')) : '' // ); $namespaceFilter = $namespace === '' ? null : $namespace; $classMap = $this->addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $blacklist, $namespaceFilter, $classMap); } } } } foreach ($autoloads['classmap'] as $dir) { $classMap = $this->addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $blacklist, null, $classMap); } ksort($classMap); foreach ($classMap as $class => $code) { $classmapFile .= ' ' . var_export($class, true) . ' => ' . $code; } $classmapFile .= ");\n"; if (!$suffix) { if (!$config->get('autoloader-suffix') && is_readable($vendorPath . '/autoload.php')) { $content = file_get_contents($vendorPath . '/autoload.php'); if (preg_match('{ComposerAutoloaderInit([^:\\s]+)::}', $content, $match)) { $suffix = $match[1]; } } if (!$suffix) { $suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true)); } } file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile); file_put_contents($targetDir . '/autoload_psr4.php', $psr4File); file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile); $includePathFilePath = $targetDir . '/include_paths.php'; if ($includePathFileContents = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($includePathFilePath, $includePathFileContents); } elseif (file_exists($includePathFilePath)) { unlink($includePathFilePath); } $includeFilesFilePath = $targetDir . '/autoload_files.php'; if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($includeFilesFilePath, $includeFilesFileContents); } elseif (file_exists($includeFilesFilePath)) { unlink($includeFilesFilePath); } file_put_contents($vendorPath . '/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); file_put_contents($targetDir . '/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)); $this->safeCopy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php'); $this->safeCopy(__DIR__ . '/../../../LICENSE', $targetDir . '/LICENSE'); $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(), array('optimize' => (bool) $scanPsr0Packages)); }
/** * Remove symlinks for Contao sources before uninstalling a package. * * {@inheritdoc} * * @throws \InvalidArgumentException When the requested package is not installed. */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } $this->logVerbose(sprintf('Removing Contao sources for %s', $package->getName())); $this->removeSymlinks($package, $this->getContaoRoot(), $this->getSources($package)); parent::uninstall($repo, $package); $this->logVerbose(''); }
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { throw new \InvalidArgumentException('Package is not installed: ' . $package); } if ($package->getType() === MagentoInstaller::MAGENTO_SOURCE) { $repo->removePackage($package); $this->_makeBackup($repo, $package); } else { $repo->removePackage($package); $installPath = $this->getInstallPath($package); $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); } }
function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { $repo->removePackage($package); $installPath = $this->getInstallPath($package); $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); }
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') { $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode); $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); $basePath = $filesystem->normalizePath(realpath(getcwd())); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $useGlobalIncludePath = (bool) $config->get('use-include-path'); $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true'; $targetDir = $vendorPath . '/' . $targetDir; $filesystem->ensureDirectoryExists($targetDir); $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); $namespacesFile = <<<EOF <?php // autoload_namespaces.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; $psr4File = <<<EOF <?php // autoload_psr4.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; // Collect information from all packages. $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); $autoloads = $this->parseAutoloads($packageMap, $mainPackage); // Process the 'psr-0' base directories. foreach ($autoloads['psr-0'] as $namespace => $paths) { $exportedPaths = array(); foreach ($paths as $path) { $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); } $exportedPrefix = var_export($namespace, true); $namespacesFile .= " {$exportedPrefix} => "; $namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n"; } $namespacesFile .= ");\n"; // Process the 'psr-4' base directories. foreach ($autoloads['psr-4'] as $namespace => $paths) { $exportedPaths = array(); foreach ($paths as $path) { $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); } $exportedPrefix = var_export($namespace, true); $psr4File .= " {$exportedPrefix} => "; $psr4File .= "array(" . implode(', ', $exportedPaths) . "),\n"; } $psr4File .= ");\n"; $classmapFile = <<<EOF <?php // autoload_classmap.php @generated by Composer \$vendorDir = {$vendorPathCode52}; \$baseDir = {$appBaseDirCode}; return array( EOF; // add custom psr-0 autoloading if the root package has a target dir $targetDirLoader = null; $mainAutoload = $mainPackage->getAutoload(); if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) { $levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir()))); $prefixes = implode(', ', array_map(function ($prefix) { return var_export($prefix, true); }, array_keys($mainAutoload['psr-0']))); $baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $basePath, true); $targetDirLoader = <<<EOF public static function autoload(\$class) { \$dir = {$baseDirFromTargetDirCode} . '/'; \$prefixes = array({$prefixes}); foreach (\$prefixes as \$prefix) { if (0 !== strpos(\$class, \$prefix)) { continue; } \$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), {$levels})).'.php'; if (!\$path = stream_resolve_include_path(\$path)) { return false; } require \$path; return true; } } EOF; } // flatten array $classMap = array(); if ($scanPsr0Packages) { // Scan the PSR-0/4 directories for class files, and add them to the class map foreach (array('psr-0', 'psr-4') as $psrType) { foreach ($autoloads[$psrType] as $namespace => $paths) { foreach ($paths as $dir) { $dir = $filesystem->normalizePath($filesystem->isAbsolutePath($dir) ? $dir : $basePath . '/' . $dir); if (!is_dir($dir)) { continue; } $whitelist = sprintf('{%s/%s.+(?<!(?<!/)Test\\.php)$}', preg_quote($dir), $psrType === 'psr-0' && strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : ''); $namespaceFilter = $namespace === '' ? null : $namespace; foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) { if (!isset($classMap[$class])) { $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $classMap[$class] = $path . ",\n"; } } } } } } foreach ($autoloads['classmap'] as $dir) { foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) { $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $classMap[$class] = $path . ",\n"; } } ksort($classMap); foreach ($classMap as $class => $code) { $classmapFile .= ' ' . var_export($class, true) . ' => ' . $code; } $classmapFile .= ");\n"; if (!$suffix) { $suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true)); } file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile); file_put_contents($targetDir . '/autoload_psr4.php', $psr4File); file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile); if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($targetDir . '/include_paths.php', $includePathFile); } if ($includeFilesFile = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($targetDir . '/autoload_files.php', $includeFilesFile); } file_put_contents($vendorPath . '/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); file_put_contents($targetDir . '/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)); // use stream_copy_to_stream instead of copy // to work around https://bugs.php.net/bug.php?id=64634 $sourceLoader = fopen(__DIR__ . '/ClassLoader.php', 'r'); $targetLoader = fopen($targetDir . '/ClassLoader.php', 'w+'); stream_copy_to_stream($sourceLoader, $targetLoader); fclose($sourceLoader); fclose($targetLoader); unset($sourceLoader, $targetLoader); $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode); }
/** * {@inheritDoc} */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { $this->repository = $repo; $this->beforePatches($package, $package->getVersion(), '0'); if ($repo->hasPackage($package)) { $modules = 0; foreach ($this->getModulesPaths($package) as $path) { $this->uninstallModule($path, $package); $modules++; } if ($modules) { $this->io->write(''); } } $this->afterPatches($package, $package->getVersion(), '0'); parent::uninstall($repo, $package); }