|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @see https://github.com/open-code-modeling/php-code-generator for the canonical source repository |
| 5 | + * @copyright https://github.com/open-code-modeling/php-code-generator/blob/master/COPYRIGHT.md |
| 6 | + * @license https://github.com/open-code-modeling/php-code-generator/blob/master/LICENSE.md MIT License |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace OpenCodeModeling\CodeGenerator; |
| 12 | + |
| 13 | +if (version_compare('7.3', PHP_VERSION, '>')) { |
| 14 | + fwrite( |
| 15 | + STDERR, |
| 16 | + 'This version of open-code-modeling requires PHP >= 7.3; using the latest version of PHP is highly recommended.' . PHP_EOL |
| 17 | + ); |
| 18 | + |
| 19 | + die(1); |
| 20 | +} |
| 21 | + |
| 22 | +if (! ini_get('date.timezone')) { |
| 23 | + ini_set('date.timezone', 'UTC'); |
| 24 | +} |
| 25 | + |
| 26 | +foreach ( |
| 27 | + [ |
| 28 | + __DIR__ . '/../../../autoload.php', |
| 29 | + __DIR__ . '/../../autoload.php', |
| 30 | + __DIR__ . '/../vendor/autoload.php', |
| 31 | + __DIR__ . '/vendor/autoload.php', |
| 32 | + ] as $file |
| 33 | +) { |
| 34 | + if (file_exists($file)) { |
| 35 | + define('OCMCG_COMPOSER_INSTALL', $file); |
| 36 | + break; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +unset($file); |
| 41 | + |
| 42 | +if (! defined('OCMCG_COMPOSER_INSTALL')) { |
| 43 | + fwrite(STDERR, |
| 44 | + 'You need to set up the project dependencies using the following commands:' . PHP_EOL . |
| 45 | + 'wget http://getcomposer.org/composer.phar' . PHP_EOL . |
| 46 | + 'php composer.phar install' . PHP_EOL |
| 47 | + ); |
| 48 | + |
| 49 | + die(1); |
| 50 | +} |
| 51 | + |
| 52 | +require OCMCG_COMPOSER_INSTALL; |
| 53 | + |
| 54 | +use OpenCodeModeling\CodeGenerator\Config\EmptyResolver; |
| 55 | +use OpenCodeModeling\CodeGenerator\Config\FilePhpResolver; |
| 56 | +use OpenCodeModeling\CodeGenerator\Config\Config; |
| 57 | +use Symfony\Component\Console\Application; |
| 58 | +use Symfony\Component\Console\Input\ArgvInput; |
| 59 | +use Symfony\Component\Console\Input\InputOption; |
| 60 | + |
| 61 | +$description = <<<DESC |
| 62 | +=========================================== |
| 63 | +Open Code Modeling - PHP Code Generator CLI |
| 64 | +=========================================== |
| 65 | +
|
| 66 | +DESC; |
| 67 | + |
| 68 | +$config = null; |
| 69 | +$argvInput = new ArgvInput; |
| 70 | + |
| 71 | +if ($argvInput->hasParameterOption(['--config', '-c'])) { |
| 72 | + $config = $argvInput->getParameterOption(['--config', '-c']); |
| 73 | +} |
| 74 | + |
| 75 | +$application = new Application($description); |
| 76 | +$application->getDefinition()->addOption(new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')); |
| 77 | +$helperSet = $application->getHelperSet(); |
| 78 | + |
| 79 | +$helperSet->set(new Console\WorkflowContext(), Console\WorkflowContext::class); |
| 80 | + |
| 81 | +if ($config) { |
| 82 | + $resolver = new FilePhpResolver($config); |
| 83 | +} else { |
| 84 | + $resolver = new EmptyResolver(); |
| 85 | + |
| 86 | + if (file_exists('open-code-modeling.php.dist')) { |
| 87 | + $resolver = new FilePhpResolver('open-code-modeling.php.dist'); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +$helperSet->set(new Console\Config($resolver), Config::class); |
| 92 | + |
| 93 | +$application->addCommands( |
| 94 | + [ |
| 95 | + new Console\WorkflowCommand(), |
| 96 | + ] |
| 97 | +); |
| 98 | + |
| 99 | +unset($workflowContext, $config, $argvInput); |
| 100 | + |
| 101 | +$application->run(); |
0 commit comments