public function getGlobals() { /** @var \Bolt\Config $config */ $config = $this->app['config']; $configVal = $this->safe ? null : $config; /** @var \Bolt\Users $users */ $users = $this->app['users']; /** @var \Bolt\Configuration\ResourceManager $resources */ $resources = $this->app['resources']; $zone = null; /** @var RequestStack $requestStack */ $requestStack = $this->app['request_stack']; if ($request = $requestStack->getCurrentRequest()) { $zone = Zone::get($request); } // User calls can cause exceptions that block the exception handler try { /** @deprecated Deprecated since 3.0, to be removed in 4.0. */ $usersVal = $this->safe ? null : $users->getUsers(); $usersCur = $users->getCurrentUser(); } catch (\Exception $e) { $usersVal = null; $usersCur = null; } // Structured to allow PHPStorm's SymfonyPlugin to provide code completion return ['bolt_name' => Bolt\Version::name(), 'bolt_version' => Bolt\Version::VERSION, 'bolt_stable' => Bolt\Version::isStable(), 'frontend' => $zone === Zone::FRONTEND, 'backend' => $zone === Zone::BACKEND, 'async' => $zone === Zone::ASYNC, 'paths' => $resources->getPaths(), 'theme' => $config->get('theme'), 'user' => $usersCur, 'users' => $usersVal, 'config' => $configVal]; }
/** * @param array $values */ public function __construct(array $values = []) { /** @deprecated since 3.0, to be removed in 4.0. */ $values['bolt_version'] = Version::VERSION; /** @deprecated since 3.0, to be removed in 4.0. */ $values['bolt_name'] = Version::name(); /** @deprecated since 3.0, to be removed in 4.0. */ $values['bolt_released'] = Version::isStable(); /** @deprecated since 3.0, to be removed in 4.0. */ $values['bolt_long_version'] = Version::VERSION; /** @internal Parameter to track a deprecated PHP version */ $values['deprecated.php'] = version_compare(PHP_VERSION, '5.5.9', '<'); parent::__construct($values); $this->register(new PathServiceProvider()); // Initialize the config. Note that we do this here, on 'construct'. // All other initialisation is triggered from bootstrap.php // Warning! // One of a valid ResourceManager ['resources'] or ClassLoader ['classloader'] // must be defined for working properly if (!isset($this['resources'])) { $this['resources'] = new Configuration\ResourceManager($this); } else { $this['classloader'] = $this['resources']->getClassLoader(); } // Register a PHP shutdown function to catch fatal errors with the application object register_shutdown_function(['\\Bolt\\Exception\\LowlevelException', 'catchFatalErrors'], $this); $this['resources']->setApp($this); $this->initConfig(); $this->initLogger(); $this['resources']->initialize(); $this['debug'] = $this['config']->get('general/debug', false); $locales = (array) $this['config']->get('general/locale'); $this['locale'] = reset($locales); // Initialize the 'editlink' and 'edittitle'. $this['editlink'] = ''; $this['edittitle'] = ''; // Initialize the JavaScript data gateway. $this['jsdata'] = []; }
/** * Get the parameters that will be used to update Bolt's registered Twig * globals. * * This is here as a transitory measure. * * @param bool $safe * * @return array */ private function setGlobals($safe) { /** @var \Twig_Environment $twig */ $twig = $safe ? $this->app['safe_twig'] : $this->app['twig']; /** @var \Bolt\Config $config */ $config = $this->app['config']; $configVal = $safe ? null : $config; /** @var \Bolt\Users $users */ $users = $this->app['users']; /** @var \Bolt\Configuration\ResourceManager $resources */ $resources = $this->app['resources']; $zone = null; /** @var RequestStack $requestStack */ $requestStack = $this->app['request_stack']; if ($request = $requestStack->getCurrentRequest()) { $zone = Zone::get($request); } // User calls can cause exceptions that block the exception handler try { /** @deprecated Deprecated since 3.0, to be removed in 4.0. */ $usersVal = $safe ? null : $users->getUsers(); $usersCur = $users->getCurrentUser(); } catch (\Exception $e) { $usersVal = null; $usersCur = null; } $twig->addGlobal('bolt_name', Bolt\Version::name()); $twig->addGlobal('bolt_version', Bolt\Version::VERSION); $twig->addGlobal('bolt_stable', Bolt\Version::isStable()); $twig->addGlobal('frontend', $zone === Zone::FRONTEND); $twig->addGlobal('backend', $zone === Zone::BACKEND); $twig->addGlobal('async', $zone === Zone::ASYNC); $twig->addGlobal('paths', $resources->getPaths()); $twig->addGlobal('theme', $config->get('theme')); $twig->addGlobal('user', $usersCur); $twig->addGlobal('users', $usersVal); $twig->addGlobal('config', $configVal); }