From 07e181c6ebde32ec49fd829e6aba4154f1a6f51d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 15 Sep 2011 11:50:50 +0200 Subject: [PATCH] Fix lowercase behavior --- bin/composer | 2 ++ src/Composer/Command/InstallCommand.php | 18 ++++--------- src/Composer/Package/BasePackage.php | 31 +++++++++++++---------- src/Composer/Package/PackageInterface.php | 7 +++++ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/bin/composer b/bin/composer index 304940f6d..597c7e4fd 100755 --- a/bin/composer +++ b/bin/composer @@ -10,6 +10,8 @@ use Composer\Downloader\ZipDownloader; use Composer\Command\InstallCommand; use Composer\Installer\LibraryInstaller; +setlocale(LC_ALL, 'C'); + $composer = new Composer(); $composer->addDownloader('git', new GitDownloader); $composer->addDownloader('pear', new PearDownloader); diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index e92994a46..368d03814 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -65,7 +65,7 @@ class InstallCommand // TODO there should be an update flag or dedicated update command // TODO check lock file to remove packages that disappeared from the requirements foreach ($config['require'] as $name => $version) { - $name = $this->lowercase($name); + $name = strtolower($name); if ('latest' === $version) { $request->install($name); } else { @@ -90,7 +90,7 @@ class InstallCommand switch ($task['job']) { case 'install': $package = $task['package']; - echo '> Installing '.$package->getName().PHP_EOL; + echo '> Installing '.$package->getPrettyName().PHP_EOL; if ($sourceInstall) { // TODO } else { @@ -98,16 +98,16 @@ class InstallCommand $downloaderType = $package->getDistType(); $type = 'dist'; } elseif ($package->getSourceType()) { - echo 'Package '.$package->getName().' has no dist url, installing from source instead.'; + echo 'Package '.$package->getPrettyName().' has no dist url, installing from source instead.'; $downloaderType = $package->getSourceType(); $type = 'source'; } else { - throw new \UnexpectedValueException('Package '.$package->getName().' has no source or dist URL.'); + throw new \UnexpectedValueException('Package '.$package->getPrettyName().' has no source or dist URL.'); } $downloader = $composer->getDownloader($downloaderType); $installer = $composer->getInstaller($package->getType()); if (!$installer->install($package, $downloader, $type)) { - throw new \LogicException($package->getName().' could not be installed.'); + throw new \LogicException($package->getPrettyName().' could not be installed.'); } } $lock[$package->getName()] = array('version' => $package->getVersion()); @@ -158,12 +158,4 @@ class InstallCommand file_put_contents('composer.lock', json_encode($content, JSON_FORCE_OBJECT)."\n"); echo '> composer.lock dumped'.PHP_EOL; } - - protected function lowercase($str) - { - if (function_exists('mb_strtolower')) { - return mb_strtolower($str, 'UTF-8'); - } - return strtolower($str, 'UTF-8'); - } } \ No newline at end of file diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 37479476d..73afc1a79 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -24,6 +24,7 @@ use Composer\Repository\RepositoryInterface; abstract class BasePackage implements PackageInterface { protected $name; + protected $prettyName; protected $repository; protected $id; @@ -34,14 +35,13 @@ abstract class BasePackage implements PackageInterface */ public function __construct($name) { + $this->prettyName = $name; $this->name = strtolower($name); $this->id = -1; } /** - * Returns the package's name without version info, thus not a unique identifier - * - * @return string package name + * {@inheritDoc} */ public function getName() { @@ -49,12 +49,15 @@ abstract class BasePackage implements PackageInterface } /** - * Returns a set of names that could refer to this package - * - * No version or release type information should be included in any of the - * names. Provided or replaced package names need to be returned as well. - * - * @return array An array of strings referring to this package + * {@inheritDoc} + */ + public function getPrettyName() + { + return $this->prettyName; + } + + /** + * {@inheritDoc} */ public function getNames() { @@ -74,16 +77,16 @@ abstract class BasePackage implements PackageInterface } /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ public function setId($id) { $this->id = $id; } /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ public function getId() { return $this->id; @@ -157,7 +160,7 @@ abstract class BasePackage implements PackageInterface 'version' => $matches[1] .(!empty($matches[2]) ? $matches[2] : '.0') .(!empty($matches[3]) ? $matches[3] : '.0'), - 'type' => strtolower(!empty($matches[4]) ? $matches[4] : 'stable'), + 'type' => !empty($matches[4]) ? strtolower($matches[4]) : 'stable', 'dev' => !empty($matches[5]), ); } diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index f67213a9c..3fdefc78d 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -27,6 +27,13 @@ interface PackageInterface */ function getName(); + /** + * Returns the package's pretty (i.e. with proper case) name + * + * @return string package name + */ + function getPrettyName(); + /** * Returns a set of names that could refer to this package *