当前位置: 首页>>代码示例>>PHP>>正文


PHP Console::getInstance方法代码示例

本文整理汇总了PHP中Zend\Console\Console::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::getInstance方法的具体用法?PHP Console::getInstance怎么用?PHP Console::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Console\Console的用法示例。


在下文中一共展示了Console::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConsole

 /**
  * Return console adapter to use when showing prompt.
  *
  * @return ConsoleAdapter
  */
 public function getConsole()
 {
     if (!$this->console) {
         $this->console = Console::getInstance();
     }
     return $this->console;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:AbstractPrompt.php

示例2: __construct

 /**
  * Initialize the application
  *
  * Creates a RouteCollection and populates it with the $routes provided.
  *
  * Sets the banner to call showVersion().
  *
  * If no help command is defined, defines one.
  *
  * If no version command is defined, defines one.
  *
  * @param string $name Application name
  * @param string $version Application version
  * @param array|Traversable $routes Routes/route specifications to use for the application
  * @param Console $console Console adapter to use within the application
  * @param Dispatcher $dispatcher Configured dispatcher mapping routes to callables
  */
 public function __construct($name, $version, $routes, Console $console = null, Dispatcher $dispatcher = null)
 {
     if (!is_array($routes) && !$routes instanceof Traversable) {
         throw new InvalidArgumentException('Routes must be provided as an array or Traversable object');
     }
     $this->name = $name;
     $this->version = $version;
     if (null === $console) {
         $console = DefaultConsole::getInstance();
     }
     $this->console = $console;
     if (null === $dispatcher) {
         $dispatcher = new Dispatcher();
     }
     $this->dispatcher = $dispatcher;
     $this->routeCollection = $routeCollection = new RouteCollection();
     $this->setRoutes($routes);
     $this->banner = [$this, 'showVersion'];
     if (!$routeCollection->hasRoute('help')) {
         $this->setupHelpCommand($routeCollection, $dispatcher);
     }
     if (!$routeCollection->hasRoute('version')) {
         $this->setupVersionCommand($routeCollection, $dispatcher);
     }
     if (!$routeCollection->hasRoute('autocomplete')) {
         $this->setupAutocompleteCommand($routeCollection, $dispatcher);
     }
 }
开发者ID:stefanotorresi,项目名称:zf-console,代码行数:45,代码来源:Application.php

示例3: passwordAction

 public function passwordAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not
     // tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     // Get user email from console and check if the user used --verbose or
     // -v flag
     $userEmail = $request->getParam('userEmail');
     $verbose = $request->getParam('verbose');
     // reset new password
     $newPassword = Rand::getString(16);
     $console = Console::getInstance();
     if (Confirm::prompt('Is this the correct answer? [y/n]', 'y', 'n')) {
         $console->write("You chose YES\n");
     } else {
         $console->write("You chose NO\n");
     }
     if (!$verbose) {
         return "Done! {$userEmail} has received an email with his new password.\n";
     } else {
         return "Done! New password for user {$userEmail} is '{$newPassword}'. It has also been emailed to him. \n";
     }
 }
开发者ID:EngrHaiderAli,项目名称:movein-ui,代码行数:27,代码来源:WorkerController.php

示例4: getConsoleAdapter

 /**
  *
  * @return ConsoleAdapter
  */
 public function getConsoleAdapter()
 {
     if (null === $this->consoleAdapter) {
         $this->consoleAdapter = Console::getInstance();
     }
     return $this->consoleAdapter;
 }
开发者ID:rezix,项目名称:ZfcDatagrid,代码行数:11,代码来源:Renderer.php

示例5: installAction

 /**
  * Creates all needed classes and fills them with random data
  */
 public function installAction()
 {
     Time::check();
     $this->createTables();
     Console::getInstance()->writeLine('Tables created in ' . Time::check() . ' sec.');
     $pupilService = $this->getPupilService();
     $count = $this->generateItems($pupilService, $this->getRequest()->getParam('pupils', 100000), ['email', 'birthday'], function ($item) {
         return ['name' => $item['full'], 'email' => $item['email'], 'birthday' => $item['birthday'], 'level' => \Application\Entity\Pupil::$levels[rand(0, 5)]];
     });
     Console::getInstance()->writeLine($count . ' pupils generated in ' . Time::check() . ' sec.');
     $teachersCount = $this->getRequest()->getParam('teachers', 10000);
     $teacherService = $this->getTeacherService();
     $this->generateItems($teacherService, $teachersCount, ['phone'], function ($item) {
         $gender = $item['gender'] === \NameGenerator\Gender::GENDER_MALE ? TeacherEntity::GENDER_MALE : TeacherEntity::GENDER_FEMALE;
         return ['gender' => $gender, 'name' => $item['full'], 'phone' => $item['phone']];
     });
     Console::getInstance()->writeLine($teachersCount . ' teachers generated in ' . Time::check() . ' sec.');
     $pupilMaxId = $pupilService->getMaxId();
     $teacherMaxId = $teacherService->getMaxId();
     $teacherPupilService = $this->getTeacherPupilService();
     $linksCount = 0;
     for ($teacherId = 1; $teacherId < $teacherMaxId; $teacherId++) {
         $except = [];
         for ($j = 0; $j < rand(0, 3); $j++) {
             $pupil_id = rand(0, $pupilMaxId);
             if (in_array($pupil_id, $except)) {
                 continue;
             }
             $except[] = $pupil_id;
             $teacherPupilService->insert(['teacher_id' => $teacherId, 'pupil_id' => $pupil_id]);
             $linksCount++;
         }
     }
     Console::getInstance()->writeLine($linksCount . ' links generated in ' . Time::check() . ' sec.');
 }
开发者ID:sedpro,项目名称:test_skyeng,代码行数:38,代码来源:CliController.php

示例6: __construct

 public function __construct()
 {
     $routes = [['name' => '<config> <output_file> [--strip]', 'short_description' => "Generate class cache based on <config> file into <output_file>.", 'handler' => [$this, 'generateDump']]];
     parent::__construct('Cache dumper', 1.0, $routes, Console::getInstance());
     $this->removeRoute('autocomplete');
     $this->removeRoute('help');
     $this->removeRoute('version');
 }
开发者ID:mtymek,项目名称:class-dumper,代码行数:8,代码来源:DumperApp.php

示例7: __construct

 /**
  * Create console instance for color output of success/failure
  * messages.
  *
  * @param ConsoleAdapter $console
  */
 public function __construct(ConsoleAdapter $console = null)
 {
     if (null === $console) {
         $this->console = Console::getInstance();
     } else {
         $this->console = $console;
     }
 }
开发者ID:bravadomizzou,项目名称:dewdrop,代码行数:14,代码来源:Markdown.php

示例8: setUp

 /**
  * setUp from PHPUnit
  */
 public function setUp()
 {
     ob_start();
     $this->console = Console::getInstance();
     $this->routes = (include __DIR__ . '/../config/routes.php');
     $this->deploy = new Deploy();
     copy(__DIR__ . '/TestAsset/App/config/autoload/.gitignore.dist', __DIR__ . '/TestAsset/App/config/autoload/.gitignore');
 }
开发者ID:beejhuff,项目名称:zf-deploy,代码行数:11,代码来源:DeployTest.php

示例9: testDrawReal

 /**
  * @coversNothing
  */
 public function testDrawReal()
 {
     $console = Console::getInstance();
     ob_start();
     (new Logo())->draw($console);
     $this->assertNotEmpty(ob_get_contents());
     ob_end_clean();
 }
开发者ID:ocramius,项目名称:ocramius,代码行数:11,代码来源:LogoTest.php

示例10: testCanForceInstance

 public function testCanForceInstance()
 {
     $console = Console::getInstance('Posix');
     $this->assertTrue($console instanceof Adapter\AdapterInterface);
     $this->assertTrue($console instanceof Adapter\Posix);
     Console::overrideIsConsole(null);
     Console::resetInstance();
     $console = Console::getInstance('Windows');
     $this->assertTrue($console instanceof Adapter\AdapterInterface);
     $this->assertTrue($console instanceof Adapter\Windows);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:11,代码来源:ConsoleTest.php

示例11: __construct

 public function __construct(Options $options = null, Console $console = null)
 {
     if (null === $options) {
         $options = new Options();
     }
     $this->options = $options;
     if (null === $console) {
         $console = Console::getInstance();
     }
     $this->console = $console;
 }
开发者ID:ivan-novakov,项目名称:php-perun-api,代码行数:11,代码来源:perun-client.php

示例12: dumpCompleteAction

 /**
  * Dumps all available routes (including defined in modules) into cache file.
  * @see annotated_router.cache_file config key
  */
 public function dumpCompleteAction()
 {
     $config = $this->serviceLocator->get('Config');
     $console = Console::getInstance();
     $console->writeLine('Dumping all routes into "' . $config['annotated_router']['cache_file'] . '"');
     $annotatedRouterConfig = $this->serviceLocator->get('AnnotatedRouter\\ControllerParser')->getRouteConfig();
     $annotatedRouterConfig = array_replace_recursive($annotatedRouterConfig, isset($config['router']['routes']) ? $config['router']['routes'] : array());
     $generator = new ValueGenerator($annotatedRouterConfig);
     $content = "<?php\n\nreturn " . $generator . ';';
     file_put_contents($config['annotated_router']['cache_file'], $content);
 }
开发者ID:alex-oleshkevich,项目名称:zf2-annotated-router,代码行数:15,代码来源:ConsoleController.php

示例13: setUp

 protected function setUp()
 {
     $config = ['app' => "this is my app", "test" => "prova", "version" => "0.0.1", 'routes' => [['name' => 'hello', 'route' => "--name=", 'short_description' => "Good morning!! This is a beautiful day", "handler" => ['App\\Command\\Hello', 'run']]], "service_manager" => ["invokables" => [], "factories" => []]];
     $builder = new ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions($config);
     $container = $builder->build();
     $configServiceManager = new Config($config['service_manager']);
     $container->set("service_manager", new ServiceManager($configServiceManager));
     $this->application = new Application($config['app'], $config['version'], $config['routes'], Console::getInstance(), new Dispatcher($container));
 }
开发者ID:gianarb,项目名称:pan,代码行数:11,代码来源:ApplicationTest.php

示例14: installAction

 /**
  * Creates all needed classes and filles them with dummie data
  */
 public function installAction()
 {
     Time::check();
     $nameGenerator = new \NameGenerator\Generator();
     $this->createTables();
     $teachersCount = $this->getRequest()->getParam('teachers', 10000);
     $pupilsCount = $this->getRequest()->getParam('pupils', 100000);
     /** @var \Application\Model\Teacher $teacherTable */
     $teacherTable = $this->getServiceLocator()->get('TeacherTable');
     /** @var \Application\Model\Pupil $pupilTable */
     $pupilTable = $this->getServiceLocator()->get('PupilTable');
     /** @var \Application\Model\TeacherPupil $teacherPupilTable */
     $teacherPupilTable = $this->getServiceLocator()->get('TeacherPupilTable');
     Console::getInstance()->writeLine('Tables created in ' . Time::check() . ' sec.');
     $pupils = $nameGenerator->get($pupilsCount, ['email', 'birthday']);
     foreach ($pupils as $randomPupil) {
         $level = \Application\Entity\Pupil::$levels[rand(0, count(\Application\Entity\Pupil::$levels) - 1)];
         /** @var \Application\Entity\Pupil $pupil */
         $pupil = $pupilTable->getEntity();
         $pupil->setName($randomPupil['first'] . ' ' . $randomPupil['last'])->setEmail($randomPupil['email'])->setBirthday($randomPupil['birthday'])->setLevel($level);
         $pupilTable->insert($pupil);
     }
     Console::getInstance()->writeLine($pupilsCount . ' pupils generated in ' . Time::check() . ' sec.');
     $teachers = $nameGenerator->get($teachersCount, ['phone']);
     foreach ($teachers as $randomTeacher) {
         $gender = $randomTeacher['gender'] == \NameGenerator\Gender::GENDER_MALE ? \Application\Entity\Teacher::GENDER_MALE : \Application\Entity\Teacher::GENDER_FEMALE;
         /** @var \Application\Entity\Teacher $teacher */
         $teacher = $teacherTable->getEntity();
         $teacher->setName($randomTeacher['first'] . ' ' . $randomTeacher['last'])->setGender($gender)->setPhone($randomTeacher['phone']);
         $teacherTable->insert($teacher);
     }
     Console::getInstance()->writeLine($teachersCount . ' teachers generated in ' . Time::check() . ' sec.');
     $pupilMaxId = $pupilTable->getMaxId();
     $teacherMaxId = $teacherTable->getMaxId();
     $linksCount = 0;
     for ($teacherId = 1; $teacherId < $teacherMaxId; $teacherId++) {
         $except = [];
         for ($j = 0; $j < rand(0, 3); $j++) {
             $pupil_id = rand(0, $pupilMaxId);
             if (in_array($pupil_id, $except)) {
                 continue;
             }
             $except[] = $pupil_id;
             $link = $teacherPupilTable->getEntity();
             $link->teacher_id = $teacherId;
             $link->pupil_id = $pupil_id;
             $teacherPupilTable->insert($link);
             $linksCount++;
         }
     }
     Console::getInstance()->writeLine($linksCount . ' links generated in ' . Time::check() . ' sec.');
 }
开发者ID:shukshin-ivan,项目名称:test_skyeng,代码行数:55,代码来源:CliController.php

示例15: getAccessToken

 /**
  * Получить AccessToken из консоли
  *
  * @param EventInterface $e
  *
  * @return string|null
  * @throws \Zend\Console\Exception\RuntimeException
  * @throws \Zend\Console\Exception\InvalidArgumentException
  * @throws \Assert\AssertionFailedException
  */
 public function getAccessToken(EventInterface $e)
 {
     if (!Console::isConsole()) {
         return null;
     }
     $authUrl = $e->getParam('authUrl', null);
     Assertion::url($authUrl);
     $console = Console::getInstance();
     $console->writeLine(sprintf('Open the following link in your browser:'));
     $console->writeLine($authUrl);
     $console->writeLine();
     $console->write('Enter verification code: ');
     return $console->readLine();
 }
开发者ID:old-town-gitlab-tools,项目名称:analizator,代码行数:24,代码来源:AccessTokenFromConsole.php


注:本文中的Zend\Console\Console::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。