Load the configuration from a yml file or the container, according to the given option.

@param InputInterface $input

@return array

@throws Exception
767815
protected function loadConfiguration(InputInterface $input)
    {
        $loader = new ConfigurationLoader();

        if ($input->hasOption('config') && $file = $input->getOption('config')) {
            $configuration = $loader->loadFromFile($file);
        } else {
            
            if (null === $this->container) {
                throw new Exception('Unable to find the assets configuration from the container');
            }
            $configuration = $loader->loadFromContainer($this->container);
        }

        return $configuration;
    }
1274435
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $errorIo = $io->getErrorStyle();

        if (null === $name = $input->getArgument('name')) {
            $this->listBundles($errorIo);
            $errorIo->comment([
                'Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. <comment>config:dump-reference FrameworkBundle</comment>)',
                'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
            ]);

            return;
        }

        $extension = $this->findExtension($name);

        $configuration = $extension->getConfiguration([], $this->getContainerBuilder());

        $this->validateConfiguration($extension, $configuration);

        $format = $input->getOption('format');
        $path = $input->getArgument('path');

        if (null !== $path && 'yaml' !== $format) {
            $errorIo->error('The "path" option is only available for the "yaml" format.');

            return 1;
        }

        if ($name === $extension->getAlias()) {
            $message = sprintf('Default configuration for extension with alias: "%s"', $name);
        } else {
            $message = sprintf('Default configuration for "%s"', $name);
        }

        if (null !== $path) {
            $message .= sprintf(' at path "%s"', $path);
        }

        switch ($format) {
            case 'yaml':
                $io->writeln(sprintf('# %s', $message));
                $dumper = new YamlReferenceDumper();
                break;
            case 'xml':
                $io->writeln(sprintf('<!-- %s -->', $message));
                $dumper = new XmlReferenceDumper();
                break;
            default:
                $io->writeln($message);
                throw new InvalidArgumentException('Only the yaml and xml formats are supported.');
        }

        $io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));
    }
739175
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->validateCommand($input);

        $output->writeln('> Loading configuration file');
        $config = $input->getOption('config');
        $files = (new ConfigResolver())->getFileList($config);
        $output->writeLn('- Found '.count($files).' files');

        $preloader = (new Factory())->create($this->getOptions($input));

        $outputFile = $input->getOption('output');
        $handle = $preloader->prepareOutput($outputFile, $input->getOption('strict_types'));

        $output->writeln('> Compiling classes');

        $count = 0;
        $countSkipped = 0;
        $comments = !$input->getOption('strip_comments');

        foreach ($files as $file) {
            $count++;

            try {
                $code = $preloader->getCode($file, $comments);
                $output->writeln('- Writing '.$file);
                fwrite($handle, $code."\n");
            } catch (VisitorExceptionInterface $e) {
                $countSkipped++;
                $output->writeln('- Skipping '.$file);
            }
        }

        fclose($handle);

        $output->writeln("> Compiled loader written to $outputFile");
        $output->writeln('- Files: '.($count - $countSkipped).'/'.$count.' (skipped: '.$countSkipped.')');
        $output->writeln('- Filesize: '.(round(filesize($outputFile) / 1024)).' kb');
    }
236040
protected function execute(InputInterface $input, OutputInterface $output)
    {
        // retrieve the current settings
        $options = $this->getCurrentOptions($input, $output);

        // check if docker is installed
        if (false === $this->commandExists('docker')) {
            $output->writeln('Docker is required to run DUnit.');
            return self::ERROR_CODE;
        }
        // loop over each of the docker images specified
        foreach ($options[self::OPTIONS_KEY_IMAGES] as $image) {
            if ($options[self::OPTIONS_KEY_PULL]) {
                passthru(sprintf(
                    self::DOCKER_COMMAND_PULL,
                    escapeshellarg($image)
                ));
                continue;
            }

            $output->writeln('Running against image '.$image);
            if ($options[self::OPTIONS_KEY_SYNTAX]) {
                $output->writeln('Checking syntax');
                // run the syntax checks
                $this->executeCommandForImage(
                    $image,
                    $options[self::OPTIONS_KEY_SYNTAXCOMMAND]
                );
            }
            if ($options[self::OPTIONS_KEY_UNITTESTS]) {
                $output->writeln('Running unit test suite');
                // run the unit tests
                $this->executeCommandForImage(
                    $image,
                    $options[self::OPTIONS_KEY_UNITTESTSCOMMAND]
                );
            }
        }
        return self::NO_ERROR;
    }
324683
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($root = $input->getArgument('root-dir')) {
            chdir(realpath($root));
        }

        $rootDir = realpath(getcwd());
        $logger  = new ConsoleLogger($output);

        $composerJson = $rootDir . '/composer.json';
        if (!file_exists($composerJson)) {
            $logger->error(
                '<error>File not found, can not analyze: {file}</error> ',
                array('file' => $composerJson)
            );

            return 1;
        }

        $destinations   = array();
        $destinations[] = new PsrLogDestination($logger);

        $report   = $this->prepareReport($input, $logger);
        $composer = json_decode(file_get_contents($composerJson), true);
        $ignore   = $this->getIgnoredFiles($composer, $input->getOption('ignore-files'));
        $factory  = new AutoloadValidatorFactory($rootDir, new ClassMapGenerator($ignore), $report);
        $test     = new AutoloadValidator($factory->createFromComposerJson($composer), $report);
        $test->validate();
        if ($report->hasError()) {
            $logger->error('<error>Testing loaders found errors</error> ');
        }

        $enumLoader = new EnumeratingClassLoader();
        $this->prepareLoader($enumLoader, $test);

        $hacker = new HackPreparator($enumLoader, $logger);
        if ($custom = $input->getOption('add-autoloader')) {
            $hacker->prepareHacks(
                $custom,
                array(
                    $rootDir,
                    dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'hacks'
                )
            );
        }
        $this->prepareComposerFallbackLoader($enumLoader, $rootDir, $composer);
        if (!($input->getOption('disable-legacy-hacks') || $input->getOption('add-autoloader'))) {
            $hacker->prepareLegacyHack();
        }

        $loadCycle = new AllLoadingAutoLoader($enumLoader, $test->getClassMap(), $logger);

        return static::$exitCodes[$loadCycle->run() && !$report->hasError()];
    }
243088
protected function getEndpoints(InputInterface $input): array
    {
        $endpointsName = $input->getOption('endpoint');
        $endpoints = Endpoints::filter($endpointsName);

        if (count($endpointsName) > count($endpoints)) {
            throw new Exception(sprintf(
                'Endpoint not found. Endpoints available: %s',
                implode(', ', array_keys(Endpoints::all()))
            ));
        }

        return $endpoints;
    }
1045532
public function createProjectByInput(InputInterface $input) : Project
    {
        $configFinder = new ConfigFinder();
        $configLoader = new ConfigLoader();

        /**
         * This section is just for finding the right values to work with in
         * this execution.
         *
         * $options array will have, after this block, all these values
         */
        $configPath = rtrim($input->getOption('config'), DIRECTORY_SEPARATOR);
        $configValues = $configLoader->loadConfigValues(
            $configFinder->findConfigFile($configPath)
        );

        $masterLanguage = $configValues['master_language'];
        $languages = $configValues['languages'];
        $filePaths = $configValues['paths'];

        return Project::create(
            $masterLanguage,
            $languages,
            $filePaths
        );
    }
376742
public function input($filename, $input)
    {
        if (substr($filename, strlen($this->_settings['ext']) * -1) !== $this->_settings['ext']) {
            return $input;
        }
        if (!class_exists('lessc')) {
            throw new \Exception('Cannot not load "lessc" class. Make sure it is installed.');
        }
        $lc = new lessc($filename);
        return $lc->parse();
    }
87012
protected function loadConfig(InputInterface $input, OutputInterface $output)
    {
        $configFilePath = $this->locateConfigFile($input);
        $output->writeln('<info>using config file</info> .' . str_replace(getcwd(), '', realpath($configFilePath)));

        $parser = $input->getOption('parser');

        // If no parser is specified try to determine the correct one from the file extension.  Defaults to YAML
        if ($parser === null) {
            $extension = pathinfo($configFilePath, PATHINFO_EXTENSION);

            switch (strtolower($extension)) {
                case 'json':
                    $parser = 'json';
                    break;
                case 'php':
                    $parser = 'php';
                    break;
                case 'yml':
                default:
                    $parser = 'yaml';
            }
        }

        switch (strtolower($parser)) {
            case 'json':
                $config = Config::fromJson($configFilePath);
                break;
            case 'php':
                $config = Config::fromPhp($configFilePath);
                break;
            case 'yaml':
                $config = Config::fromYaml($configFilePath);
                break;
            default:
                throw new \InvalidArgumentException(sprintf('\'%s\' is not a valid parser.', $parser));
        }

        $output->writeln('<info>using config parser</info> ' . $parser);

        $this->setConfig($config);
    }
307060
protected function createUser(InputInterface $input)
    {
        return $this->userFactory->createUser()
            ->setEmail($input->getArgument('email'))
            ->setPlainPassword($input->getArgument('password'));
    }
346397
protected function getOptions(InputInterface $input)
    {
        return [
            'dir'    => (bool) $input->getOption('fix_dir'),
            'file'   => (bool) $input->getOption('fix_file'),
            'skip'   => (bool) $input->getOption('skip_dir_file'),
            'strict' => (bool) $input->getOption('strict_types'),
        ];
    }
1045383
public function execute(InputInterface $input, OutputInterface $output)
    {
        $container = null;
        try {
            // There is a tiny hack here. We need editable container and we know that at this point
            // container still can be edited so we cast it to `LimoncelloContainerInterface`.
            $container = $this->createContainer($this->getComposer());
            assert($container instanceof LimoncelloContainerInterface);

            $this->executeCommand($this->getName(), $this->callable, $this->wrapIo($input, $output), $container);
        } catch (Exception $exception) {
            if ($container !== null && $container->has(ThrowableHandlerInterface::class) === true) {
                /** @var ThrowableHandlerInterface $handler */
                $handler  = $container->get(ThrowableHandlerInterface::class);
                $response = $handler->createResponse($exception, $container);

                $output->writeln((string)$response->getBody());
            } else {
                $message = $exception->getMessage();
                $file    = $exception->getFile();
                $line    = $exception->getLine();
                $trace   = $exception->getTraceAsString();

                $output->writeln("$message at $file#$line" . PHP_EOL . $trace);
            }

            throw $exception;
        }
    }
1041447
private function getReadyAdapter(InputInterface $input, OutputInterface $output)
    {
        $adapterClass = $this->getAdapterClassFromArgument($input->getArgument('adapter'));

        try {
            $adapter = new $adapterClass();
        } catch (\Exception $e) {
            $adapterData = [];
            preg_match_all('/"(.*)"/i', $e->getMessage(), $matches);

            foreach ($matches[1] as $match) {
                $optionKey = str_replace('_', '-', Inflector::tableize($match));
                $option    = $input->getOption($optionKey);

                if (!$option) {
                    throw new AdapterException(
                        sprintf(
                            'The option "%s" is needed by %s adapter',
                            $optionKey,
                            $adapterClass
                        )
                    );
                }

                $adapterData[$match] = $option;
            }

            $adapter = new $adapterClass($adapterData);
        }

        return $adapter;
    }
13054
protected function getProgramOptions(
        InputInterface $input,
        OutputInterface $output
    ) {
        $opts = array();

        foreach ($this->getDefinition()->getOptions() as $o) {
            $name = $o->getName();
            if (! array_key_exists($name, $this->programOptions )) {
                continue;
            }
            $value = $input->getOption($name);
            if ($o->acceptValue() && $value !== null) {
                $opts[$this->programOptions[$name]] = $value;
            } else if (! $o->acceptValue() && $value === true) {
                $opts[] = $this->programOptions[$name];
            }
        }

        return array_merge(
            $opts,
            $this->getVerbosityOptions($output->getVerbosity())
        );
    }
418790
public function parse(Input $input)
    {
        // fill config
        $this->config = $this->default;

        if ($input instanceof RequestInput) {
            $this->config['optional_item_id'] = true;
        }

        $object = $input->getAsObject();

        $document = $this->getFactory()->make(
            'Document',
            [$object, $this, new RootAccessable]
        );

        // Clear config
        $this->config = [];

        return $document;
    }
1188387
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;
        $io = new SymfonyStyle($input, $output);

        $config = $this->getConfigHelper()->load($input);
        $typeMap = TypeMap::fromMetadata(
            $config->getTypeNamespace(),
            $config->getEngine()->getMetadata()->getTypes()
        );

        $generator = new ClassMapGenerator(
            $config->getRuleSet(),
            $config->getClassMapName(),
            $config->getClassMapNamespace()
        );
        $path = $config->getClassMapDestination().DIRECTORY_SEPARATOR.$config->getClassMapName().'.php';
        $this->handleClassmap($generator, $typeMap, $path);

        $io->success('Generated classmap at ' . $path);
    }
1243508
private function validateInput(InputInterface $input)
    {
        if (!$input->getOption('grep')) {
            foreach (['invert', 'insensitive'] as $option) {
                if ($input->getOption($option)) {
                    throw new RuntimeException('--' . $option . ' does not make sense without --grep');
                }
            }
        }
    }