FZE
FZE

Reputation: 1627

composer install pass command line argument or parameter to bin/console

I'm trying to make my symfony 3.0 app capable to work with multiple kernel. real aim : Multiple applications in one project

Generally everything is OK. I edited bin/console it's content exactly as the following. It works exactly and results what I need via php bin/console --app=api But when I execute composer install bin/console throws the Exception naturally it doesn't knows about --app parameter. I want to make something like composer install --app=api and desired behaviour it would pass the parameter to bin/console I checked documentation and almost every pixel of the internet couldn't find a solution.

#!/usr/bin/env php
<?php

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Debug\Debug;

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

set_time_limit(0);

/**
 * @var Composer\Autoload\ClassLoader $loader
 */
$loader = require __DIR__.'/../apps/autoload.php';

$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$app = $input->getParameterOption(array('--app', '-a'));
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';

if ($debug) {
    Debug::enable();
}

switch ($app) {
    case 'api':
        $kernel = new ApiKernel($env, $debug);
        break;
    case 'frontend':
        $kernel = new FrontendKernel($env, $debug);
        break;
    default:
        throw new \InvalidArgumentException("[--app|-a=<app>]  app: api|frontend");
        break;
}

$application = new Application($kernel);
$application->getDefinition()->addOptions([
    new InputOption('--app', '-a', InputOption::VALUE_REQUIRED, 'The application to operate in.'),
]);
$application->run($input);

Upvotes: 3

Views: 2833

Answers (1)

Ryan
Ryan

Reputation: 5056

You can use composer install --no-scripts to prevent automatically running app/console after installation.

Or you can remove the the bin/console commands from the scripts section in your composer.json altogether, which probably makes more sense. See https://github.com/symfony/symfony-standard/blob/master/composer.json#L33-L34

Or you can use environment variables instead of arguments.

Upvotes: 1

Related Questions