Browse Source

Allow autoloader optimization right from 'install'

Sebastian Krebs 12 years ago
parent
commit
d3aaeb21da
2 changed files with 17 additions and 1 deletions
  1. 2 0
      src/Composer/Command/InstallCommand.php
  2. 15 1
      src/Composer/Installer.php

+ 2 - 0
src/Composer/Command/InstallCommand.php

@@ -37,6 +37,7 @@ class InstallCommand extends Command
                 new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'),
                 new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
                 new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
+                new InputOption('optimize-autoloaders', null, InputOption::VALUE_NONE, 'Optimize autoloaders during autoloader dump')
             ))
             ->setHelp(<<<EOT
 The <info>install</info> command reads the composer.lock file from
@@ -64,6 +65,7 @@ EOT
             ->setPreferDist($input->getOption('prefer-dist'))
             ->setDevMode($input->getOption('dev'))
             ->setRunScripts(!$input->getOption('no-scripts'))
+            ->setOptimizeAutoloaders($input->getOption('optimize-autoloaders'))
         ;
 
         if ($input->getOption('no-custom-installers')) {

+ 15 - 1
src/Composer/Installer.php

@@ -92,6 +92,7 @@ class Installer
 
     protected $preferSource = false;
     protected $preferDist = false;
+    protected $optimizeAutoloaders = false;
     protected $devMode = false;
     protected $dryRun = false;
     protected $verbose = false;
@@ -221,7 +222,7 @@ class Installer
             // write autoloader
             $this->io->write('<info>Generating autoload files</info>');
             $localRepos = new CompositeRepository($this->repositoryManager->getLocalRepositories());
-            $this->autoloadGenerator->dump($this->config, $localRepos, $this->package, $this->installationManager, 'composer');
+            $this->autoloadGenerator->dump($this->config, $localRepos, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloaders);
 
             if ($this->runScripts) {
                 // dispatch post event
@@ -739,6 +740,19 @@ class Installer
         return $this;
     }
 
+    /**
+     * Wether or not generated autoloaders are optimized
+     *
+     * @param bool $optimizeAutoloaders
+     * @return Installer
+     */
+    public function setOptimizeAutoloaders($optimizeAutoloaders = false)
+    {
+        $this->optimizeAutoloaders = (boolean) $optimizeAutoloaders;
+
+        return $this;
+    }
+
     /**
      * update packages
      *