/**
  * Register this plates view provider with a Pimple container.
  *
  * @param \Pimple\Container $container
  */
 public function register(Container $container)
 {
     if (!isset($container->get('settings')['view'])) {
         throw new InvalidArgumentException('Template configuration not found');
     }
     $engine = new Plates($container->get('settings')['view'], $container->get('response'));
     $engine->loadExtension(new PlatesExtension($container->get('router'), $container->get('request')->getUri()));
     $container['view'] = $engine;
 }
 /**
  * @param ContainerInterface|Container $pimple A container instance
  *
  * @throws InvalidSettingsException
  *
  * @return Engine
  */
 public function register(Container $pimple)
 {
     $settings = $pimple->get('settings')['renderer'];
     if (is_null($settings)) {
         throw new InvalidSettingsException('Please configure the renderer settings with valid `template_path` and `template_ext` values.');
     }
     $engine = new PlatesRenderer($settings['template_path'], $settings['template_ext']);
     $engine->getEngine()->loadExtension(new PlatesSlimRouterExtension($pimple->get('router')));
     $pimple['renderer'] = $engine;
 }
Beispiel #3
0
 /**
  * Register Twig Service Provider
  *
  * @param Container $container
  */
 public function register(Container $container)
 {
     $config = $this->getConfig($container->get('settings'));
     $container['view'] = function (Container $container) use($config) {
         $engine = new Twig($config['template_path'], $config['twig']);
         // Add extensions
         $engine->addExtension(new TwigExtension($container->get('router'), $container->get('request')->getUri()));
         $engine->addExtension(new \Twig_Extension_Debug());
         return $engine;
     };
 }
 /**
  * Register this content negotiator provider with a Pimple container
  *
  * @param \Pimple\Container $container
  */
 public function register(Container $container)
 {
     $settings = $container->get('settings');
     // Overwrite default language based on setting.
     $this->default['language'] = $settings['lang']['default'];
     $container['negotiator'] = $this;
 }
 /**
  * Register this plates view provider with a Pimple container
  *
  * @param \Pimple\Container $container
  */
 public function register(Container $container)
 {
     $settings = $container->get('settings');
     if (!isset($settings['fs'])) {
         throw new InvalidArgumentException('Filesystem configuration not found');
     }
     $container['fs'] = new Flysystem($settings['fs']);
 }
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container|ContainerInterface $pimple A container instance
  *
  * @return PhpRenderer
  */
 public function register(Container $pimple)
 {
     $settings = $pimple->get('settings')['logger'];
     $logger = new \Monolog\Logger($settings['name']);
     $logger->pushProcessor(new \Monolog\Processor\UidProcessor());
     $logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['path'], \Monolog\Logger::DEBUG));
     $pimple['logger'] = $logger;
 }
 /**
  * Register this monolog provider with a Pimple container
  *
  * @param Container $container
  */
 public function register(Container $container)
 {
     $settings = $container->get('settings');
     if (!isset($settings['logger'])) {
         throw new InvalidArgumentException('Logger configuration not found');
     }
     $basename = isset($settings['basename']) ? $settings['basename'] : 'slim-app';
     $container['logger'] = new Monolog($basename, $settings['logger']);
 }
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container|ContainerInterface $pimple A container instance
  */
 public function register(Container $pimple)
 {
     $capsule = new Manager();
     $capsule->addConnection($pimple->get('settings')['database']);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     $pimple['db'] = function () use($capsule) {
         return $capsule;
     };
 }
 public function register(Container $c)
 {
     $c['logger'] = function ($c) {
         $settings = $c->get('settings')['logger'];
         $logger = new Logger($settings['name']);
         $logger->pushProcessor(new UidProcessor());
         $logger->pushHandler(new StreamHandler($settings['path'], Logger::DEBUG));
         return $logger;
     };
 }
Beispiel #10
0
 /**
  * Register log service provider
  *
  * @param Container $container
  */
 public function register(Container $container)
 {
     $config = $this->getConfig($container->get('settings'));
     $container['logger'] = function () use($config) {
         $logger = new Logger($config['name']);
         $logger->pushProcessor(new UidProcessor());
         $logger->pushHandler(new StreamHandler($config['path'], Logger::DEBUG));
         return $logger;
     };
 }
 public function register(Container $c)
 {
     $c['db'] = function ($c) {
         $settings = $c->get('settings')['pdo'];
         $queryFactory = new QueryFactory('mysql');
         $pdo = new PDOWrapper($settings['driver'] . ":host=" . $settings['host'] . ";dbname=" . $settings['dbname'], $settings['username'], $settings['password'], null, $queryFactory);
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
         $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         return $pdo;
     };
 }
 /**
  * Register this database provider with a Pimple container
  *
  * @param \Pimple\Container $container
  */
 public function register(Container $container)
 {
     $settings = $container->get('settings');
     if (!isset($settings['db'])) {
         throw new InvalidArgumentException('Database configuration not found');
     }
     $db = $settings['db'];
     if (!$db['dsn']) {
         $db['dsn'] = sprintf('%s:host=%s;dbname=%s;charset=%s', $db['driver'], $db['host'], $db['name'], $db['charset']);
     }
     $container['db'] = new Database($db['dsn'], $db['user'], $db['pass']);
 }
 public function register(Container $app)
 {
     $app['oauth.login_route'] = '_auth_service';
     $app['oauth.callback_route'] = '_auth_service_callback';
     $app['oauth.check_route'] = '_auth_service_check';
     $app['oauth.register_routes'] = true;
     $app['oauth.services'] = array();
     $app['oauth.http_client'] = function ($app) {
         return new CurlClient();
     };
     $app['oauth.factory'] = function ($app) {
         $factory = new ServiceFactory();
         $factory->setHttpClient($app['oauth.http_client']);
         return $factory;
     };
     $app['oauth.storage'] = function ($app) {
         return new SymfonySession($app['session']);
     };
     $app['oauth.url_generator'] = function ($app) {
         return $app['url_generator'];
     };
     $app['oauth.csrf_token'] = $app->protect(function ($intention) use($app) {
         if (!isset($app['form.csrf_provider'])) {
             return null;
         }
         $tokenManagerInterface = 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface';
         if ($app['form.csrf_provider'] instanceof $tokenManagerInterface) {
             return strval($app['form.csrf_provider']->getToken($intention));
         }
         return $app['form.csrf_provider']->generateCsrfToken($intention);
     });
     $app['oauth'] = function ($app) {
         return new OAuthServiceRegistry($app['oauth.factory'], $app['oauth.storage'], $app['oauth.url_generator'], $app['oauth.services'], array('callback_route' => $app['oauth.callback_route']));
     };
     $app['oauth.login_paths'] = function ($app) {
         $services = array_map('strtolower', array_keys($app['oauth.services']));
         $token = $app['oauth.csrf_token']('oauth');
         return array_map(function ($service) use($app, $token) {
             return $app['url_generator']->generate($app['oauth.login_route'], array('service' => $service, '_csrf_token' => $token));
         }, array_combine($services, $services));
     };
     $app['oauth.user_info_listener'] = function ($app) {
         return new UserInfoListener($app['oauth'], $app['oauth.services']);
     };
     $app['oauth.user_provider_listener'] = function ($app) {
         return new UserProviderListener();
     };
     $app['security.authentication_listener.factory.oauth'] = $app->protect(function ($name, $options) use($app) {
         if (!isset($app['security.authentication_listener.' . $name . '.oauth'])) {
             $app['security.authentication_listener.' . $name . '.oauth'] = $app['security.authentication_listener.oauth._proto']($name, $options);
         }
         if (!isset($app['security.authentication_provider.' . $name . '.oauth'])) {
             $app['security.authentication_provider.' . $name . '.oauth'] = $app['security.authentication_provider.oauth._proto']($name);
         }
         return array('security.authentication_provider.' . $name . '.oauth', 'security.authentication_listener.' . $name . '.oauth', null, 'pre_auth');
     });
     $app['security.authentication_listener.oauth._proto'] = $app->protect(function ($name, $options) use($app) {
         return function () use($app, $name, $options) {
             $options['login_route'] = $app['oauth.login_route'];
             $options['callback_route'] = $app['oauth.callback_route'];
             $options['check_route'] = $app['oauth.check_route'];
             if ($app['oauth.register_routes']) {
                 $app->match(isset($options['login_path']) ? $options['login_path'] : '/auth/{service}', function () {
                 })->bind($options['login_route']);
                 $app->get(isset($options['callback_path']) ? $options['callback_path'] : '/auth/{service}/callback', function () {
                 })->bind($options['callback_route']);
                 $app->get(isset($options['check_path']) ? $options['check_path'] : '/auth/{service}/check', function () {
                 })->bind($options['check_route']);
             }
             if (!isset($app['security.authentication.success_handler.' . $name . '.oauth'])) {
                 $app['security.authentication.success_handler.' . $name . '.oauth'] = $app['security.authentication.success_handler._proto']($name, $options);
             }
             if (!isset($app['security.authentication.failure_handler.' . $name . '.oauth'])) {
                 $app['security.authentication.failure_handler.' . $name . '.oauth'] = $app['security.authentication.failure_handler._proto']($name, $options);
             }
             return new OAuthAuthenticationListener($app['security.token_storage'], $app['security.authentication_manager'], $app['security.session_strategy'], $app['security.http_utils'], $name, $app['oauth'], $app['security.authentication.success_handler.' . $name . '.oauth'], $app['security.authentication.failure_handler.' . $name . '.oauth'], $options, $app['logger'], $app['dispatcher'], isset($options['with_csrf']) && $options['with_csrf'] && isset($app['form.csrf_provider']) ? $app['form.csrf_provider'] : null);
         };
     });
     $app['security.authentication_provider.oauth._proto'] = $app->protect(function ($name) use($app) {
         return function () use($app, $name) {
             return new OAuthAuthenticationProvider($app['security.user_provider.' . $name], $app['security.user_checker'], $name, $app['dispatcher']);
         };
     });
 }
Beispiel #14
0
 function __construct(Container $container, $session)
 {
     $this->container = $container;
     $this->session = $container->get($session);
 }