1
0
Fork 0

Move .composer files out into the vendor dir, fixes #497

pull/603/head
Jordi Boggiano 2012-04-19 21:55:35 +02:00
parent 108134451d
commit 22fe296ad0
8 changed files with 35 additions and 16 deletions

View File

@ -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

View File

@ -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.

View File

@ -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) →

View File

@ -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', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload_namespaces.php';\n");
file_put_contents($targetDir.'/.composer/autoload_classmap.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload_classmap.php';\n");
file_put_contents($targetDir.'/.composer/autoload.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload.php';\n");
file_put_contents($targetDir.'/.composer/ClassLoader.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/ClassLoader.php';\n");
if ($includePathFile) {
file_put_contents($targetDir.'/.composer/include_paths.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/include_paths.php';\n");
}
}
}
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages)

View File

@ -81,10 +81,10 @@ class Compiler
$this->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

View File

@ -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)

View File

@ -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('<info>Generating autoload files</info>');
$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;

View File

@ -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);