/** * @param Nette\Configurator $configurator * @return bool has the debug mode been modified? */ public static function setupMode(Nette\Configurator $configurator) { if (PHP_SAPI !== 'cli') { return FALSE; } $input = new ArgvInput(); if (!$input->hasParameterOption('--debug-mode')) { return FALSE; } if ($input->hasParameterOption(['--debug-mode=no', '--debug-mode=off', '--debug-mode=false', '--debug-mode=0'])) { $configurator->setDebugMode(FALSE); return TRUE; } else { $configurator->setDebugMode(TRUE); return TRUE; } }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME, DiCompileMultiTenantCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $generationDir = $cmdName === DiCompileMultiTenantCommand::NAME ? $this->input->getParameterOption(DiCompileMultiTenantCommand::INPUT_KEY_GENERATION) : null; if (!$generationDir) { $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $generationDir = (new DirectoryList(BP, $mageDirs))->getPath(DirectoryList::GENERATION); } if ($this->filesystemDriver->isExists($generationDir)) { $this->filesystemDriver->deleteDirectory($generationDir); } }
/** * Determine whether a CLI command is for compilation, and if so, clear the directory * * @throws \Magento\Framework\Exception\FileSystemException * @return void */ public function handleCompilerEnvironment() { $compilationCommands = [DiCompileCommand::NAME]; $cmdName = $this->input->getFirstArgument(); $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); if (!in_array($cmdName, $compilationCommands) || $isHelpOption) { return; } $compileDirList = []; $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $directoryList = new DirectoryList(BP, $mageDirs); $compileDirList[] = $directoryList->getPath(DirectoryList::GENERATION); $compileDirList[] = $directoryList->getPath(DirectoryList::DI); foreach ($compileDirList as $compileDir) { if ($this->filesystemDriver->isExists($compileDir)) { $this->filesystemDriver->deleteDirectory($compileDir); } } }
public static function runCLI($environment = 'dev', $debug = true) { set_time_limit(0); $input = new ArgvInput(); $environment = $input->getParameterOption(array('--env', '-e'), $environment); $debug = !$input->hasParameterOption(array('--no-debug', '')) && $environment !== 'prod'; if ($debug) { Debug::enable(); } $kernel = new static($environment, $debug); $application = new Application($kernel); $application->run($input); }
/** * Runs Symfony2 in console mode. * * @param string $kernelClass Class name for the kernel to be ran. */ public static function console($kernelClass) { set_time_limit(0); $input = new ArgvInput(); // decide env and debug info based on cli params $env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { Debug::enable(); } $kernel = new $kernelClass($env, $debug); $application = new Application($kernel); $application->run($input); }
/** * @return string[] * @author Maximilian Ruta <*****@*****.**> */ public function getBundles() { require_once $this->console->getAppDir() . '/AppKernel.php'; $input = new ArgvInput(); $env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; $kernel = new \AppKernel($env, $debug); $bundles = $kernel->registerBundles(); $bundleMap = []; foreach ($bundles as $bundle) { $reflector = new \ReflectionClass($bundle); $bundlePath = dirname($reflector->getFileName()); $bundleMap[$bundle->getName()] = $bundlePath; } return $bundleMap; }
/** * Detect if a custom environment file matching the APP_ENV exists. * * @param \Illuminate\Contracts\Foundation\Application|\Notadd\Foundation\Application $app * * @return void */ protected function checkForSpecificEnvironmentFile($app) { if (php_sapi_name() == 'cli') { $input = new ArgvInput(); if ($input->hasParameterOption('--env')) { $file = $app->environmentFile() . '.' . $input->getParameterOption('--env'); $this->loadEnvironmentFile($app, $file); } } if (!env('APP_ENV')) { return; } if (empty($file)) { $file = $app->environmentFile() . '.' . env('APP_ENV'); $this->loadEnvironmentFile($app, $file); } }
public static function install() { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { return; } $input = new ArgvInput(); if ($input->hasParameterOption(array('--no-interaction', '-n'))) { return; } $cwd = getcwd(); $www = dirname($cwd); $site = basename($cwd); $arguments = array('site:install', 'site' => $site, '--www' => $www, '--interactive' => true, '--mysql_db_prefix' => ''); self::logo(); $output = new ConsoleOutput(); $output->writeln("<info>Welcome to the Joomla Platform installer!</info>"); $output->writeln("Fill in the following details to configure your new application."); $application = new Application(); $application->run(new ArrayInput($arguments)); }
public static function install() { $output = new ConsoleOutput(); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $output->writeln("<info>Sorry, automated installation is not yet supported on Windows!</info>"); $output->writeln("Please refer to the documentation for alternative installation methods: http://developer.joomlatools.com/platform/getting-started.html"); return; } $input = new ArgvInput(); if ($input->hasParameterOption(array('--no-interaction', '-n'))) { return; } $cwd = getcwd(); $www = dirname($cwd); $site = basename($cwd); $arguments = array('site:install', 'site' => $site, '--www' => $www, '--interactive' => true, '--mysql_db_prefix' => ''); $output->writeln("<info>Welcome to the Joomlatools Platform installer!</info>"); $output->writeln("Fill in the following details to configure your new application."); $application = new Application(); $application->run(new ArrayInput($arguments)); }
/** * Handles the brood default options/arguments. */ public static final function ArgvInput() { # get the raw commands $raws = ['--env', '--timeout']; # get the options from Brood $options = [Brood::environmentOption(), Brood::timeoutOption()]; $instances = []; $reflect = new ReflectionClass(InputOption::class); foreach ($options as $opt) { $instances[] = $reflect->newInstanceArgs($opt); } # still, listen to the php $_SERVER['argv'] $cmd_input = new ArgvInput(); # get the default brood options $brood_input = new ArgvInput($raws, new InputDefinition($instances)); foreach ($raws as $raw) { if ($cmd_input->hasParameterOption([$raw])) { $val = $cmd_input->getParameterOption($raw); $val = is_numeric($val) ? (int) $val : $val; $brood_input->setOption(str_replace('-', '', $raw), $val); } } return $brood_input; }
<?php /** * Project: zaralab * Filename: console.php * * @author Miroslav Yovchev <*****@*****.**> * @since 31.10.15 */ require __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\Console\Input\ArgvInput; use Zaralab\Framework\Console\App; use Zaralab\Framework\Config; // Override DEBUG/ENV $input = new ArgvInput(); $env = $input->getParameterOption(array('--env', '-e'), null); $debug = $env === null ? null : !$input->hasParameterOption(array('--no-debug', '')) && $env != 'prod'; $container = Config::containerFactory(__DIR__, $env, $debug); // Set current directory to application root so we can find root config files chdir(__DIR__ . '/..'); $app = new App($container); $app->setCatchExceptions(true); // Set up DIC require __DIR__ . '/dependencies.php'; $app->run($input);
public function testHasParameterOptionOnlyOptions() { $input = new ArgvInput(array('cli.php', '-f', 'foo')); $this->assertTrue($input->hasParameterOption('-f', true), '->hasParameterOption() returns true if the given short option is in the raw input'); $input = new ArgvInput(array('cli.php', '--foo', '--', 'foo')); $this->assertTrue($input->hasParameterOption('--foo', true), '->hasParameterOption() returns true if the given long option is in the raw input'); $input = new ArgvInput(array('cli.php', '--foo=bar', 'foo')); $this->assertTrue($input->hasParameterOption('--foo', true), '->hasParameterOption() returns true if the given long option with provided value is in the raw input'); $input = new ArgvInput(array('cli.php', '--', '--foo')); $this->assertFalse($input->hasParameterOption('--foo', true), '->hasParameterOption() returns false if the given option is in the raw input but after an end of options signal'); }
$phpbb_root_path = __DIR__ . '/../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require $phpbb_root_path . 'includes/startup.' . $phpEx; require $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); extract($phpbb_config_php_file->get_all()); require $phpbb_root_path . 'includes/constants.' . $phpEx; require $phpbb_root_path . 'includes/functions.' . $phpEx; require $phpbb_root_path . 'includes/functions_admin.' . $phpEx; require $phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx; $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_dump_container(false); $input = new ArgvInput(); if ($input->hasParameterOption(array('--safe-mode'))) { $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); } else { $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); phpbb_load_extensions_autoloaders($phpbb_root_path); } $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->get('request')->enable_super_globals(); require $phpbb_root_path . 'includes/compatibility_globals.' . $phpEx; $user = $phpbb_container->get('user'); $user->data['user_id'] = ANONYMOUS; $user->ip = '127.0.0.1'; $user->add_lang('acp/common'); $user->add_lang('cli');
* If not, see http://www.gnu.org/licenses/. */ $values = array(); if (defined("PHAR")) { require_once "phar://kengrabber.phar/vendor/autoload.php"; $values['app_root'] = dirname(Phar::running(false)); $values['root'] = dirname(__DIR__); } else { require_once "vendor/autoload.php"; $values['app_root'] = $values['root'] = dirname(__DIR__); } use rootLogin\Kengrabber\Kengrabber; use Symfony\Component\Console\Input\ArgvInput; $input = new ArgvInput(); $env = $input->getParameterOption(array('--env', '-e'), getenv('APP_ENV') ?: 'dev'); $debug = $input->hasParameterOption(array('--debug')); //Remove the options $bad = ['--env', '-e', '--debug']; foreach ($_SERVER['argv'] as $key => $value) { if (in_array($value, $bad)) { unset($_SERVER['argv'][$key]); } } // enable all errors with debug == true if ($debug) { error_reporting(E_ALL); } $values['debug'] = isset($debug) ? $debug : false; $values['env'] = isset($env) ? $env : 'prod'; $app = new Kengrabber($values); $app->run();
date_default_timezone_set('UTC'); // Include Composer autoload require_once __DIR__ . '/../vendor/autoload.php'; // Get config $aConfig = call_user_func(function () { $aGlobalConfig = (require __DIR__ . '/../app/config/global.php'); $aLocalConfig = file_exists(__DIR__ . '/../app/config/local.php') ? require __DIR__ . '/../app/config/local.php' : []; return ExtendedArray::extendWithDefaultValues($aLocalConfig, $aGlobalConfig); }); // Get inputs $oInput = new ArgvInput(); // Build logger /** @var \Psr\Log\LoggerInterface $oLogger */ $oLogger = call_user_func(function () use($aConfig, $oInput) { // Get min level message if ($oInput->hasParameterOption(['-v', '-vv', '-vvv', '--verbose'])) { $iMinMsgLevel = LogLevel::DEBUG; } else { $iMinMsgLevel = LogLevel::INFO; } // Build handlers $oHandler = new StreamHandler('php://stdout', $iMinMsgLevel); $oSyslogHandler = new SyslogHandler($aConfig['logger']['syslog']['ident'], $aConfig['logger']['syslog']['facility'], $aConfig['logger']['syslog']['level']); // Set formatter $oLineFormatter = new LineFormatter($aConfig['logger']['line_format'], $aConfig['logger']['date_format'], false, true); $oHandler->setFormatter($oLineFormatter); // Build logger return new Logger($aConfig['logger']['name'], [$oHandler, $oSyslogHandler]); }); // Build Connection Locator /* @var $oDbConnectionLocator \Aura\Sql\ConnectionLocator */
public function requestAction() { $request = $this->get('request'); if ($request->isXmlHttpRequest() && $request->getMethod() == 'POST') { // retrieve command string $sf2Command = stripslashes($request->request->get('command')); if ($sf2Command == '.') { // this trick is used to give the possibility to have "php app/console" equivalent $sf2Command = 'list'; } //TODO: not really efficient $app = $request->request->get('app') ? $request->request->get('app') : basename($this->get('kernel')->getRootDir()); if (!in_array($app, $this->container->getParameter('sf2gen_console.apps'))) { return new Response('This application is not allowed...', 200); // set to 200 to allow console display } //Try to run a separate shell process if ($this->container->getParameter('sf2gen_console.new_process')) { //Try to run a separate shell process try { $php = $this->getPhpExecutable(); $commandLine = $php . ' ' . $app . '/' . 'console '; if (!empty($sf2Command)) { $commandLine .= $sf2Command; } $p = new Process($commandLine, dirname($this->get('kernel')->getRootDir()), null, null, 30, array('suppress_errors' => false, 'bypass_shell' => false)); $p->run(); $output = $p->getOutput(); /* if the process is not successful: - 1) Symfony throws an error and ouput is not empty; continue without Exception. - 2) Process throws an error and ouput is empty => Exception! */ if (!$p->isSuccessful() && empty($output)) { throw new \RuntimeException('Unabled to run the process.'); } } catch (\Exception $e) { // not trying the other method. It is interesting to know where it is not working (single process or not) return new Response(nl2br("The request failed when using a separated shell process. Try to use 'new_process: false' in configuration.\n Error : " . $e->getMessage())); } } else { //Try to execute a console within this process //TODO: fix cache:clear issue try { //Prepare input $args = preg_split("/ /", trim($sf2Command)); array_unshift($args, "fakecommandline"); //To simulate the console's arguments $app = $args[1]; $input = new ArgvInput($args); //Prepare output ob_start(); $output = new StreamOutput(fopen("php://output", 'w'), StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatterHtml(true)); //Start a kernel/console and an application $env = $input->getParameterOption(array('--env', '-e'), 'dev'); $debug = !$input->hasParameterOption(array('--no-debug', '')); $kernel = new \AppKernel($env, $debug); $kernel->boot(); $application = new Application($kernel); foreach ($kernel->getBundles() as $bundle) { $bundle->registerCommands($application); } //integrate all availables commands //Find, initialize and run the real command $run = $application->find($app)->run($input, $output); $output = ob_get_contents(); ob_end_clean(); } catch (\Exception $e) { return new Response(nl2br("The request failed when using same process.\n Error : " . $e->getMessage())); } } // common response for both methods if (empty($output)) { $output = 'The command "' . $sf2Command . '" was successful.'; } return new Response($this->convertOuput($output)); } return new Response('This request was not found.', 404); // request is not a POST request }
public function testHasParameterOption() { $input = new ArgvInput(array('cli.php', '-f', 'foo')); $this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input'); $input = new ArgvInput(array('cli.php', '--foo', 'foo')); $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input'); $input = new ArgvInput(array('cli.php', 'foo')); $this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input'); $input = new ArgvInput(array('cli.php', '--foo=bar')); $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given option with provided value is in the raw input'); }
<?php use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; 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); $input = new ArgvInput(); $env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; if ($debug) { Debug::enable(); } $kernel = new $kernelClass($env, $debug); $application = new Application($kernel); $application->run($input);