├── composer.json ├── LICENSE └── Command ├── DumpAutoloadCommand.php ├── InstallCommand.php └── UpdateCommand.php /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dflydev/embedded-composer-console", 3 | "description": "Embed Composer into a Symfony Console application", 4 | "keywords": ["embedded", "composer", "extensibility", "console"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Dragonfly Development Inc.", 9 | "email": "info@dflydev.com", 10 | "homepage": "http://dflydev.com" 11 | }, 12 | { 13 | "name": "Beau Simensen", 14 | "email": "beau@dflydev.com", 15 | "homepage": "http://beausimensen.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.3.2", 20 | "dflydev/embedded-composer-core": "1.*@dev", 21 | "symfony/console": "~2.3@dev", 22 | 23 | "composer/composer": "@dev" 24 | }, 25 | "autoload": { 26 | "psr-0": { "Dflydev\\EmbeddedComposer\\Console": "" } 27 | }, 28 | "target-dir": "Dflydev/EmbeddedComposer/Console", 29 | "extra": { 30 | "branch-alias": { 31 | "dev-master": "1.0-dev" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2014 Dragonfly Development Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Command/DumpAutoloadCommand.php: -------------------------------------------------------------------------------- 1 | 27 | * @author Beau Simensen 28 | */ 29 | class DumpAutoloadCommand extends Command 30 | { 31 | public function __construct($commandPrefix = 'composer:') 32 | { 33 | $this->commandPrefix = $commandPrefix; 34 | parent::__construct(); 35 | } 36 | 37 | protected function configure() 38 | { 39 | $fullCommand = $this->commandPrefix.'dump-autoload'; 40 | $this 41 | ->setName($fullCommand) 42 | ->setAliases(array($this->commandPrefix.'dumpautoload')) 43 | ->setDescription('Dumps the autoloader') 44 | ->setDefinition(array( 45 | new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 packages to be loaded with classmaps too, good for production.'), 46 | )) 47 | ->setHelp(<<${fullCommand} -o command dumps an optimized autoloader. 49 | 50 | EOT 51 | ) 52 | ; 53 | } 54 | 55 | protected function execute(InputInterface $input, OutputInterface $output) 56 | { 57 | if (!($this->getApplication() instanceof EmbeddedComposerAwareInterface)) { 58 | throw new \RuntimeException('Application must be instance of EmbeddedComposerAwareInterface'); 59 | } 60 | 61 | $embeddedComposer = $this->getApplication()->getEmbeddedComposer(); 62 | 63 | $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()); 64 | $composer = $embeddedComposer->createComposer($io); 65 | 66 | $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output); 67 | $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); 68 | 69 | $installationManager = $composer->getInstallationManager(); 70 | $localRepo = $composer->getRepositoryManager()->getLocalRepository(); 71 | $package = $composer->getPackage(); 72 | $config = $composer->getConfig(); 73 | 74 | $composer->getAutoloadGenerator()->dump($config, $localRepo, $package, $installationManager, 'composer', $input->getOption('optimize')); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Command/InstallCommand.php: -------------------------------------------------------------------------------- 1 | 26 | * @author Ryan Weaver 27 | * @author Konstantin Kudryashov 28 | * @author Beau Simensen 29 | */ 30 | class InstallCommand extends Command 31 | { 32 | public function __construct($commandPrefix = 'composer:') 33 | { 34 | $this->commandPrefix = $commandPrefix; 35 | parent::__construct(); 36 | } 37 | 38 | protected function configure() 39 | { 40 | $fullCommand = $this->commandPrefix.'install'; 41 | $this 42 | ->setName($fullCommand) 43 | ->setDescription('Install dependencies') 44 | ->setDefinition(array( 45 | new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), 46 | new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), 47 | new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), 48 | new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), 49 | )) 50 | ->setHelp(<<{$fullCommand} command reads a composer.json formatted file. 52 | The file is read from the current directory. And installs its dependencies. 53 | 54 | EOT 55 | ) 56 | ; 57 | } 58 | 59 | protected function execute(InputInterface $input, OutputInterface $output) 60 | { 61 | if (!$this->getApplication() instanceof EmbeddedComposerAwareInterface) { 62 | throw new \RuntimeException('Application must be instance of EmbeddedComposerAwareInterface'); 63 | } 64 | 65 | $embeddedComposer = $this->getApplication()->getEmbeddedComposer(); 66 | 67 | $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()); 68 | $installer = $embeddedComposer->createInstaller($io); 69 | 70 | $installer 71 | ->setDryRun($input->getOption('dry-run')) 72 | ->setVerbose($input->getOption('verbose')) 73 | ->setPreferSource($input->getOption('prefer-source')) 74 | ->setDevMode($input->getOption('dev')) 75 | ->setRunScripts(!$input->getOption('no-scripts')) 76 | ; 77 | 78 | return $installer->run(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Command/UpdateCommand.php: -------------------------------------------------------------------------------- 1 | 27 | * @author Ryan Weaver 28 | * @author Konstantin Kudryashov 29 | * @author Beau Simensen 30 | */ 31 | class UpdateCommand extends Command 32 | { 33 | public function __construct($commandPrefix = 'composer:') 34 | { 35 | $this->commandPrefix = $commandPrefix; 36 | parent::__construct(); 37 | } 38 | 39 | protected function configure() 40 | { 41 | $fullCommand = $this->commandPrefix.'update'; 42 | $this 43 | ->setName($fullCommand) 44 | ->setDescription('Update dependencies') 45 | ->setDefinition(array( 46 | new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be updated, if not provided all packages are.'), 47 | new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), 48 | new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), 49 | new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), 50 | new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), 51 | )) 52 | ->setHelp(<<{$fullCommand} command reads a composer.json formatted file. 54 | The file is read from the current directory. 55 | 56 | To limit the update operation to a few packages, you can list the package(s) 57 | you want to update on the command line: 58 | 59 | {$fullCommand} vendor/package1 foo/mypackage [...] 60 | 61 | EOT 62 | ) 63 | ; 64 | } 65 | 66 | protected function execute(InputInterface $input, OutputInterface $output) 67 | { 68 | if (!($this->getApplication() instanceof EmbeddedComposerAwareInterface)) { 69 | throw new \RuntimeException('Application must be instance of EmbeddedComposerAwareInterface'); 70 | } 71 | 72 | $embeddedComposer = $this->getApplication()->getEmbeddedComposer(); 73 | 74 | $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()); 75 | $installer = $embeddedComposer->createInstaller($io); 76 | 77 | $installer 78 | ->setDryRun($input->getOption('dry-run')) 79 | ->setVerbose($input->getOption('verbose')) 80 | ->setPreferSource($input->getOption('prefer-source')) 81 | ->setDevMode($input->getOption('dev')) 82 | ->setRunScripts(!$input->getOption('no-scripts')) 83 | ->setUpdate(true) 84 | ->setUpdateWhitelist($input->getArgument('packages')) 85 | ; 86 | 87 | return $installer->run(); 88 | } 89 | } 90 | --------------------------------------------------------------------------------