During normalization, all slashes are replaced by forward slashes ("/").
Contrary to {@link canonicalize()}, this method does not remove invalid
or dot path segments. Consequently, it is much more efficient and should
be used whenever the given path is known to be a valid, absolute system
path.
This method is able to deal with both UNIX and Windows paths.
/** * Rebuild the puli dependencies for symfony container. */ protected function rebuild(InputInterface $input, OutputInterface $output) { $puli = new Puli(Path::join([getcwd(), NANBANDO_DIR])); $puli->start(); /** @var EmbeddedComposerInterface $embeddedComposer */ $embeddedComposer = $this->getApplication()->getEmbeddedComposer(); $packageManager = $puli->getPackageManager(); $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()); $composer = $embeddedComposer->createComposer($io); $installationManager = $composer->getInstallationManager(); $rootPackage = $composer->getPackage(); $repository = $composer->getRepositoryManager()->getLocalRepository(); $packages = []; foreach ($repository->getPackages() as $package) { $packages[$package->getName()] = $package; } foreach ($rootPackage->getRequires() as $require) { if (!array_key_exists($require->getTarget(), $packages)) { continue; } $packageManager->installPackage(Path::normalize($installationManager->getInstallPath($packages[$require->getTarget()])), $require->getTarget(), 'nanbando'); } $filesystem = new Filesystem(); $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, '.puli'])); $discoveryManager = $puli->getDiscoveryManager(); if (!$discoveryManager->hasRootTypeDescriptor('nanbando/bundle')) { $discoveryManager->addRootTypeDescriptor(new BindingTypeDescriptor(new BindingType('nanbando/bundle')), 0); } $discoveryManager->clearDiscovery(); $discoveryManager->buildDiscovery(); $filesystem = new Filesystem(); $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, 'app', 'cache'])); }
/** * Creates a temporary directory. * * @param string $namespace The directory path in the system's temporary * directory. * @param string $className The name of the test class. * * @return string The path to the created directory. */ public static function makeTempDir($namespace, $className) { if (false !== ($pos = strrpos($className, '\\'))) { $shortClass = substr($className, $pos + 1); } else { $shortClass = $className; } // Usage of realpath() is important if the temporary directory is a // symlink to another directory (e.g. /var => /private/var on some Macs) // We want to know the real path to avoid comparison failures with // code that uses real paths only $systemTempDir = Path::normalize(realpath(sys_get_temp_dir())); $basePath = $systemTempDir . '/' . $namespace . '/' . $shortClass; while (false === @mkdir($tempDir = $basePath . rand(10000, 99999), 0777, true)) { // Run until we are able to create a directory } return $tempDir; }
/** * @param PackageInterface[] $composerPackages * @param bool[] $prodPackageNames * @param PuliPackage[] $puliPackages * @param IOInterface $io * @param Composer $composer */ private function installNewPackages(array $composerPackages, array $prodPackageNames, array &$puliPackages, IOInterface $io, Composer $composer) { $installationManager = $composer->getInstallationManager(); foreach ($composerPackages as $packageName => $package) { if ($package instanceof AliasPackage) { $package = $package->getAliasOf(); } // We need to normalize the system-dependent paths returned by Composer $installPath = Path::normalize($installationManager->getInstallPath($package)); $env = isset($prodPackageNames[$packageName]) ? PuliPackage::ENV_PROD : PuliPackage::ENV_DEV; // Skip meta packages if ('' === $installPath) { continue; } if (isset($puliPackages[$packageName])) { $puliPackage = $puliPackages[$packageName]; // Only proceed if the install path or environment has changed if ($installPath === $puliPackage->getInstallPath() && $env === $puliPackage->getEnvironment()) { continue; } // Only remove packages installed by Composer if (self::INSTALLER_NAME === $puliPackage->getInstallerName()) { $io->write(sprintf('Reinstalling <info>%s</info> (<comment>%s</comment>) in <comment>%s</comment>', $packageName, Path::makeRelative($installPath, $this->rootDir), $env)); try { $this->removePackage($packageName); } catch (PuliRunnerException $e) { $this->printPackageWarning($io, 'Could not remove package "%s" (at ./%s)', $packageName, $installPath, $e); continue; } } } else { $io->write(sprintf('Installing <info>%s</info> (<comment>%s</comment>) in <comment>%s</comment>', $packageName, Path::makeRelative($installPath, $this->rootDir), $env)); } try { $this->installPackage($installPath, $packageName, $env); } catch (PuliRunnerException $e) { $this->printPackageWarning($io, 'Could not install package "%s" (at ./%s)', $packageName, $installPath, $e); continue; } $puliPackages[$packageName] = new PuliPackage($packageName, self::INSTALLER_NAME, $installPath, PuliPackage::STATE_ENABLED, $env); } }
/** * @expectedException \InvalidArgumentException */ public function testNormalizeFailsIfNoString() { Path::normalize(true); }