Example #1
0
 public function format($date, $format = 'medium', $timezone = null)
 {
     $formats = ['none' => DateManager::NONE, 'short' => DateManager::SHORT, 'medium' => DateManager::MEDIUM, 'long' => DateManager::LONG, 'full' => DateManager::FULL, 'interval' => DateManager::INTERVAL];
     return $this->manager->format($date, isset($formats[$format]) ? $formats[$format] : $format, $timezone, $format);
 }
 /**
  * {@inheritdoc}
  */
 public function boot(Application $app)
 {
     if (!(isset($this['config']) ? $this['config']['app.debug'] : true)) {
         $app['events']->addSubscriber(new ExceptionListener('Pagekit\\System\\Exception\\ExceptionController::showAction'));
     }
     $app['events']->addSubscriber(new AccessListener());
     $app['events']->addSubscriber(new AdminMenuListener());
     $app['events']->addSubscriber(new AliasListener());
     $app['events']->addSubscriber(new AuthorizationListener());
     $app['events']->addSubscriber(new CanonicalListener());
     $app['events']->addSubscriber(new FrontpageListener());
     $app['events']->addSubscriber(new LocaleListener());
     $app['events']->addSubscriber(new LoginAttemptListener());
     $app['events']->addSubscriber(new MaintenanceListener());
     $app['events']->addSubscriber(new MenuListener());
     $app['events']->addSubscriber(new MigrationListener());
     $app['events']->addSubscriber(new ResponseListener());
     $app['events']->addSubscriber(new SystemListener());
     $app['events']->addSubscriber(new UserListener());
     $app['events']->addSubscriber(new WidgetListener());
     $app['events']->addSubscriber(new ThemeListener());
     $app['events']->addSubscriber(new ThemeWidgetListener());
     parent::boot($app);
     $this->mergeOptions();
     $app['system'] = $this;
     $app['menus'] = function () {
         return new MenuProvider();
     };
     $app['user'] = function ($app) {
         if (!($user = $app['auth']->getUser())) {
             $user = new UserEntity();
             $roles = $app['users']->getRoleRepository()->where(['id' => RoleInterface::ROLE_ANONYMOUS])->get();
             $user->setRoles($roles);
         }
         return $user;
     };
     $app['users'] = function () {
         return new UserProvider();
     };
     $app['permissions'] = function ($app) {
         return $app['events']->dispatch('system.permission', new PermissionEvent())->getPermissions();
     };
     $app['content'] = function () {
         return new ContentHelper();
     };
     $app['languages'] = function () {
         return new LanguageHelper();
     };
     $app['countries'] = function () {
         return new CountryHelper();
     };
     $app['system.info'] = function () {
         return new SystemInfoHelper();
     };
     $app['oauth'] = function () {
         return new OAuthHelper();
     };
     $app['dates'] = function ($app) {
         $manager = new DateHelper();
         $manager->setTimezone($app['option']->get('system:app.timezone', 'UTC'));
         $manager->setFormats([DateHelper::NONE => '', DateHelper::FULL => __('DATE_FULL'), DateHelper::LONG => __('DATE_LONG'), DateHelper::MEDIUM => __('DATE_MEDIUM'), DateHelper::SHORT => __('DATE_SHORT'), DateHelper::INTERVAL => __('DATE_INTERVAL')]);
         return $manager;
     };
     $app->extend('mailer', function ($mailer, $app) {
         $address = $app['config']->get('mail.from.address');
         $name = $app['config']->get('mail.from.name');
         $mailer->registerPlugin(new ImpersonatePlugin($address, $name));
         return $mailer;
     });
     if (isset($app['profiler'])) {
         $app->on('system.init', function () use($app) {
             $app['profiler']->add(new SystemDataCollector($app['system.info']), 'extension://system/views/profiler/toolbar/system.php', 'extension://system/views/profiler/panel/system.php', 50);
             $app['profiler']->add(new UserDataCollector($app['auth']), 'extension://system/views/profiler/toolbar/user.php', null, -20);
         });
     }
 }