/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * @param Application $app */ public function register(Application $app) { parent::register($app); $app['cache'] = $app->share(function ($app) { $config = $app['config']; if (!array_key_exists('cache.driver', $config)) { return new ArrayCache(); } switch ($config['cache.driver']) { case 'array': return new ArrayCache(); case 'redis': $cache = new RedisCache(); if (isset($config['cache.redis'])) { $redis = new \Redis(); $redis->connect($config['cache.redis']['host'], $config['cache.redis']['port']); $cache->setRedis($redis); } else { $cache->setRedis($app['redis']); } return $cache; case 'xcache': return new XcacheCache(); default: throw new \RuntimeException('Unknown cache driver: ' . $config['cache.driver']); } }); }
public function register(Application $app) { parent::register($app); $app[MetadataFactory::class] = $app->share(function () { return new MetadataFactory(new AnnotationDriver(new AnnotationReader())); }); }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * @param Application $app */ public function register(Application $app) { parent::register($app); // override this in config to allow a different user entity class to be used. if (isset($app['config']['user.entity'])) { $app['user.entity'] = $app['config']['user.entity']; } else { $app['user.entity'] = User::class; } // setup security for cli commands if (php_sapi_name() === 'cli') { $app['console.configure'] = $app->extend('console.configure', function ($callbacks) { $callbacks[] = function (Command $command) { if ($command instanceof BaseCommand) { $command->addOption('user', 'U', InputOption::VALUE_REQUIRED, 'User ID to run command as'); } }; return $callbacks; }); $app['console.prerun'] = $app->extend('console.prerun', function ($callbacks) { $callbacks[] = function (Command $command, InputInterface $input, OutputInterface $output) { if ($command instanceof BaseCommand && $input->getOption('user')) { $app = $command->getSilexApplication(); /** @var EntityManagerInterface $em */ $em = $app['orm.em']; $app['user'] = $em->find($app['user.entity'], $input->getOption('user')); } }; return $callbacks; }); } $app['security.firewalls'] = []; $app['security.access_rules'] = []; $app->register(new SecurityServiceProvider()); }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * @param Application $app */ public function register(Application $app) { parent::register($app); $app->register(new \Silex\Provider\DoctrineServiceProvider(), ['db.options' => $app['config']['db.options']]); $app->register(new DoctrineOrmServiceProvider(), $app['config']['orm.options']); if (getenv('MIGRATION_COMMANDS')) { $app->register(new MigrationServiceProvider(), ['db.migrations.path' => $app['config']['migrations.directory']]); } $app['orm.em'] = $app->extend('orm.em', function (EntityManagerInterface $em) use($app) { if (file_exists(APP_PATH . '/vendor/apitude/apitude/src/Annotations/APIAnnotations.php')) { AnnotationRegistry::registerFile(APP_PATH . '/vendor/apitude/apitude/src/Annotations/APIAnnotations.php'); } /** @var Configuration $config */ $config = $em->getConfiguration(); $config->setMetadataCacheImpl($app['cache']); $config->addCustomHydrationMode('simple', SimpleHydrator::class); /** @var MappingDriverChain $driver */ $driver = $config->getMetadataDriverImpl(); // gedmo initialization $reader = new AnnotationReader(); $cache = new CachedReader($reader, $app['cache']); DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driver, $cache); return $em; }); }
public function register(Application $app) { parent::register($app); $app['qless.client'] = $app->share(function () use($app) { $config = $app['config']; return new Client($config['qless']['host'], $config['qless']['port']); }); }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * @param Application $app */ public function register(Application $app) { parent::register($app); $app->get('/people', PersonController::class . '::readList'); $app->get('/people({id})', PersonController::class . '::read')->assert('id', '\\d+'); $app->post('/people', PersonController::class . '::create'); $app->patch('/people({id})', PersonController::class . '::update')->assert('id', '\\d+'); $app->delete('/people({id})', PersonController::class . '::delete')->assert('id', '\\d+'); $app->get('/authpeople', PersonController::class . '::readList'); }
public function register(Application $app) { parent::register($app); $adapters = ['local__DIR__' => ['adapter' => Local::class, 'args' => [__DIR__]]]; $config = $app['config']['files']; if (isset($config['filesystems']['s3'])) { $client = new S3Client(['credentials' => ['key' => $config['credentials']['AWS_ACCESS_KEY_ID'], 'secret' => $config['credentials']['AWS_SECRET_ACCESS_KEY']], 'region' => $config['region'], 'version' => $config['version']]); $adapters['s3'] = ['adapter' => AwsS3Adapter::class, 'args' => [$client, $config['bucket']]]; } $app->register(new FlysystemServiceProvider(), ['flysystem.filesystems' => $adapters]); }
public function register(Application $app) { parent::register($app); $config = $app['config']; $app['handlebars'] = $app->share(function ($app) use($config) { $templatePathConfigPath = 'template.handlebars.path'; if (!Arr::path($config, $templatePathConfigPath)) { Arr::setPath($config, $templatePathConfigPath, APP_PATH . '/templates'); } return new Handlebars(['loader' => new FilesystemLoader(Arr::path($config, $templatePathConfigPath), ['extension' => '.hbs']), 'partials_loader' => new FilesystemLoader(Arr::path($config, $templatePathConfigPath), ['prefix' => '_'])]); }); $app['config'] = $config; }
public function register(Application $app) { parent::register($app); $config = $app['config']; if (!isset($config['email'])) { $config['email'] = ['sender' => SimpleSender::class]; } if (!array_key_exists('mandrill_api_key', $config['email'])) { if (getenv('MANDRILL_API_KEY')) { $config['email']['mandrill_api_key'] = getenv('MANDRILL_API_KEY'); } } if (array_key_exists('mailgun_api_key', $config['email'])) { $app['mailgun'] = $app->share(function ($app) use($config) { return new Mailgun($config['email']['mailgun_api_key'], new HttpClient()); }); } $app['config'] = $config; }
public function boot(Application $app) { parent::boot($app); $app->mount('/oauth', new OauthControllerProvider()); }