本文整理汇总了PHP中Zend\Console\Console::isConsole方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::isConsole方法的具体用法?PHP Console::isConsole怎么用?PHP Console::isConsole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Console\Console
的用法示例。
在下文中一共展示了Console::isConsole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: __invoke
/**
* @param ContainerInterface $container
* @return ConsoleRequest|HttpRequest
*/
public function __invoke(ContainerInterface $container)
{
if (Console::isConsole()) {
return new ConsoleRequest();
}
return new HttpRequest();
}
示例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: 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);
}
}
示例5: 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);
}
示例6: __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');
}
示例7: 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);
}
示例8: __invoke
/**
* @param ContainerInterface $container
* @param string $name
* @param callable $callback
* @param null|array $options
* @return ConsoleRequest|\Zend\Http\Request
*/
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
if (!Console::isConsole()) {
return $callback();
}
return new ConsoleRequest();
}
示例9: 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();
}
示例10: createService
/**
* Create and return a Console adapter instance.
* In case we're not in a Console environment, return a dummy stdClass object.
*
* In order to disable adapter auto-detection and use a specific adapter (and charset),
* add the following fields to application configuration, for example:
*
* 'console' => array(
* 'adapter' => 'MyConsoleAdapter', // always use this console adapter
* 'charset' => 'MyConsoleCharset', // always use this console charset
* ),
* 'service_manager' => array(
* 'invokables' => array(
* 'MyConsoleAdapter' => 'Zend\Console\Adapter\Windows',
* 'MyConsoleCharset' => 'Zend\Console\Charset\DESCG',
* )
* )
*
* @param ServiceLocatorInterface $serviceLocator
* @return AdapterInterface|stdClass
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
// First, check if we're actually in a Console environment
if (!Console::isConsole()) {
// SM factory cannot currently return null, so we return dummy object
return new stdClass();
}
// Read app config and determine Console adapter to use
$config = $serviceLocator->get('Config');
if (!empty($config['console']) && !empty($config['console']['adapter'])) {
// use the adapter supplied in application config
$adapter = $serviceLocator->get($config['console']['adapter']);
} else {
// try to detect best console adapter
$adapter = Console::detectBestAdapter();
$adapter = new $adapter();
}
// check if we have a valid console adapter
if (!$adapter instanceof AdapterInterface) {
// SM factory cannot currently return null, so we convert it to dummy object
return new stdClass();
}
// Optionally, change Console charset
if (!empty($config['console']) && !empty($config['console']['charset'])) {
// use the charset supplied in application config
$charset = $serviceLocator->get($config['console']['charset']);
$adapter->setCharset($charset);
}
return $adapter;
}
示例11: logException
/**
* Логгируем информацию об исключении
*
* @param \Exception $e
*/
public function logException(\Exception $e)
{
do {
$context = Console::isConsole() ? $_ENV : $_SERVER;
$this->getLogger()->crit($e->__toString(), ['context' => print_r($context, true)]);
} while ($e = $e->getPrevious());
}
示例12: 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();
}
示例13: __invoke
/**
* Create and return the view manager for the console environment
*
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return ConsoleViewManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
if (!Console::isConsole()) {
throw new ServiceNotCreatedException('ConsoleViewManager requires a Console environment; console environment not detected');
}
return new ConsoleViewManager();
}
示例14: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
if (!Console::isConsole()) {
$viewHelperManager = $serviceManager->get('ViewHelperManager');
$formElementErrors = $viewHelperManager->get('formElementErrors');
$formElementErrors->setMessageOpenFormat('<div class="zui-error">');
$formElementErrors->setMessageSeparatorString('</div><div class="zui-error">');
$formElementErrors->setMessageCloseString('</div>');
$flashMessenger = $viewHelperManager->get('flashMessenger');
$flashMessenger->setMessageOpenFormat('<div class="zui-alert zui-alert-%s"><p>');
$flashMessenger->setMessageSeparatorString('</p><p>');
$flashMessenger->setMessageCloseString('</p><span class="zui-icon zui-icon-x" role="button" tabindex="0"></span></div>');
/** @var ManagerInterface $sessionManager */
$sessionManager = $serviceManager->get(ManagerInterface::class);
$sessionManager->start();
}
$helpers = $serviceManager->get('ViewHelperManager');
$hal = $helpers->get('Hal');
$hal->getEventManager()->attach('renderCollection.post', [$this, 'onRenderCollection']);
$hal->getEventManager()->attach('renderEntity.post', [$this, 'onRenderEntity']);
}
示例15: createService
/**
* Create and return a view manager based on detected environment
*
* @param ServiceLocatorInterface $serviceLocator
* @return ConsoleViewManager|HttpViewManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (Console::isConsole()) {
return $serviceLocator->get('ConsoleViewManager');
}
return $serviceLocator->get('HttpViewManager');
}