當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Console\Console類代碼示例

本文整理匯總了PHP中Zend\Console\Console的典型用法代碼示例。如果您正苦於以下問題:PHP Console類的具體用法?PHP Console怎麽用?PHP Console使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Console類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     if (\Zend\Console\Console::isConsole()) {
         return;
     }
     $eventManager = $e->getApplication()->getEventManager();
     $services = $e->getApplication()->getServiceManager();
     // TODO: Löschen sobald die Lösung mit der LoginBox klappt
     //$eventManager->attach(
     //    array(MvcEvent::EVENT_RENDER, MvcEvent::EVENT_RENDER_ERROR),
     //    array(new InjectLoginInfoListener(), 'injectLoginInfo'), -1000
     //);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $e) use($services) {
         /** @var CheckPermissionsListener $checkPermissionsListener */
         $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener');
         $checkPermissionsListener->onRoute($e);
     }, -10);
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) use($services) {
         /** @var CheckPermissionsListener $checkPermissionsListener */
         $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener');
         $checkPermissionsListener->onDispatch($e);
     }, 10);
     $unauthorizedAccessListener = $services->get('UnauthorizedAccessListener');
     $unauthorizedAccessListener->attach($eventManager);
     $sharedManager = $eventManager->getSharedManager();
     $defaultlistener = $services->get('Auth/Listener/AuthAggregateListener');
     $defaultlistener->attachShared($sharedManager);
 }
開發者ID:webpants,項目名稱:YAWIK,代碼行數:28,代碼來源:Module.php

示例2: onBootstrap

 public function onBootstrap(MvcEvent $mvcEvent)
 {
     if (Console::isConsole()) {
         return;
     }
     $application = $mvcEvent->getApplication();
     $serviceLocator = $application->getServiceManager();
     $strategy = $serviceLocator->get(AccessListener::class);
     $eventManager = $application->getEventManager();
     $strategy->attach($eventManager);
     //            try {
     //                $remote = new RemoteAddress;
     //                $remote->setUseProxy(true);
     //                $mapper = $serviceManager->get(UserAuthenticationLogMapper::class);
     //                $logEntity = new UserAuthenticationLog(
     //                    $authEvent->getIdentity(),
     //                    new \DateTime("now"),
     //                    $remote->getIpAddress()
     //                );
     //                $mapper->save($logEntity);
     //
     //            } catch (\Exception $x) {
     //
     //            }
     //        });
 }
開發者ID:saeven,項目名稱:zf3-circlical-user,代碼行數:26,代碼來源:Module.php

示例3: getCookieManager

 /**
  * Construct the cookie manager.
  *
  * @param ServiceManager $sm Service manager.
  *
  * @return \VuFind\Cookie\CookieManager
  */
 public static function getCookieManager(ServiceManager $sm)
 {
     if (Console::isConsole()) {
         return false;
     }
     return parent::getCookieManager($sm);
 }
開發者ID:jlehmus,項目名稱:NDL-VuFind2,代碼行數:14,代碼來源:Factory.php

示例4: createService

 /**
  * Create and return the router
  *
  * Retrieves the "router" key of the Config service, and uses it
  * to instantiate the router. Uses the TreeRouteStack implementation by
  * default.
  *
  * @param  ServiceLocatorInterface        $serviceLocator
  * @param  string|null                     $cName
  * @param  string|null                     $rName
  * @return \Zend\Mvc\Router\RouteStackInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
 {
     $config = $serviceLocator->get('Config');
     $routePluginManager = $serviceLocator->get('RoutePluginManager');
     if ($rName === 'ConsoleRouter' || $cName === 'router' && Console::isConsole()) {
         // We are in a console, use console router.
         if (isset($config['console']) && isset($config['console']['router'])) {
             $routerConfig = $config['console']['router'];
         } else {
             $routerConfig = array();
         }
         $router = new ConsoleRouter($routePluginManager);
     } else {
         // This is an HTTP request, so use HTTP router
         $router = new HttpRouter($routePluginManager);
         $routerConfig = isset($config['router']) ? $config['router'] : array();
     }
     if (isset($routerConfig['route_plugins'])) {
         $router->setRoutePluginManager($routerConfig['route_plugins']);
     }
     if (isset($routerConfig['routes'])) {
         $router->addRoutes($routerConfig['routes']);
     }
     if (isset($routerConfig['default_params'])) {
         $router->setDefaultParams($routerConfig['default_params']);
     }
     return $router;
 }
開發者ID:totolouis,項目名稱:ZF2-Auth,代碼行數:40,代碼來源:RouterFactory.php

示例5: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $app->getEventManager();
     $sm = $app->getServiceManager();
     // initialize SessionManager
     $this->bootstrapSession($e);
     // Attach UserListener for role and UserProfile handling
     $listener = $sm->get(UserListener::class);
     $eventManager->attach($listener);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'initTranslator'), -100);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'setUserLanguage'));
     // Enable BjyAuthorize when not in console mode
     if (!\Zend\Console\Console::isConsole()) {
         // Add ACL information to the Navigation view helper
         $authorize = $sm->get(Authorize::class);
         $acl = $authorize->getAcl();
         $role = $authorize->getIdentity();
         Navigation::setDefaultAcl($acl);
         Navigation::setDefaultRole($role);
     }
     /* @var $translator \Zend\I18n\Translator\Translator */
     $translator = $e->getApplication()->getServiceManager()->get('MvcTranslator');
     // add Db Loader factory
     $translator->getPluginManager()->setFactory(I18n\Translator\Loader\Db::class, I18n\Translator\Loader\Factory\DbFactory::class);
     if ($e->getRouter() instanceof \Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack) {
         $e->getRouter()->setTranslator($translator);
     }
 }
開發者ID:xelax90,項目名稱:skeleton-module,代碼行數:31,代碼來源:Module.php

示例6: __invoke

 /**
  * @param  ContainerInterface $container
  * @return ConsoleRequest|HttpRequest
  */
 public function __invoke(ContainerInterface $container)
 {
     if (Console::isConsole()) {
         return new ConsoleRequest();
     }
     return new HttpRequest();
 }
開發者ID:zfcampus,項目名稱:zf-content-negotiation,代碼行數:11,代碼來源:RequestFactory.php

示例7: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     if (\Zend\Console\Console::isConsole()) {
         return;
     }
     $eventManager = $e->getApplication()->getEventManager();
     $services = $e->getApplication()->getServiceManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $e) use($services) {
         /* @var $checkPermissionsListener \Acl\Listener\CheckPermissionsListener */
         $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener');
         $checkPermissionsListener->onRoute($e);
     }, -10);
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) use($services) {
         /** @var CheckPermissionsListener $checkPermissionsListener */
         $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener');
         $checkPermissionsListener->onDispatch($e);
     }, 10);
     $unauthorizedAccessListener = $services->get('UnauthorizedAccessListener');
     $unauthorizedAccessListener->attach($eventManager);
     $deactivatedUserListener = $services->get('DeactivatedUserListener');
     $deactivatedUserListener->attach($eventManager);
     $sharedManager = $eventManager->getSharedManager();
     $defaultlistener = $services->get('Auth/Listener/AuthAggregateListener');
     $defaultlistener->attachShared($sharedManager);
     $socialProfilesUnconfiguredErrorListener = new SocialProfilesUnconfiguredErrorListener();
     $socialProfilesUnconfiguredErrorListener->attach($eventManager);
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:27,代碼來源:Module.php

示例8: __invoke

 /**
  * Return a ConsoleViewManager if in a Console environment.
  *
  * @param ContainerInterface $container
  * @param string $name
  * @param callable $callback
  * @param null|array $options
  * @return \Zend\Mvc\Console\View\ViewManager|Zend\Mvc\View\Http\ViewManager
  */
 public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
 {
     if (!Console::isConsole() || !$container->has('ConsoleViewManager')) {
         return $callback();
     }
     return $container->get('ConsoleViewManager');
 }
開發者ID:zendframework,項目名稱:zend-mvc-console,代碼行數:16,代碼來源:ViewManagerDelegatorFactory.php

示例9: 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

示例10: getIP

 public static function getIP($just_remote = true)
 {
     if (Console::isConsole()) {
         return '127.0.0.1';
     }
     // O único realmente seguro de se confiar é o REMOTE_ADDR
     $validator = new \Zend\Validator\Ip();
     $remote = $_SERVER['REMOTE_ADDR'];
     if (!$validator->isValid($remote)) {
         throw new \RuntimeException("Endereço de IP '{$remote}' inválido");
     }
     if ($just_remote) {
         return $remote;
     }
     $ips = [$remote];
     if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
         $ip = $_SERVER['HTTP_CLIENT_IP'];
         if ($validator->isValid($ip)) {
             $ips[2] = $ip;
         }
     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
         if ($validator->isValid($ip)) {
             $ips[1] = $ip;
         }
     }
     return $ips;
 }
開發者ID:lafaiDev,項目名稱:suive_com,代碼行數:28,代碼來源:Util.php

示例11: createService

 /**
  * Create and return a request instance, according to current environment.
  *
  * @param  ServiceLocatorInterface $serviceLocator
  * @return ConsoleRequest|HttpRequest
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     if (Console::isConsole()) {
         return new ConsoleRequest();
     }
     return new HttpRequest();
 }
開發者ID:Baft,項目名稱:Zend-Form,代碼行數:13,代碼來源:RequestFactory.php

示例12: __invoke

 /**
  * Create and return a request instance, according to current environment.
  *
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $services
  * @return ConsoleRequest|HttpRequest
  */
 public function __invoke($services)
 {
     if (Console::isConsole()) {
         return new ConsoleRequest();
     }
     return new HttpRequest();
 }
開發者ID:gstearmit,項目名稱:EshopVegeTable,代碼行數:13,代碼來源:RequestFactory.php

示例13: createService

 /**
  * Create and return a request instance, according to current environment.
  *
  * @param  ServiceLocatorInterface $serviceLocator
  * @return HttpViewManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     if (Console::isConsole()) {
         return new ConsoleViewManager();
     }
     return new HttpViewManager();
 }
開發者ID:Baft,項目名稱:Zend-Form,代碼行數:13,代碼來源:ViewManagerFactory.php

示例14: createService

 /**
  * Create and return the view manager for the console environment
  *
  * @param  ServiceLocatorInterface $serviceLocator
  * @return ConsoleViewManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     if (!Console::isConsole()) {
         throw new ServiceNotCreatedException('ConsoleViewManager requires a Console environment; console environment not detected');
     }
     return new ConsoleViewManager();
 }
開發者ID:tejdeeps,項目名稱:tejcs.com,代碼行數:13,代碼來源:ConsoleViewManagerFactory.php

示例15: getConsoleAdapter

 /**
  *
  * @return ConsoleAdapter
  */
 public function getConsoleAdapter()
 {
     if (null === $this->consoleAdapter) {
         $this->consoleAdapter = Console::getInstance();
     }
     return $this->consoleAdapter;
 }
開發者ID:rezix,項目名稱:ZfcDatagrid,代碼行數:11,代碼來源:Renderer.php


注:本文中的Zend\Console\Console類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。