From 22fe296ad0ff789adf0cec163281836b8a69f221 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 19 Apr 2012 21:55:35 +0200 Subject: [PATCH] Move .composer files out into the vendor dir, fixes #497 --- CHANGELOG.md | 1 + doc/00-intro.md | 2 +- doc/01-basic-usage.md | 10 +++++----- src/Composer/Autoload/AutoloadGenerator.php | 13 ++++++++++++- src/Composer/Compiler.php | 8 ++++---- src/Composer/Factory.php | 11 +++++++++-- src/Composer/Installer.php | 4 ++-- src/bootstrap.php | 2 +- 8 files changed, 35 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09f21b61b..6b32d8fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Schema: Added 'require-dev' for development-time requirements (tests, etc), install with --dev * Schema: Removed 'recommend' * Schema: 'suggest' is now informational and can use any description for a package, not only a constraint + * Break: .composer/autoload.php and other files in vendor/.composer have been moved to vendor/ * Added caching of repository metadata (faster startup times & failover if packagist is down) * Added include_path support for legacy projects that are full of require_once statements * Added installation notifications API to allow better statistics on Composer repositories diff --git a/doc/00-intro.md b/doc/00-intro.md index 2437b7437..91ee3e66b 100644 --- a/doc/00-intro.md +++ b/doc/00-intro.md @@ -80,7 +80,7 @@ capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process: - require 'vendor/.composer/autoload.php'; + require 'vendor/autoload.php'; Woh! Now start using monolog! To keep learning more about Composer, keep reading the "Basic Usage" chapter. diff --git a/doc/01-basic-usage.md b/doc/01-basic-usage.md index 27f4d2972..b920eb455 100644 --- a/doc/01-basic-usage.md +++ b/doc/01-basic-usage.md @@ -136,10 +136,10 @@ but it makes life quite a bit simpler. ## Autoloading For libraries that specify autoload information, Composer generates a -`vendor/.composer/autoload.php` file. You can simply include this file and you +`vendor/autoload.php` file. You can simply include this file and you will get autoloading for free. - require 'vendor/.composer/autoload.php'; + require 'vendor/autoload.php'; This makes it really easy to use third party code. For example: If your project depends on monolog, you can just start using classes from it, and they @@ -168,13 +168,13 @@ be in your project root. An example filename would be `src/Acme/Foo.php` containing an `Acme\Foo` class. After adding the `autoload` field, you have to re-run `install` to re-generate -the `vendor/.composer/autoload.php` file. +the `vendor/autoload.php` file. Including that file will also return the autoloader instance, so you can store the return value of the include call in a variable and add more namespaces. This can be useful for autoloading classes in a test suite, for example. - $loader = require 'vendor/.composer/autoload.php'; + $loader = require 'vendor/autoload.php'; $loader->add('Acme\Test', __DIR__); In addition to PSR-0 autoloading, classmap is also supported. This allows @@ -182,7 +182,7 @@ classes to be autoloaded even if they do not conform to PSR-0. See the [autoload reference](04-schema.md#autoload) for more details. > **Note:** Composer provides its own autoloader. If you don't want to use -that one, you can just include `vendor/.composer/autoload_namespaces.php`, +that one, you can just include `vendor/autoload_namespaces.php`, which returns an associative array mapping namespaces to directories. ← [Intro](00-intro.md) | [Libraries](02-libraries.md) → diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index b9806320c..2e8fc07eb 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -25,7 +25,7 @@ use Composer\Util\Filesystem; */ class AutoloadGenerator { - public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir) + public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $bcLinks = false) { $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($installationManager->getVendorPath()); @@ -96,6 +96,17 @@ EOF; } file_put_contents($targetDir.'/autoload.php', $this->getAutoloadFile(true, true, (Boolean) $includePathFile)); copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); + + // TODO BC feature, add E_DEPRECATED in autoload.php on April 30th, remove after May 30th + if ($bcLinks) { + file_put_contents($targetDir.'/.composer/autoload_namespaces.php', "addFile($phar, $file); } - $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/.composer/ClassLoader.php')); - $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/.composer/autoload.php')); - $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/.composer/autoload_namespaces.php')); - $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/.composer/autoload_classmap.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/ClassLoader.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload_namespaces.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload_classmap.php')); $this->addComposerBin($phar); // Stubs diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 9758fc946..e166754c5 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -151,8 +151,15 @@ class Factory protected function addLocalRepository(RepositoryManager $rm, $vendorDir) { - $rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json'))); - $rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/.composer/installed_dev.json'))); + // TODO BC feature, remove after May 30th + if (file_exists($vendorDir.'/.composer/installed.json')) { + rename($vendorDir.'/.composer/installed.json', $vendorDir.'/installed.json'); + } + if (file_exists($vendorDir.'/.composer/installed_dev.json')) { + rename($vendorDir.'/.composer/installed_dev.json', $vendorDir.'/installed_dev.json'); + } + $rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/installed.json'))); + $rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/installed_dev.json'))); } protected function addPackagistRepository(array $localConfig) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 1816e7ee2..1b0b78835 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -152,7 +152,7 @@ class Installer } } - // dump suggestions + // output suggestions foreach ($this->suggestedPackages as $suggestion) { $this->io->write($suggestion['source'].' suggests installing '.$suggestion['target'].' ('.$suggestion['reason'].')'); } @@ -174,7 +174,7 @@ class Installer $this->io->write('Generating autoload files'); $generator = new AutoloadGenerator; $localRepos = new CompositeRepository($this->repositoryManager->getLocalRepositories()); - $generator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath().'/.composer'); + $generator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath(), true); // dispatch post event $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD; diff --git a/src/bootstrap.php b/src/bootstrap.php index c7f2fd0d6..0eab8a25e 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -16,7 +16,7 @@ function includeIfExists($file) { } } -if ((!$loader = includeIfExists(__DIR__.'/../vendor/.composer/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../.composer/autoload.php'))) { +if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) { die('You must set up the project dependencies, run the following commands:'.PHP_EOL. 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. 'php composer.phar install'.PHP_EOL);