php Symfony-Component-Console-Input-ArgvInput类(方法)实例源码

下面列出了php Symfony-Component-Console-Input-ArgvInput 类(方法)源码代码实例,从而了解它的用法。

作者:mothership-e    项目:co   
/**
  * 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;
     };
 }

作者:adolfo210    项目:hcloudfile   
/**
  * @param OutputInterface $output
  */
 public function loadCommands(OutputInterface $output)
 {
     // $application is required to be defined in the register_command scripts
     $application = $this->application;
     require_once \OC::$SERVERROOT . '/core/register_command.php';
     if ($this->config->getSystemValue('installed', false)) {
         if (!\OCP\Util::needUpgrade()) {
             OC_App::loadApps();
             foreach (OC_App::getAllApps() as $app) {
                 $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
                 if (file_exists($file)) {
                     require $file;
                 }
             }
         } else {
             $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
         }
     } else {
         $output->writeln("ownCloud is not installed - only a limited number of commands are available");
     }
     $input = new ArgvInput();
     if ($input->getFirstArgument() !== 'check') {
         $errors = \OC_Util::checkServer(\OC::$server->getConfig());
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $output->writeln($error['error']);
                 $output->writeln($error['hint']);
                 $output->writeln('');
             }
             throw new \Exception("Environment not properly prepared.");
         }
     }
 }

作者:stevepo    项目:testing-bundl   
/**
  * @see FixturesExportCommand::execute
  */
 public function testExecute_SpecificEntity_Association()
 {
     $directoryPath = sys_get_temp_dir();
     $dumper = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Fixture\\Dumper')->disableOriginalConstructor()->setMethods(['dumpToYaml', 'setAssociation', 'setClassMetadataInfo'])->getMock();
     $dumper->expects($this->once())->method('dumpToYaml')->with($directoryPath)->will($this->returnValue($directoryPath . '/table.yml'));
     $dumper->expects($this->once())->method('setAssociation')->with(true)->will($this->returnValue(null));
     $classMetaDataInfo = $this->getMockBuilder('\\Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $dumper->expects($this->once())->method('setClassMetadataInfo')->with($classMetaDataInfo)->will($this->returnValue(null));
     $metaDataFactory = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\Mapping\\ClassMetadataFactory')->disableOriginalConstructor()->setMethods(['getMetadataFor'])->getMockForAbstractClass();
     $metaDataFactory->expects($this->once())->method('getMetadataFor')->with('BundleName:EntityName')->will($this->returnValue($classMetaDataInfo));
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getMetadataFactory'])->getMock();
     $entityManager->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metaDataFactory));
     $doctrine = $this->getMockBuilder('\\Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->setMethods(['getManager'])->getMock();
     $doctrine->expects($this->once())->method('getManager')->will($this->returnValue($entityManager));
     $container = new Container();
     $container->set('doctrine', $doctrine);
     $container->set('cosma_testing.fixture_dumper', $dumper);
     $command = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Command\\FixturesExportCommand')->disableOriginalConstructor()->setMethods(['getContainer'])->getMock();
     $command->expects($this->exactly(2))->method('getContainer')->will($this->returnValue($container));
     $reflectionClass = new \ReflectionClass($command);
     $dumperProperty = $reflectionClass->getParentClass()->getProperty('dumper');
     $dumperProperty->setAccessible(true);
     $dumperProperty->setValue($command, $dumper);
     $inputDefinition = new InputDefinition([new InputArgument('dumpDirectory', InputArgument::REQUIRED), new InputArgument('entity', InputArgument::OPTIONAL), new InputOption('associations', 'a', InputOption::VALUE_NONE)]);
     $input = new ArgvInput(['dummySoInputValidates' => 'dummy', 'dumpDirectory' => $directoryPath, 'entity' => 'BundleName:EntityName'], $inputDefinition);
     $input->setOption('associations', true);
     $output = new BufferedOutput();
     $reflectionClass = new \ReflectionClass($command);
     $executeMethod = $reflectionClass->getMethod('execute');
     $executeMethod->setAccessible(true);
     $executeMethod->invoke($command, $input, $output);
     $this->assertContains("successfully dumped in file  {$directoryPath}/table.yml", $output->fetch(), 'The entity was not dump successfully');
 }

作者:quickstra    项目:quickstra   
public function initComposer(OutputInterface $output)
 {
     $input = new ArgvInput(['composer', 'init']);
     $input->setInteractive(true);
     /** @var InitCommand $command */
     $command = $this->getHelperSet()->getCommand()->getApplication()->find('init');
     return $this->execute($input, $output, $command);
 }

作者:EnmanuelCod    项目:backend-larave   
/**
     * `psysh` command line executable.
     *
     * @return Closure
     */
    function bin()
    {
        return function () {
            $usageException = null;
            $input = new ArgvInput();
            try {
                $input->bind(new InputDefinition(array(new InputOption('help', 'h', InputOption::VALUE_NONE), new InputOption('config', 'c', InputOption::VALUE_REQUIRED), new InputOption('version', 'v', InputOption::VALUE_NONE), new InputOption('cwd', null, InputOption::VALUE_REQUIRED), new InputArgument('include', InputArgument::IS_ARRAY))));
            } catch (\RuntimeException $e) {
                $usageException = $e;
            }
            $config = array();
            // Handle --config
            if ($configFile = $input->getOption('config')) {
                $config['configFile'] = $configFile;
            }
            $shell = new Shell(new Configuration($config));
            // Handle --help
            if ($usageException !== null || $input->getOption('help')) {
                if ($usageException !== null) {
                    echo $usageException->getMessage() . PHP_EOL . PHP_EOL;
                }
                $version = $shell->getVersion();
                $name = basename(reset($_SERVER['argv']));
                echo <<<EOL
{$version}

Usage:
  {$name} [--version] [--help] [files...]

Options:
  --help     -h Display this help message.
  --config   -c Use an alternate PsySH config file location.
  --cwd         Use an alternate working directory.
  --version  -v Display the PsySH version.

EOL;
                exit($usageException === null ? 0 : 1);
            }
            // Handle --version
            if ($input->getOption('version')) {
                echo $shell->getVersion() . PHP_EOL;
                exit(0);
            }
            // Pass additional arguments to Shell as 'includes'
            $shell->setIncludes($input->getArgument('include'));
            try {
                // And go!
                $shell->run();
            } catch (Exception $e) {
                echo $e->getMessage() . PHP_EOL;
                // TODO: this triggers the "exited unexpectedly" logic in the
                // ForkingLoop, so we can't exit(1) after starting the shell...
                // fix this :)
                // exit(1);
            }
        };
    }

作者:umpirsk    项目:pim-community-de   
public function __construct(ConsoleOutput $output, ArgvInput $input)
 {
     $this->output = $output;
     $env = $input->getParameterOption(['-e', '--env']);
     if (!$env) {
         $env = 'dev';
     }
     $this->kernel($env);
 }

作者:hotfic    项目:lichess-ol   
public function isSafe(ArgvInput $input, $env)
 {
     if ('prod' == $env) {
         if (in_array($input->getFirstArgument(), $this->productionBlackList)) {
             return false;
         }
     }
     return true;
 }

作者:ChrisWesterfiel    项目:MJR.ONE-C   
/**
  * We need to add the profile enable option to all commands if we are in
  * the parameter mode.
  *
  * Inspired by
  * http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/
  *
  * @param ConsoleCommandEvent $event
  * @return mixed
  */
 private function isProfileOption(ConsoleCommandEvent $event)
 {
     $inputDefinition = $event->getCommand()->getApplication()->getDefinition();
     $inputDefinition->addOption(new InputOption($this->optionName, null, InputOption::VALUE_NONE, '<info>JnsXhprofBundle</info>: Whether to profile this command with xhprof', null));
     // merge the application's input definition
     $event->getCommand()->mergeApplicationDefinition();
     $input = new ArgvInput();
     // we use the input definition of the command
     $input->bind($event->getCommand()->getDefinition());
     return $input->getOption($this->optionName);
 }

作者:Slayu    项目:casto   
/**
  * Do the locateFile Action
  *
  * @param $arg
  * @param $dir
  * @return string
  */
 protected function runLocateFile($arg, $dir)
 {
     chdir($this->baseDir . '/' . $dir);
     $definition = new InputDefinition(array(new InputOption('configuration')));
     $input = new ArgvInput(array(), $definition);
     if ($arg) {
         $input->setOption('configuration', $arg);
     }
     $command = new VoidCommand('void');
     return $command->locateConfigFile($input);
 }

作者:juliensn    项目:pim-community-standar   
/**
  * @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');
 }

作者:kosak8    项目:OpenSoccerSta   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->write('loading all fixtures...........');
     $input = new ArgvInput();
     $input->setInteractive(false);
     $command = $this->getApplication()->find('doctrine:fixtures:load');
     $command->run($input, new NullOutput());
     $output->writeln('<info>OK</info>');
     $output->write('setting up match fixtures......');
     $this->getContainer()->get('oss.league.service.fixture')->createFixtures(1);
     $output->writeln('<info>OK</info>');
 }

作者:alpixe    项目:AlpixelCMSBundl   
public function execute(InputInterface $input, OutputInterface $output)
 {
     $definition = $this->getDefinition();
     $arguments = $definition->getArguments();
     $arguments['target']->setDefault($this->container->getParameter('kernel.root_dir') . '/../web/');
     $definition->setArguments($arguments);
     if (count($input->getArguments()) === 0) {
         $input = new ArgvInput(null, $definition);
         $input->setArgument('target', $this->container->getParameter('kernel.root_dir') . '/../web/');
     }
     return parent::execute($input, $output);
 }

作者:mork    项目:bounce-bundl   
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);
 }

作者:michaldude    项目:flavou   
/**
  * 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);
 }

作者:quickstra    项目:quickstra   
public function requirePackage(OutputInterface $output, $package, $version = null, $dev = true)
 {
     $packageArg = sprintf("%s%s", $package, $version != null ? ':' . $version : null);
     $args = ['composer', 'require'];
     if ($dev) {
         $args[] = '--dev';
     }
     $args[] = $packageArg;
     $input = new ArgvInput($args);
     $input->setInteractive(true);
     /** @var RequireCommand $command */
     $command = $this->getHelperSet()->getCommand()->getApplication()->find('require');
     return $this->execute($input, $output, $command);
 }

作者:drewmelc    项目:platformsh-cl   
/**
  * @param string $arg
  *
  * @return string
  */
 protected function escapeArg($arg)
 {
     // Get a blank ArgvInput object so we can use the 'escapeToken' method.
     $argv = new ArgvInput();
     // If the string looks like an option=value pair, split them up.
     if ($arg[0] === '-' && strpos($arg, '=')) {
         list($option, $value) = explode('=', $arg, 2);
         return $option . '=' . $argv->escapeToken($value);
     }
     if (strpos($arg, '-') === 0) {
         return $arg;
     }
     return $argv->escapeToken($arg);
 }

作者:afrihos    项目:BaseCommandBundl   
/**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     /** @var Application $application */
     $application = $command->getApplication();
     $inputDefinition = $command->getDefinition();
     if ($command instanceof HelpCommand) {
         $input = new ArgvInput();
         $input->bind($inputDefinition);
         $command = $application->find($input->getFirstArgument());
     }
     if ($command instanceof BaseCommand) {
         $this->setInputDefinition($inputDefinition);
     }
 }

作者:aml-bendal    项目:ExpandAkeneoAp   
/**
  * @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));
     }
 }

作者:Catapus    项目:Idephi   
public function testParameters()
 {
     $cw = $this->buildCommandWrapper();
     $originaDefinition = clone $cw->getDefinition();
     $appIndexDefinition = $this->buildInputDefinition();
     $this->mergeInputDefinitions($cw, $appIndexDefinition);
     $input = new ArgvInput(array('cmd', 'uno_value', 'name_value', '--go'));
     $input->bind($cw->getDefinition());
     $input = $cw->filterByOriginalDefinition($input, $appIndexDefinition);
     $input->validate();
     $this->assertEquals(count($originaDefinition->getArguments()), count($input->getArguments()));
     $this->assertEquals(1, count($input->getArguments()));
     $this->assertEquals(array('name' => 'name_value'), $input->getArguments());
     $this->assertEquals(array('go' => true), $input->getOptions());
 }

作者:im286e    项目:en   
/**
  *
  * @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');
 }


问题


面经


文章

微信
公众号

扫码关注公众号