本文整理汇总了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);
}
示例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) {
//
// }
// });
}
示例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);
}
示例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;
}
示例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);
}
}
示例6: __invoke
/**
* @param ContainerInterface $container
* @return ConsoleRequest|HttpRequest
*/
public function __invoke(ContainerInterface $container)
{
if (Console::isConsole()) {
return new ConsoleRequest();
}
return new HttpRequest();
}
示例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);
}
示例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');
}
示例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";
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例15: getConsoleAdapter
/**
*
* @return ConsoleAdapter
*/
public function getConsoleAdapter()
{
if (null === $this->consoleAdapter) {
$this->consoleAdapter = Console::getInstance();
}
return $this->consoleAdapter;
}