本文整理汇总了PHP中Symfony\Component\Console\Input\ArgvInput::getParameterOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ArgvInput::getParameterOption方法的具体用法?PHP ArgvInput::getParameterOption怎么用?PHP ArgvInput::getParameterOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\ArgvInput
的用法示例。
在下文中一共展示了ArgvInput::getParameterOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param ConsoleOutput $output
* @param ArgvInput $input
*/
public function __construct(ConsoleOutput $output, ArgvInput $input)
{
$this->output = $output;
$kernel = $this->bootKernel($input->getParameterOption(['-e', '--env'], 'dev'));
$this->container = $kernel->getContainer();
$this->ormConnection = $this->container->get('database_connection');
$this->schemaHelper = new SchemaHelper($this->container);
$this->upgradeHelper = new UpgradeHelper($this->container);
$this->mediaDirectory = $input->getParameterOption(['--media-directory'], $this->container->getParameter('kernel.root_dir') . self::MEDIA_DIR);
$this->productMediaTable = $input->getParameterOption(['--product-media-table'], self::MEDIA_TABLE);
$this->productTemplateTable = $input->getParameterOption(['--product-template-table'], self::TEMPLATE_TABLE);
if (!is_dir($this->mediaDirectory)) {
throw new \RuntimeException(sprintf('The media directory "%s" does not exist', $this->mediaDirectory));
}
}
示例2: __construct
/**
* Constructor. This is run before any modules are loaded, so we can
* initialise the console here.
*
* @param ContainerInterface $container The service container
* @param array|null $arguments Arguments to pass into the Console component
*
* @todo Change the environment earlier if possible. Can we make the context
* run something before even Cog is bootstrapped?
*/
public function __construct(ContainerInterface $container, array $arguments = null)
{
$this->_services = $container;
$this->_services['console.commands'] = function () {
return new CommandCollection(array(new Command\EventList(), new Command\ModuleList(), new Command\RouteList(), new Command\RouteCollectionTree(), new Command\Setup(), new Command\Status(), new Command\TaskGenerate(), new Command\TaskList(), new Command\TaskRun(), new Command\TaskRunScheduled(), new Command\AssetDump(), new Command\AssetGenerator(), new Command\MigrateInstall(), new Command\MigrateRollback(), new Command\MigrateReset(), new Command\MigrateRefresh(), new Command\MigrateRun(), new Command\DeployEvent(), new Command\DeployPermissions(), new Command\ModuleNamespace(), new Command\CacheClear()));
};
$this->_services['console.app'] = function ($c) {
$app = new Application();
$app->setContainer($c);
$app->getDefinition()->addOption(new InputOption('--' . $app::ENV_OPT_NAME, '', InputOption::VALUE_OPTIONAL, 'The Environment name.'));
// Add the commands
foreach ($c['console.commands'] as $command) {
$app->add($command);
}
return $app;
};
if (null === $arguments) {
$arguments = $_SERVER['argv'];
}
$input = new ArgvInput($arguments);
if ($env = $input->getParameterOption(array('--env'), '')) {
$this->_services['environment']->setWithInstallation($env);
}
// Setup a fake request context
$this->_services['http.request.context'] = function ($c) {
$context = new \Message\Cog\Routing\RequestContext();
return $context;
};
}
示例3: handleCompilerEnvironment
/**
* 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);
}
}
示例4: __construct
public function __construct(ConsoleOutput $output, ArgvInput $input)
{
$this->output = $output;
$env = $input->getParameterOption(['-e', '--env']);
if (!$env) {
$env = 'dev';
}
$this->kernel($env);
}
示例5: __construct
/**
* @param ConsoleOutput $output
* @param ArgvInput $input
*/
public function __construct(ConsoleOutput $output, ArgvInput $input)
{
$this->output = $output;
$env = $input->getParameterOption(['-e', '--env']);
if (!$env) {
$env = 'dev';
}
$this->bootKernel($env);
$schemaHelper = new SchemaHelper($this->container);
$this->productTemplateTable = $schemaHelper->getTableOrCollection('product_template');
}
示例6: runCLI
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);
}
示例7: bootstrapOxid
/**
* @return bool
*/
public function bootstrapOxid()
{
$input = new ArgvInput();
if ($input->getParameterOption('--shopDir')) {
$oxBootstrap = $input->getParameterOption('--shopDir') . '/bootstrap.php';
if ($this->checkBootstrapOxidInclude($oxBootstrap) === true) {
return true;
}
return false;
}
// try to guess where bootstrap.php is
$currentWorkingDirectory = getcwd();
do {
$oxBootstrap = $currentWorkingDirectory . '/bootstrap.php';
if ($this->checkBootstrapOxidInclude($oxBootstrap) === true) {
return true;
break;
}
$currentWorkingDirectory = dirname($currentWorkingDirectory);
} while ($currentWorkingDirectory !== '/');
return false;
}
示例8: console
/**
* 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);
}
示例9: loadCli
/**
*
* @param Event $event
*/
public function loadCli(EventInterface $event)
{
$commands = array(new \Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateDocumentsCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateHydratorsCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand(), new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand());
foreach ($commands as $command) {
$command->getDefinition()->addOption(new InputOption('documentmanager', null, InputOption::VALUE_OPTIONAL, 'The name of the documentmanager to use. If none is provided, it will use odm_default.'));
}
$cli = $event->getTarget();
$cli->addCommands($commands);
$arguments = new ArgvInput();
$documentManagerName = $arguments->getParameterOption('--documentmanager');
$documentManagerName = !empty($documentManagerName) ? $documentManagerName : 'odm_default';
$documentManager = $event->getParam('ServiceManager')->get('doctrine.documentmanager.' . $documentManagerName);
$documentHelper = new \Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper($documentManager);
$cli->getHelperSet()->set($documentHelper, 'dm');
}
示例10: getBundles
/**
* @return string[]
* @author Maximilian Ruta <mr@xtain.net>
*/
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;
}
示例11: checkForSpecificEnvironmentFile
/**
* 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);
}
}
示例12: getContainer
/**
* @return ContainerBuilder
*/
public function getContainer()
{
if ($this->container) {
return $this->container;
}
// Load cli options:
$input = new ArgvInput();
$configPath = $input->getParameterOption(['--config', '-c'], $this->getConfigDefaultPath());
// Make sure to set the full path when it is declared relative
// This will fix some issues in windows.
$filesystem = new Filesystem();
if (!$filesystem->isAbsolutePath($configPath)) {
$configPath = getcwd() . DIRECTORY_SEPARATOR . $configPath;
}
$this->container = new ContainerBuilder();
$extension = new OctavaGeggsExtension();
$this->container->registerExtension($extension);
$loader = new YamlFileLoader($this->container, new FileLocator(dirname($configPath)));
$loader->load(basename($configPath));
$this->container->compile();
return $this->container;
}
示例13: setEntityManager
public function setEntityManager(Event $e)
{
/* @var $cli \Symfony\Component\Console\Application */
$cli = $e->getTarget();
// Set new option for all commands
$commands = $cli->all();
foreach ($commands as $command) {
$command->getDefinition()->addOption(new InputOption('em', null, InputOption::VALUE_OPTIONAL, 'Set the name of your entity manager (overrides orm_default)'));
}
// Get command-line arguments
$args = new ArgvInput();
$em = $args->getParameterOption('--em');
// Set the new em if needed
if ($em) {
/* @var $serviceLocator \Zend\ServiceManager\ServiceLocatorInterface */
$serviceLocator = $e->getParam('ServiceManager');
/* @var $entityManager \Doctrine\ORM\EntityManager */
$entityManager = $serviceLocator->get(sprintf('doctrine.entitymanager.%s', $em));
$helperSet = $cli->getHelperSet();
$helperSet->set(new ConnectionHelper($entityManager->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($entityManager), 'em');
}
}
示例14: ArgvInput
/**
* 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;
}
示例15: requestAction
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
}