Added support for installing packages conforming to PSR-4 standard

This commit is contained in:
Qiang Xue
2014-01-08 09:22:25 -05:00
parent e123428c94
commit c9c1041a61
3 changed files with 33 additions and 14 deletions

View File

@ -5,6 +5,7 @@ Yii Framework 2 composer extension Change Log
----------------------------
- Bug #1480: Fixed issue with creating extensions.php when php opcache is enabled (cebe)
- Enh: Added support for installing packages conforming to PSR-4 standard (qiangxue)
2.0.0 alpha, December 1, 2013

View File

@ -100,25 +100,42 @@ class Installer extends LibraryInstaller
protected function generateDefaultAlias(PackageInterface $package)
{
$autoload = $package->getAutoload();
if (empty($autoload['psr-0'])) {
return false;
}
$fs = new Filesystem;
$vendorDir = $fs->normalizePath($this->vendorDir);
$autoload = $package->getAutoload();
$aliases = [];
foreach ($autoload['psr-0'] as $name => $path) {
$name = str_replace('\\', '/', trim($name, '\\'));
if (!$fs->isAbsolutePath($path)) {
$path = $this->vendorDir . '/' . $package->getName() . '/' . $path;
}
$path = $fs->normalizePath($path);
if (strpos($path . '/', $vendorDir . '/') === 0) {
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir)) . '/' . $name;
} else {
$aliases["@$name"] = $path . '/' . $name;
if (!empty($autoload['psr-0'])) {
foreach ($autoload['psr-0'] as $name => $path) {
$name = str_replace('\\', '/', trim($name, '\\'));
if (!$fs->isAbsolutePath($path)) {
$path = $this->vendorDir . '/' . $package->getName() . '/' . $path;
}
$path = $fs->normalizePath($path);
if (strpos($path . '/', $vendorDir . '/') === 0) {
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir)) . '/' . $name;
} else {
$aliases["@$name"] = $path . '/' . $name;
}
}
}
if (!empty($autoload['psr-4'])) {
foreach ($autoload['psr-4'] as $name => $path) {
$name = str_replace('\\', '/', trim($name, '\\'));
if (!$fs->isAbsolutePath($path)) {
$path = $this->vendorDir . '/' . $package->getName() . '/' . $path;
}
$path = $fs->normalizePath($path);
if (strpos($path . '/', $vendorDir . '/') === 0) {
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir));
} else {
$aliases["@$name"] = $path;
}
}
}
return $aliases;
}