2012-06-25 12:20:50 +00:00
< ? php
/*
* This file is part of Composer .
*
* ( c ) Nils Adermann < naderman @ naderman . de >
* Jordi Boggiano < j . boggiano @ seld . be >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Composer\Command ;
2013-09-05 12:30:03 +00:00
use Composer\Plugin\CommandEvent ;
use Composer\Plugin\PluginEvents ;
2012-06-25 12:20:50 +00:00
use Symfony\Component\Console\Input\InputInterface ;
2012-08-14 18:29:29 +00:00
use Symfony\Component\Console\Input\InputOption ;
2012-06-25 12:20:50 +00:00
use Symfony\Component\Console\Output\OutputInterface ;
/**
* @ author Jordi Boggiano < j . boggiano @ seld . be >
*/
2016-02-19 22:56:46 +00:00
class DumpAutoloadCommand extends BaseCommand
2012-06-25 12:20:50 +00:00
{
protected function configure ()
{
$this
-> setName ( 'dump-autoload' )
2012-08-18 12:33:34 +00:00
-> setAliases ( array ( 'dumpautoload' ))
2017-01-11 22:08:12 +00:00
-> setDescription ( 'Dumps the autoloader.' )
2012-08-14 18:29:29 +00:00
-> setDefinition ( array (
2014-08-08 07:27:19 +00:00
new InputOption ( 'no-scripts' , null , InputOption :: VALUE_NONE , 'Skips the execution of all scripts defined in composer.json file.' ),
2014-05-07 08:55:42 +00:00
new InputOption ( 'optimize' , 'o' , InputOption :: VALUE_NONE , 'Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.' ),
2015-08-16 19:56:52 +00:00
new InputOption ( 'classmap-authoritative' , 'a' , InputOption :: VALUE_NONE , 'Autoload classes from the classmap only. Implicitly enables `--optimize`.' ),
2016-07-28 08:23:39 +00:00
new InputOption ( 'apcu' , null , InputOption :: VALUE_NONE , 'Use APCu to cache found/not-found classes.' ),
2014-03-01 19:39:06 +00:00
new InputOption ( 'no-dev' , null , InputOption :: VALUE_NONE , 'Disables autoload-dev rules.' ),
2020-06-01 13:43:24 +00:00
new InputOption ( 'ignore-platform-reqs' , null , InputOption :: VALUE_OPTIONAL | InputOption :: VALUE_IS_ARRAY , 'Ignore platform requirements (php & ext- packages), optionally can take a package name to ignore specific package(s) from the platform check.' ),
2012-08-14 18:29:29 +00:00
))
2018-07-24 12:32:52 +00:00
-> setHelp (
<<< EOT
2012-06-25 12:20:50 +00:00
< info > php composer . phar dump - autoload </ info >
2019-03-04 11:55:38 +00:00
Read more at https :// getcomposer . org / doc / 03 - cli . md #dump-autoload-dumpautoload-
2012-06-25 12:20:50 +00:00
EOT
)
;
}
protected function execute ( InputInterface $input , OutputInterface $output )
{
$composer = $this -> getComposer ();
2013-09-05 12:30:03 +00:00
$commandEvent = new CommandEvent ( PluginEvents :: COMMAND , 'dump-autoload' , $input , $output );
$composer -> getEventDispatcher () -> dispatch ( $commandEvent -> getName (), $commandEvent );
2012-06-25 12:20:50 +00:00
$installationManager = $composer -> getInstallationManager ();
2013-03-03 00:54:14 +00:00
$localRepo = $composer -> getRepositoryManager () -> getLocalRepository ();
2012-06-25 12:20:50 +00:00
$package = $composer -> getPackage ();
2012-07-02 07:52:09 +00:00
$config = $composer -> getConfig ();
2012-06-25 12:20:50 +00:00
2015-08-16 19:56:52 +00:00
$optimize = $input -> getOption ( 'optimize' ) || $config -> get ( 'optimize-autoloader' );
$authoritative = $input -> getOption ( 'classmap-authoritative' ) || $config -> get ( 'classmap-authoritative' );
2017-03-09 08:41:22 +00:00
$apcu = $input -> getOption ( 'apcu' ) || $config -> get ( 'apcu-autoloader' );
2014-01-16 19:44:16 +00:00
2017-12-06 10:58:04 +00:00
if ( $authoritative ) {
2019-10-30 15:35:13 +00:00
$this -> getIO () -> write ( '<info>Generating optimized autoload files (authoritative)</info>' );
2017-12-06 10:58:04 +00:00
} elseif ( $optimize ) {
2019-10-30 15:35:13 +00:00
$this -> getIO () -> write ( '<info>Generating optimized autoload files</info>' );
2014-01-16 19:44:16 +00:00
} else {
2019-10-30 15:35:13 +00:00
$this -> getIO () -> write ( '<info>Generating autoload files</info>' );
2014-01-16 19:44:16 +00:00
}
2020-06-01 13:43:24 +00:00
$ignorePlatformReqs = $input -> getOption ( 'ignore-platform-reqs' )
? ( array_filter ( $input -> getOption ( 'ignore-platform-reqs' )) ? $input -> getOption ( 'ignore-platform-reqs' ) : true )
: false ;
2014-02-27 09:39:33 +00:00
$generator = $composer -> getAutoloadGenerator ();
2014-03-01 19:39:06 +00:00
$generator -> setDevMode ( ! $input -> getOption ( 'no-dev' ));
2015-08-16 19:56:52 +00:00
$generator -> setClassMapAuthoritative ( $authoritative );
2016-07-28 08:23:39 +00:00
$generator -> setApcu ( $apcu );
2014-08-08 07:27:19 +00:00
$generator -> setRunScripts ( ! $input -> getOption ( 'no-scripts' ));
2020-06-01 13:43:24 +00:00
$generator -> setIgnorePlatformRequirements ( $ignorePlatformReqs );
2018-08-27 12:46:05 +00:00
$numberOfClasses = $generator -> dump ( $config , $localRepo , $package , $installationManager , 'composer' , $optimize );
if ( $authoritative ) {
2019-10-30 15:35:13 +00:00
$this -> getIO () -> write ( '<info>Generated optimized autoload files (authoritative) containing ' . $numberOfClasses . ' classes</info>' );
2018-08-27 12:46:05 +00:00
} elseif ( $optimize ) {
2019-10-30 15:35:13 +00:00
$this -> getIO () -> write ( '<info>Generated optimized autoload files containing ' . $numberOfClasses . ' classes</info>' );
2018-08-27 12:46:05 +00:00
} else {
2020-03-13 17:28:27 +00:00
$this -> getIO () -> write ( '<info>Generated autoload files</info>' );
2018-08-27 12:46:05 +00:00
}
2019-10-07 16:50:18 +00:00
return 0 ;
2012-06-25 12:20:50 +00:00
}
}