本文整理汇总了PHP中Composer\Util\Filesystem::normalizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::normalizePath方法的具体用法?PHP Filesystem::normalizePath怎么用?PHP Filesystem::normalizePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Util\Filesystem
的用法示例。
在下文中一共展示了Filesystem::normalizePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dumpFiles
/**
* @param \Composer\Composer
* @param string
* @param string
*/
public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer')
{
$installationManager = $composer->getInstallationManager();
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$mainPackage = $composer->getPackage();
$config = $composer->getConfig();
$filesystem = new Filesystem();
$basePath = $filesystem->normalizePath(realpath(getcwd()));
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
$targetDir = $vendorPath . '/' . $targetDir;
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
$autoloads = $this->parseAutoloads($packageMap, $mainPackage);
$paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage);
$autoloads['files'] = array_merge($paths, $autoloads['files']);
$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);
}
}
示例2: normalize
private function normalize(string $path) : string
{
if (!$this->filesystem->isAbsolutePath($path)) {
$path = $this->basePath . '/' . $path;
}
return $this->filesystem->normalizePath($path);
}
示例3: getIncludeFileContent
/**
* Constructs the include file content
*
* @return string
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
protected function getIncludeFileContent()
{
$includeFileTemplate = $this->filesystem->normalizePath(__DIR__ . '/../' . self::RESOURCES_PATH . '/' . self::INCLUDE_FILE_TEMPLATE);
$includeFileContent = file_get_contents($includeFileTemplate);
foreach ($this->tokens as $token) {
$includeFileContent = self::replaceToken($token->getName(), $token->getContent(), $includeFileContent);
}
return $includeFileContent;
}
示例4: onPostInstallCommand
public function onPostInstallCommand(ScriptEvent $event)
{
$config = $event->getComposer()->getConfig();
$filesystem = new Filesystem();
$vendor_path = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
$cake_dir = $filesystem->normalizePath($vendor_path . '/cakephp/cakephp');
$root_dir = $filesystem->normalizePath(realpath(""));
$app_dir = $filesystem->normalizePath($root_dir . '/app');
if (!is_dir($app_dir)) {
$this->copyRecursive($filesystem->normalizePath($cake_dir . '/app'), $app_dir);
$index_path = $filesystem->normalizePath($app_dir . '/webroot/index.php');
$index = str_replace('define(\'CAKE_CORE_INCLUDE_PATH\', ROOT);', 'define(\'CAKE_CORE_INCLUDE_PATH\', ROOT . \'vendor\' . DS . \'cakephp\' . DS . \'cakephp\');', file_get_contents($index_path));
file_put_contents($index_path, $index);
$loader_of_old_php_path = $filesystem->normalizePath($vendor_path . '/atomita/loader-of-less-than-php5.3-plugin');
if (file_exists($loader_of_old_php_path)) {
$loader = <<<EOD
// @generated by atomita/cakephp1-setup-plugin
include(ROOT . DS . '{$config->get('vendor-dir')}' . DS . 'autoload.php');
// @end generated
EOD;
$config_path = $filesystem->normalizePath($app_dir . '/config/core.php');
$config = file_get_contents($config_path);
if (false === strpos($config, $loader)) {
file_put_contents($config_path, $config . PHP_EOL . PHP_EOL . $loader);
}
}
}
}
示例5: archive
/**
* {@inheritdoc}
*/
public function archive($sources, $target, $format, array $excludes = array())
{
$fs = new Filesystem();
$sources = $fs->normalizePath($sources);
$zip = new ZipArchive();
$res = $zip->open($target, ZipArchive::CREATE);
if ($res === true) {
$files = new ArchivableFilesFinder($sources, $excludes);
foreach ($files as $file) {
/** @var $file \SplFileInfo */
$filepath = strtr($file->getPath() . "/" . $file->getFilename(), '\\', '/');
$localname = str_replace($sources . '/', '', $filepath);
if ($file->isDir()) {
$zip->addEmptyDir($localname);
} else {
$zip->addFile($filepath, $localname);
}
}
if ($zip->close()) {
return $target;
}
}
$message = sprintf("Could not create archive '%s' from '%s': %s", $target, $sources, $zip->getStatusString());
throw new \RuntimeException($message);
}
示例6: 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;
}
示例7: 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;
}
示例8: __construct
/**
* Initializes the internal Symfony Finder with appropriate filters
*
* @param string $sources Path to source files to be archived
* @param array $excludes Composer's own exclude rules from composer.json
*/
public function __construct($sources, array $excludes)
{
$fs = new Filesystem();
$sources = $fs->normalizePath($sources);
$filters = array(new HgExcludeFilter($sources), new GitExcludeFilter($sources), new ComposerExcludeFilter($sources, $excludes));
$this->finder = new Finder\Finder();
$this->finder->in($sources)->filter(function (\SplFileInfo $file) use($sources, $filters, $fs) {
$relativePath = preg_replace('#^' . preg_quote($sources, '#') . '#', '', $fs->normalizePath($file->getRealPath()));
$exclude = false;
foreach ($filters as $filter) {
$exclude = $filter->filter($relativePath, $exclude);
}
return !$exclude;
})->ignoreVCS(true)->ignoreDotFiles(false);
parent::__construct($this->finder->getIterator());
}
示例9: getClassmap
public function getClassmap() : \Traversable
{
$filesystem = new Filesystem();
$vendorPath = $filesystem->normalizePath(realpath($this->config->get('vendor-dir')));
$classmapPath = $vendorPath . '/composer/autoload_classmap.php';
if (!is_file($classmapPath)) {
throw new \RuntimeException('Th dumped classmap does not exists. Try to run `composer dump-autoload --optimize` first.');
}
yield from (include $vendorPath . '/composer/autoload_classmap.php');
}
示例10: setUp
protected function setUp()
{
$fs = new Filesystem();
$this->fs = $fs;
$this->sources = $fs->normalizePath(realpath(sys_get_temp_dir()) . '/composer_archiver_test' . uniqid(mt_rand(), true));
$fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo');
foreach ($fileTree as $relativePath) {
$path = $this->sources . '/' . $relativePath;
$fs->ensureDirectoryExists(dirname($path));
file_put_contents($path, '');
}
}
示例11: setUp
protected function setUp()
{
$fs = new Filesystem();
$this->fs = $fs;
$this->sources = $fs->normalizePath(realpath(sys_get_temp_dir()) . '/composer_archiver_test' . uniqid(mt_rand(), true));
$fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'C/prefixA.foo', 'C/prefixB.foo', 'C/prefixC.foo', 'C/prefixD.foo', 'C/prefixE.foo', 'C/prefixF.foo', 'D/prefixA', 'D/prefixB', 'D/prefixC', 'D/prefixD', 'D/prefixE', 'D/prefixF', 'E/subtestA.foo', 'F/subtestA.foo', 'G/subtestA.foo', 'H/subtestA.foo', 'I/J/subtestA.foo', 'K/dirJ/subtestA.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo', 'parameters.yml', 'parameters.yml.dist', '!important!.txt', '!important_too!.txt');
foreach ($fileTree as $relativePath) {
$path = $this->sources . '/' . $relativePath;
$fs->ensureDirectoryExists(dirname($path));
file_put_contents($path, '');
}
}
示例12: setUp
protected function setUp()
{
$fs = new Filesystem();
$this->fs = $fs;
$this->sources = $fs->normalizePath($this->getUniqueTmpDirectory());
$fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'C/prefixA.foo', 'C/prefixB.foo', 'C/prefixC.foo', 'C/prefixD.foo', 'C/prefixE.foo', 'C/prefixF.foo', 'D/prefixA', 'D/prefixB', 'D/prefixC', 'D/prefixD', 'D/prefixE', 'D/prefixF', 'E/subtestA.foo', 'F/subtestA.foo', 'G/subtestA.foo', 'H/subtestA.foo', 'I/J/subtestA.foo', 'K/dirJ/subtestA.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo', 'parameters.yml', 'parameters.yml.dist', '!important!.txt', '!important_too!.txt', '#weirdfile');
foreach ($fileTree as $relativePath) {
$path = $this->sources . '/' . $relativePath;
$fs->ensureDirectoryExists(dirname($path));
file_put_contents($path, '');
}
}
示例13: __construct
public function __construct($sources, array $excludes)
{
$fs = new Filesystem();
$sources = $fs->normalizePath($sources);
$filters = array(new HgExcludeFilter($sources), new GitExcludeFilter($sources), new ComposerExcludeFilter($sources, $excludes));
$this->finder = new Finder\Finder();
$filter = function (\SplFileInfo $file) use($sources, $filters, $fs) {
if ($file->isLink() && strpos($file->getLinkTarget(), $sources) !== 0) {
return false;
}
$relativePath = preg_replace('#^' . preg_quote($sources, '#') . '#', '', $fs->normalizePath($file->getRealPath()));
$exclude = false;
foreach ($filters as $filter) {
$exclude = $filter->filter($relativePath, $exclude);
}
return !$exclude;
};
if (method_exists($filter, 'bindTo')) {
$filter = $filter->bindTo(null);
}
$this->finder->in($sources)->filter($filter)->ignoreVCS(true)->ignoreDotFiles(false);
parent::__construct($this->finder->getIterator());
}
示例14: createMap
/**
* Iterate over all files in the given directory searching for classes
*
* @param \Iterator|string $path The path to search in or an iterator
* @param string $blacklist Regex that matches against the file path that exclude from the classmap.
* @param IOInterface $io IO object
* @param string $namespace Optional namespace prefix to filter by
*
* @throws \RuntimeException When the path is neither an existing file nor directory
* @return array A class map array
*/
public static function createMap($path, $blacklist = null, IOInterface $io = null, $namespace = null)
{
if (is_string($path)) {
if (is_file($path)) {
$path = array(new \SplFileInfo($path));
} elseif (is_dir($path)) {
$path = Finder::create()->files()->followLinks()->name('/\\.(php|inc|hh)$/')->in($path);
} else {
throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder');
}
}
$map = array();
$filesystem = new Filesystem();
$cwd = getcwd();
foreach ($path as $file) {
$filePath = $file->getPathname();
if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) {
continue;
}
if (!$filesystem->isAbsolutePath($filePath)) {
$filePath = $cwd . '/' . $filePath;
$filePath = $filesystem->normalizePath($filePath);
} else {
$filePath = preg_replace('{[\\\\/]{2,}}', '/', $filePath);
}
if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
continue;
}
$classes = self::findClasses($filePath);
foreach ($classes as $class) {
// skip classes not within the given namespace prefix
if (null !== $namespace && 0 !== strpos($class, $namespace)) {
continue;
}
if (!isset($map[$class])) {
$map[$class] = $filePath;
} elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
$io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>');
}
}
}
return $map;
}
示例15: onPostAutoloadDump
public function onPostAutoloadDump(ScriptEvent $event)
{
$banner = 'by atomita/loader-of-less-than-php5.3-plugin';
$config = $event->getComposer()->getConfig();
$filesystem = new Filesystem();
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
$targetDir = $vendorPath . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR;
$file = $vendorPath . DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($file)) {
$content = explode('<?php', file_get_contents($file), 2);
$content = str_replace('__DIR__', 'dirname(__FILE__)', end($content));
$append = <<<EOD
<?php
// @appended {$banner}
require dirname(__FILE__) . implode(DIRECTORY_SEPARATOR, explode('/', '/atomita/loader-of-less-than-php5.3-plugin/src/autoload-wrapper.php'));
EOD;
file_put_contents($file, $append . $content);
foreach (glob($targetDir . '*.php') as $path) {
$content = file_get_contents($path);
switch (true) {
case $this->endsWith(DIRECTORY_SEPARATOR . 'ClassLoader.php', $path):
$content = str_replace('namespace Composer\\Autoload;', '// namespace Composer\\Autoload;', $content);
$content = str_replace('\\InvalidArgumentException', 'InvalidArgumentException;', $content);
$content = str_replace('spl_autoload_register(array($this, \'loadClass\'), true, $prepend);', 'spl_autoload_register(array($this, \'loadClass\'));', $content);
break;
case $this->endsWith(DIRECTORY_SEPARATOR . 'autoload_real.php', $path):
$content = str_replace('\'Composer\\Autoload\\ClassLoader\'', '\'ClassLoader\'', $content);
$content = str_replace('\\Composer\\Autoload\\ClassLoader', 'ClassLoader', $content);
$content = preg_replace('/spl_autoload_register\\(array\\(\'([^\']*?)\', \'loadClassLoader\'\\), true, true\\);/', 'spl_autoload_register(array(\'${1}\', \'loadClassLoader\'));', $content);
default:
$content = str_replace('__DIR__', 'dirname(__FILE__)', $content);
break;
}
file_put_contents($path, $content);
}
}
}