public function register(Application $app) { $app->setParameter('swiftmailer', ['initialized' => false, 'use_spool' => true, 'options' => []]); $app->singleton('mailer', function () use($app) { $app->setParameter('swiftmailer.initialized', true); /** @var \Swift_Transport $transport */ $transport = $app->getParameter('swiftmailer.use_spool') ? $app->make('swiftmailer.transport_spool') : $app->make('swiftmailer.transport'); $mailer = new \Swift_Mailer($transport); if ($address = $app->getParameter('swiftmailer.options.delivery_address')) { $mailer->registerPlugin(new \Swift_Plugins_RedirectingPlugin($address)); } return $mailer; }); $app->singleton('swiftmailer.transport', function () use($app) { $options = array_merge(['transport' => 'smtp', 'host' => 'localhost', 'port' => false, 'timeout' => 30, 'encryption' => null, 'username' => null, 'password' => null, 'delivery_address' => null], $app->getParameter('swiftmailer.options', [])); switch ($options['transport']) { case 'gmail': case 'smtp': if ($options['transport'] == 'gmail') { $options['encryption'] = 'ssl'; $options['host'] = 'smtp.gmail.com'; } if (false === $options['port']) { $options['port'] = 'ssl' === $options['encryption'] ? 465 : 25; } $transport = \Swift_SmtpTransport::newInstance($options['host'], $options['port'], $options['encryption']); $transport->setUsername($options['username']); $transport->setPassword($options['password']); $transport->setTimeout($options['timeout']); return $transport; case 'sendmail': return \Swift_SendmailTransport::newInstance(); case 'mail': return \Swift_MailTransport::newInstance(); case 'null': return \Swift_NullTransport::newInstance(); } }); $app->singleton('swiftmailer.transport_spool', function () use($app) { $type = $app->getParameter('swiftmailer.options.spool_type', 'memory'); if ($type == 'memory') { $spool = new \Swift_MemorySpool(); } elseif ($type == 'file') { $spool = new \Swift_FileSpool($app->getParameter('swiftmailer.options.spool_path')); } else { throw new \LogicException(sprintf('Spool type "%s" not found', $type)); } return new \Swift_SpoolTransport($spool); }); }
public function register(Application $app) { $app->setParameter('cache', ['namespace' => null, 'type' => 'array']); $app->singleton('cache', function () use($app) { $cache = null; $type = $app->getParameter('cache.type', 'array'); if ($type == 'array') { $cache = new ArrayCache(); } elseif ($type == 'apc') { $cache = new ApcCache(); } elseif ($type == 'xcache') { $cache = new XcacheCache(); } elseif ($type == 'memcache') { $cache = new MemcacheCache(); $memcache = new \Memcache(); $memcache->addserver($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211)); $cache->setMemcache($memcache); } elseif ($type == 'memcached') { $cache = new MemcachedCache(); $memcached = new \Memcached(); $memcached->addServer($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211)); $cache->setMemcached($memcached); } $cache->setNamespace($app->getParameter('cache.namespace')); return $cache; }); }
public function register(Application $app) { $app->singleton('session', function () use($app) { /** @var SessionHandler $handler */ $handler = null; $container = $app->getContainer(); if ($container->exists('session.handler')) { $handler = $container->make('session.handler'); } return new Session(new NativeSessionStorage($app->getParameter('session.options', []), $handler)); }); }
public function register(Application $app) { $app->singleton('twig', function () use($app) { $options = array_replace(['charset' => $app->getParameter('charset'), 'debug' => $app->getParameter('debug'), 'strict_variables' => $app->getParameter('debug')], $app->getParameter('twig.options', [])); /** @var Twig_LoaderInterface $loader */ $loader = $app->make('twig.loader'); $twig = new \Twig_Environment($loader, $options); $twig->addGlobal('app', $app); return $twig; }); $app->singleton('twig.loader', function () use($app) { return new \Twig_Loader_Filesystem($app->getParameter('twig.path')); }); }
public function register(Application $app) { $app->setParameter('db.options_default', ['dsn' => '', 'username' => 'root', 'password' => null, 'options' => []]); $app->singleton('db', function () use($app) { $manager = new Manager(); $optionsDefault = $app->getParameter('db.options_default'); $dbsOptions = $app->getParameter('dbs.options'); if (!$dbsOptions) { $dbsOptions['default'] = $app->getParameter('db.options', []); } $defaultSet = false; foreach ($dbsOptions as $name => &$options) { $options = array_replace($optionsDefault, $options); $manager->addConnection($options, $name); if (!$defaultSet) { $manager->setDefaultConnectionName($defaultSet); $defaultSet = true; } } return $manager; }); }
public function register(Application $app) { $app->singleton('router', 'Routing\\Router'); }