本文整理汇总了PHP中Composer\Installer\InstallationManager::getVendorPath方法的典型用法代码示例。如果您正苦于以下问题:PHP InstallationManager::getVendorPath方法的具体用法?PHP InstallationManager::getVendorPath怎么用?PHP InstallationManager::getVendorPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Installer\InstallationManager
的用法示例。
在下文中一共展示了InstallationManager::getVendorPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run installation (or update)
*/
public function run()
{
if ($this->dryRun) {
$this->verbose = true;
$this->runScripts = false;
$this->installationManager->addInstaller(new NoopInstaller());
}
if ($this->preferSource) {
$this->downloadManager->setPreferSource(true);
}
// create installed repo, this contains all local packages + platform packages (php & extensions)
$installedRootPackage = clone $this->package;
$installedRootPackage->setRequires(array());
$installedRootPackage->setDevRequires(array());
$repos = array_merge($this->repositoryManager->getLocalRepositories(), array(new InstalledArrayRepository(array($installedRootPackage)), new PlatformRepository()));
$installedRepo = new CompositeRepository($repos);
if ($this->additionalInstalledRepository) {
$installedRepo->addRepository($this->additionalInstalledRepository);
}
$aliases = $this->aliasPackages();
if ($this->runScripts) {
// dispatch pre event
$eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
$this->eventDispatcher->dispatchCommandEvent($eventName);
}
$this->suggestedPackages = array();
if (!$this->doInstall($this->repositoryManager->getLocalRepository(), $installedRepo, $aliases)) {
return false;
}
if ($this->devMode) {
if (!$this->doInstall($this->repositoryManager->getLocalDevRepository(), $installedRepo, $aliases, true)) {
return false;
}
}
// output suggestions
foreach ($this->suggestedPackages as $suggestion) {
if (!$installedRepo->findPackages($suggestion['target'])) {
$this->io->write($suggestion['source'] . ' suggests installing ' . $suggestion['target'] . ' (' . $suggestion['reason'] . ')');
}
}
if (!$this->dryRun) {
// write lock
if ($this->update || !$this->locker->isLocked()) {
$updatedLock = $this->locker->setLockData($this->repositoryManager->getLocalRepository()->getPackages(), $this->devMode ? $this->repositoryManager->getLocalDevRepository()->getPackages() : null, $aliases, $this->package->getMinimumStability(), $this->package->getStabilityFlags());
if ($updatedLock) {
$this->io->write('<info>Writing lock file</info>');
}
}
// write autoloader
$this->io->write('<info>Generating autoload files</info>');
$localRepos = new CompositeRepository($this->repositoryManager->getLocalRepositories());
$this->autoloadGenerator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath() . '/composer', true);
if ($this->runScripts) {
// dispatch post event
$eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
$this->eventDispatcher->dispatchCommandEvent($eventName);
}
}
return true;
}
示例2: dump
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
{
$autoloadFile = <<<'EOF'
<?php
// autoload.php generated by Composer
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
require __DIR__.'/ClassLoader.php';
}
$__composer_autoload_init = function() {
$loader = new \Composer\Autoload\ClassLoader();
$map = require __DIR__.'/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->add($namespace, $path);
}
$loader->register();
return $loader;
};
return $__composer_autoload_init();
EOF;
$filesystem = new Filesystem();
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath);
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$namespacesFile = <<<EOF
<?php
// autoload_namespace.php generated by Composer
\$vendorDir = {$vendorDirCode};
return array(
EOF;
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
$autoloads = $this->parseAutoloads($packageMap);
$appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
if (isset($autoloads['psr-0'])) {
foreach ($autoloads['psr-0'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$path = strtr($path, '\\', '/');
$baseDir = '';
if (!$filesystem->isAbsolutePath($path)) {
// vendor dir == working dir
if (preg_match('{^(\\./?)?$}', $relVendorPath)) {
$path = '/' . $path;
$baseDir = '$vendorDir . ';
} elseif (strpos($path, $relVendorPath) === 0) {
// path starts with vendor dir
$path = substr($path, strlen($relVendorPath));
$baseDir = '$vendorDir . ';
} else {
$path = '/' . $path;
$baseDir = $appBaseDir . ' . ';
}
} elseif (strpos($path, $vendorPath) === 0) {
$path = substr($path, strlen($vendorPath));
$baseDir = '$vendorDir . ';
}
$exportedPaths[] = $baseDir . var_export($path, true);
}
$exportedPrefix = var_export($namespace, true);
$namespacesFile .= " {$exportedPrefix} => ";
if (count($exportedPaths) > 1) {
$namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
} else {
$namespacesFile .= $exportedPaths[0] . ",\n";
}
}
}
$namespacesFile .= ");\n";
file_put_contents($targetDir . '/autoload.php', $autoloadFile);
file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
}
示例3: dump
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $bcLinks = false)
{
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($installationManager->getVendorPath());
$filesystem->ensureDirectoryExists($targetDir);
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
$namespacesFile = <<<EOF
<?php
// autoload_namespace.php generated by Composer
\$vendorDir = {$vendorPathCode};
\$baseDir = {$appBaseDirCode};
return array(
EOF;
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
$autoloads = $this->parseAutoloads($packageMap);
foreach ($autoloads['psr-0'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$exportedPaths[] = $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path);
}
$exportedPrefix = var_export($namespace, true);
$namespacesFile .= " {$exportedPrefix} => ";
if (count($exportedPaths) > 1) {
$namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
} else {
$namespacesFile .= $exportedPaths[0] . ",\n";
}
}
$namespacesFile .= ");\n";
$classmapFile = <<<EOF
<?php
// autoload_classmap.php generated by Composer
\$vendorDir = {$vendorPathCode};
\$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() && $mainAutoload['psr-0']) {
$levels = count(explode('/', trim(strtr($mainPackage->getTargetDir(), '\\', '/'), '/')));
$prefixes = implode(', ', array_map(function ($prefix) {
return var_export($prefix, true);
}, array_keys($mainAutoload['psr-0'])));
$baseDirFromVendorDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$targetDirLoader = <<<EOF
spl_autoload_register(function(\$class) {
\$dir = {$baseDirFromVendorDirCode} . '/';
\$prefixes = array({$prefixes});
foreach (\$prefixes as \$prefix) {
if (0 !== strpos(\$class, \$prefix)) {
continue;
}
\$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), {$levels})).'.php';
if (!stream_resolve_include_path(\$path)) {
return false;
}
require_once \$path;
return true;
}
});
EOF;
}
// flatten array
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
foreach ($autoloads['classmap'] as $dir) {
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
$path = '/' . $filesystem->findShortestPath(getcwd(), $path, true);
$classmapFile .= ' ' . var_export($class, true) . ' => $baseDir . ' . var_export($path, true) . ",\n";
}
}
$classmapFile .= ");\n";
file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile);
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)) {
file_put_contents($targetDir . '/include_paths.php', $includePathFile);
}
file_put_contents($vendorPath . '/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (bool) $includePathFile, $targetDirLoader));
copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
// TODO BC feature, remove after June 15th
if ($bcLinks) {
$filesystem->ensureDirectoryExists($vendorPath . '/.composer');
$deprecated = "// Deprecated file, use the one in root of vendor dir\n" . "trigger_error(__FILE__.' is deprecated, please use vendor/autoload.php or vendor/composer/autoload_* instead'.PHP_EOL.'See https://groups.google.com/forum/#!msg/composer-dev/fWIs3KocwoA/nU3aLko9LhQJ for details', E_USER_DEPRECATED);\n";
file_put_contents($vendorPath . '/.composer/autoload_namespaces.php', "<?php\n{$deprecated}\nreturn include dirname(__DIR__).'/composer/autoload_namespaces.php';\n");
//.........这里部分代码省略.........
示例4: run
//.........这里部分代码省略.........
}
foreach ($this->locker->getLockedPackages() as $package) {
$version = $package->getVersion();
foreach ($aliases as $alias) {
if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
$version = $alias['alias'];
break;
}
}
$constraint = new VersionConstraint('=', $version);
$request->install($package->getName(), $constraint);
}
} else {
$this->io->write('<info>Installing dependencies</info>');
$links = $this->collectLinks($noInstallRecommends, $installSuggests);
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
}
// prepare solver
$policy = new DefaultPolicy();
$solver = new Solver($policy, $pool, $installedRepo);
// solve dependencies
$operations = $solver->solve($request);
// force dev packages to be updated to latest reference on update
if ($update) {
foreach ($localRepo->getPackages() as $package) {
if ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
// skip non-dev packages
if (!$package->isDev()) {
continue;
}
// skip packages that will be updated/uninstalled
foreach ($operations as $operation) {
if ('update' === $operation->getJobType() && $package === $operation->getInitialPackage() || 'uninstall' === $operation->getJobType() && $package === $operation->getPackage()) {
continue 2;
}
}
// force update
$newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
$operations[] = new UpdateOperation($package, $newPackage);
}
}
}
// anti-alias local repository to allow updates to work fine
foreach ($this->repositoryManager->getLocalRepository()->getPackages() as $package) {
if ($package instanceof AliasPackage) {
$this->repositoryManager->getLocalRepository()->addPackage(clone $package->getAliasOf());
$this->repositoryManager->getLocalRepository()->removePackage($package);
}
}
// execute operations
if (!$operations) {
$this->io->write('<info>Nothing to install/update</info>');
}
foreach ($operations as $operation) {
if ($verbose) {
$this->io->write((string) $operation);
}
if (!$dryRun) {
$this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
// if installing from lock, restore dev packages' references to their locked state
if ($installFromLock) {
$package = null;
if ('update' === $operation->getJobType()) {
$package = $operation->getTargetPackage();
} elseif ('install' === $operation->getJobType()) {
$package = $operation->getPackage();
}
if ($package && $package->isDev()) {
$lockData = $this->locker->getLockData();
foreach ($lockData['packages'] as $lockedPackage) {
if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
$package->setSourceReference($lockedPackage['source-reference']);
break;
}
}
}
}
$this->installationManager->execute($operation);
$this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
}
}
if (!$dryRun) {
if ($update || !$this->locker->isLocked()) {
$this->locker->setLockData($localRepo->getPackages(), $aliases);
$this->io->write('<info>Writing lock file</info>');
}
$localRepo->write();
$this->io->write('<info>Generating autoload files</info>');
$generator = new AutoloadGenerator();
$generator->dump($localRepo, $this->package, $this->installationManager, $this->installationManager->getVendorPath() . '/.composer');
// dispatch post event
$eventName = $update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
$this->eventDispatcher->dispatchCommandEvent($eventName);
}
}
示例5: dump
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
{
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($installationManager->getVendorPath());
$filesystem->ensureDirectoryExists($targetDir);
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
$namespacesFile = <<<EOF
<?php
// autoload_namespace.php generated by Composer
\$vendorDir = {$vendorDirCode};
\$baseDir = {$appBaseDir};
return array(
EOF;
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
$autoloads = $this->parseAutoloads($packageMap);
foreach ($autoloads['psr-0'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$path = strtr($path, '\\', '/');
$baseDir = '';
if (!$filesystem->isAbsolutePath($path)) {
if (strpos($path, $relVendorPath) === 0) {
// path starts with vendor dir
$path = substr($path, strlen($relVendorPath));
$baseDir = '$vendorDir . ';
} else {
$path = '/' . $path;
$baseDir = '$baseDir . ';
}
} elseif (strpos($path, $vendorPath) === 0) {
$path = substr($path, strlen($vendorPath));
$baseDir = '$vendorDir . ';
}
$exportedPaths[] = $baseDir . var_export($path, true);
}
$exportedPrefix = var_export($namespace, true);
$namespacesFile .= " {$exportedPrefix} => ";
if (count($exportedPaths) > 1) {
$namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
} else {
$namespacesFile .= $exportedPaths[0] . ",\n";
}
}
$namespacesFile .= ");\n";
$classmapFile = <<<EOF
<?php
// autoload_classmap.php generated by Composer
\$vendorDir = {$vendorDirCode};
\$baseDir = {$appBaseDir};
return array(
EOF;
// flatten array
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
foreach ($autoloads['classmap'] as $dir) {
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
$path = '/' . $filesystem->findShortestPath(getcwd(), $path, true);
$classmapFile .= ' ' . var_export($class, true) . ' => $baseDir . ' . var_export($path, true) . ",\n";
}
}
$classmapFile .= ");\n";
file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile);
if ($includePathFile = $this->getIncludePathsFile($packageMap)) {
file_put_contents($targetDir . '/include_paths.php', $includePathFile);
}
file_put_contents($targetDir . '/autoload.php', $this->getAutoloadFile(true, true, (bool) $includePathFile));
copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
}
示例6: dump
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
{
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($installationManager->getVendorPath());
$filesystem->ensureDirectoryExists($targetDir);
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
$namespacesFile = <<<EOF
<?php
// autoload_namespace.php generated by Composer
\$vendorDir = {$vendorPathCode};
\$baseDir = {$appBaseDirCode};
return array(
EOF;
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
$autoloads = $this->parseAutoloads($packageMap);
foreach ($autoloads['psr-0'] as $namespace => $paths) {
$exportedPaths = array();
foreach ($paths as $path) {
$exportedPaths[] = $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path);
}
$exportedPrefix = var_export($namespace, true);
$namespacesFile .= " {$exportedPrefix} => ";
if (count($exportedPaths) > 1) {
$namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
} else {
$namespacesFile .= $exportedPaths[0] . ",\n";
}
}
$namespacesFile .= ");\n";
$classmapFile = <<<EOF
<?php
// autoload_classmap.php generated by Composer
\$vendorDir = {$vendorPathCode};
\$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() && $mainAutoload['psr-0']) {
$levels = count(explode('/', trim(strtr($mainPackage->getTargetDir(), '\\', '/'), '/')));
$prefixes = implode(', ', array_map(function ($prefix) {
return var_export($prefix, true);
}, array_keys($mainAutoload['psr-0'])));
$baseDirFromVendorDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
$targetDirLoader = <<<EOF
spl_autoload_register(function(\$class) {
\$dir = {$baseDirFromVendorDirCode} . '/';
\$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
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
foreach ($autoloads['classmap'] as $dir) {
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
$path = '/' . $filesystem->findShortestPath(getcwd(), $path, true);
$classmapFile .= ' ' . var_export($class, true) . ' => $baseDir . ' . var_export($path, true) . ",\n";
}
}
$classmapFile .= ");\n";
$filesCode = "";
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
foreach ($autoloads['files'] as $functionFile) {
$filesCode .= ' require __DIR__ . ' . var_export('/' . $filesystem->findShortestPath($vendorPath, $functionFile), true) . ";\n";
}
file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile);
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)) {
file_put_contents($targetDir . '/include_paths.php', $includePathFile);
}
file_put_contents($vendorPath . '/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (bool) $includePathFile, $targetDirLoader, $filesCode));
copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
//.........这里部分代码省略.........
示例7: testGetVendorPathRelative
public function testGetVendorPathRelative()
{
$manager = new InstallationManager('vendor');
$this->assertEquals('vendor', $manager->getVendorPath());
}