public function testBootWithTwig()
 {
     $this->app->register($this->provider);
     $this->app->register(new TwigServiceProvider());
     $this->app->boot();
     $this->assertInstanceOf('CalendR\\Extension\\Twig\\CalendRExtension', $this->app['twig']->getExtension('calendr'));
 }
 /**
  * Ensures the service provider registers the correct services.
  */
 public function testRegisteredServices()
 {
     $firewall = 'http-auth';
     $authenticationListenerServices = ['security.authentication_provider.' . $firewall . '.hmac', 'security.authentication_listener.' . $firewall . '.hmac', 'security.entry_point.' . $firewall . '.hmac', 'pre_auth'];
     $keyLoader = $this->getMock(KeyLoaderInterface::class);
     $app = new Application();
     $app->register(new SecurityServiceProvider());
     $app->register(new HmacSecurityProvider($keyLoader));
     $app['security.firewalls'] = [$firewall => ['pattern' => '^.*$', 'hmac' => true]];
     $app->boot();
     $this->assertArrayHasKey('security.authentication_listener.factory.hmac', $app);
     $this->assertArrayHasKey('security.hmac.response_listener', $app);
     $this->assertArrayHasKey('security.authentication_provider.hmac._proto', $app);
     $this->assertArrayHasKey('security.authentication_listener.hmac._proto', $app);
     $this->assertArrayHasKey('security.entry_point.hmac._proto', $app);
     $this->assertInstanceOf(HmacResponseListener::class, $app['security.hmac.response_listener']);
     $factoryResponse = $app['security.authentication_listener.factory.hmac']($firewall, []);
     $this->assertEquals($authenticationListenerServices, $factoryResponse);
     $this->assertArrayHasKey('security.authentication_provider.' . $firewall . '.hmac', $app);
     $this->assertInstanceOf(HmacAuthenticationProvider::class, $app['security.authentication_provider.' . $firewall . '.hmac']);
     $this->assertArrayHasKey('security.authentication_listener.' . $firewall . '.hmac', $app);
     $this->assertInstanceOf(HmacAuthenticationListener::class, $app['security.authentication_listener.' . $firewall . '.hmac']);
     $this->assertArrayHasKey('security.entry_point.' . $firewall . '.hmac', $app);
     $this->assertInstanceOf(HmacAuthenticationEntryPoint::class, $app['security.entry_point.' . $firewall . '.hmac']);
 }
 public function testInjectionWithApiEndPoint()
 {
     $injectionData = array('ionicPush.appId' => 'test ID', 'ionicPush.appSecretId' => 'test api ID', 'ionicPush.endPoint' => 'test end point');
     $this->app->register(new IonicPushServiceProvider(), $injectionData);
     $this->assertNotEmpty($this->app['ionicPush.processor']);
     $this->assertEquals($this->app['ionicPush.processor']->getPushEndPoint(), $injectionData['ionicPush.endPoint']);
 }
 private function createApplication()
 {
     $app = new Application(array('debug' => true));
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new Provider\RestServiceProvider($app));
     return $app;
 }
 /**
  * Returns configured {@link \Doctrine\DBAL\Connection}.
  *
  * @return Connection
  */
 protected function getDatabaseConnection()
 {
     $app = new Application();
     $app->register(new ConfigServiceProvider(__DIR__ . '/../../../../config/config.php'));
     $app->register(new DoctrineServiceProvider(), ['db.options' => ['driver' => 'pdo_pgsql', 'host' => $app['database']['host'], 'dbname' => $app['database']['schema'], 'user' => $app['database']['username'], 'password' => $app['database']['password'], 'port' => $app['database']['port']]]);
     return $app['db'];
 }
 private function getSilexApplication(GearmanClient $gearmanClient)
 {
     $app = new Application(['debug' => true]);
     $app->register(new InjectorServiceProvider(['G\\Gearman\\Client' => 'gearmanClient', 'G\\Gearman\\Tasks' => 'gearmanTasks']));
     $app->register(new GearmanServiceProvider($gearmanClient));
     return $app;
 }
 public function register(Application $app)
 {
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->register(new \Silex\Provider\SecurityServiceProvider());
     $app->register(new \Silex\Provider\RememberMeServiceProvider());
     $app['session.storage.options'] = ['name' => 'SESSION', 'cookie_httponly' => true];
     $app['dispatcher']->addListener(KernelEvents::REQUEST, function (GetResponseEvent $event) use($app) {
         $this->handleRequest($event, $app);
     }, Application::EARLY_EVENT - 400);
     $app['security.firewalls'] = ['general' => ['anonymous' => true, 'pattern' => '^/', 'form' => ['login_path' => '/', 'check_path' => '/_login_check', 'default_target_path' => '/user/files/', 'always_use_default_target_path' => false], 'logout' => ['logout_path' => '/_logout', 'target_url' => '/'], 'switch_user' => ['parameter' => '_switch_user', 'role' => 'ROLE_ALLOWED_TO_SWITCH'], 'remember_me' => ['key' => REMEMBER_ME_KEY, 'always_remember_me' => true], 'users' => $app->share(function () {
         return new UserProvider();
     })]];
     $app['security.role_hierarchy'] = ['ROLE_ADMIN' => ['ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH']];
     $nonDefaultLocales = $app['locales'];
     $defaultLocaleKey = array_search($app['default_locale'], $nonDefaultLocales);
     if ($defaultLocaleKey !== false) {
         unset($nonDefaultLocales[$defaultLocaleKey]);
     }
     if (count($nonDefaultLocales)) {
         $localesPrefix = '((' . implode('|', $nonDefaultLocales) . ')/)?';
     } else {
         $localesPrefix = '';
     }
     $app['security.access_rules'] = [['^/' . $localesPrefix . '(ajax/)?administration', 'ROLE_ADMIN'], ['^/' . $localesPrefix . '(ajax/)?user', 'ROLE_USER']];
     $app['security.authentication.failure_handler.general'] = $app->share(function () {
         return new AuthenticationHandler();
     });
 }
 public function addPimpleResources()
 {
     $this->silex['paths'] = $this->silex->share(function () {
         return new Paths();
     });
     $this->silex['application-env'] = getenv('APPLICATION_ENV');
     $this->silex['debug'] = 'development' === $this->silex['application-env'] ? true : false;
     $this->silex->register(new MonologServiceProvider(), ['monolog.logfile' => $this->silex['paths']->getAppRoot() . '/logs/' . $this->silex['application-env'] . '.log', 'monolog.level' => Logger::WARNING]);
     $this->silex['view'] = function () {
         $view = new View();
         $view->registerHelper('inputtext', '\\Dewdrop\\View\\Helper\\BootstrapInputText')->registerHelper('select', '\\Dewdrop\\View\\Helper\\BootstrapSelect')->registerHelper('textarea', '\\Dewdrop\\View\\Helper\\BootstrapTextarea');
         return $view;
     };
     $this->silex['admin'] = $this->silex->share(function () {
         $admin = new SilexAdmin($this->silex);
         return $admin;
     });
     $this->silex['config'] = $this->silex->share(function () {
         $config = new Config();
         if (!$config->has($this->silex['application-env'])) {
             return $config->get('development');
         }
         return $config->get($this->silex['application-env']);
     });
     $this->silex['db'] = $this->silex->share(function () {
         $config = $this->silex['config'];
         $pdo = new PDO('pgsql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'], $config['db']['username'], $config['db']['password']);
         $adapter = new DbAdapter();
         new Pgsql($adapter, $pdo);
         return $adapter;
     });
 }
 public function testProviderShouldAddMissingNameParam()
 {
     $this->app->register(new PhpTemplatingServiceProvider());
     $this->app['templating.paths'] = __DIR__ . '/templates';
     $rendered = $this->app['templating']->render('example.php', array('planet' => 'World'));
     $this->assertEquals($rendered, 'Hello, World!');
 }
Example #10
0
 protected function setUp()
 {
     $this->app = new Application();
     $this->app->register(new PhpDiServiceProvider());
     $this->app['debug'] = true;
     $this->app['exception_handler']->disable();
 }
 /**
  * @test
  */
 public function registerWithTwig()
 {
     $app = new Application();
     $app->register(new TwigServiceProvider());
     $app->register(new SlugifyServiceProvider());
     $this->assertTrue($app['twig']->hasExtension('slugify_extension'));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->app = new Application();
     $this->app->register(new ResolverServiceProvider());
     $this->app->register(new ServiceProvider());
 }
 private function bootstrapApp()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new TwigServiceProvider(), array('twig.templates' => array('main' => '{{ knp_menu_render("my_menu", {"compressed": true}, renderer) }}')));
     $app->register(new KnpMenuServiceProvider(), array('knp_menu.menus' => array('my_menu' => 'test.menu.my')));
     $app->register(new UrlGeneratorServiceProvider());
     $app['test.menu.my'] = function (Application $app) {
         /** @var $factory \Knp\Menu\FactoryInterface */
         $factory = $app['knp_menu.factory'];
         $root = $factory->createItem('root', array('childrenAttributes' => array('class' => 'nav')));
         $root->addChild('home', array('route' => 'homepage', 'label' => 'Home'));
         $root->addChild('KnpLabs', array('uri' => 'http://knplabs.com', 'extras' => array('routes' => 'other_route')));
         return $root;
     };
     $app['test.voter'] = $app->share(function (Application $app) {
         $voter = new RouteVoter();
         $voter->setRequest($app['request']);
         return $voter;
     });
     $app['knp_menu.matcher.configure'] = $app->protect(function (Matcher $matcher) use($app) {
         $matcher->addVoter($app['test.voter']);
     });
     $app->get('/twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('homepage');
     $app->get('/other-twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('other_route');
     $app->get('/list', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'list'));
     })->bind('list');
     return $app;
 }
 public function createApplication()
 {
     $app = new Application();
     $app->register(new RedirectRouteProvider());
     $app->register(new RoutingServiceProvider());
     return $app;
 }
 public function testFormWithoutCsrf()
 {
     $app = new Application();
     $app->register(new FormServiceProvider());
     $app->register(new TwigServiceProvider());
     $this->assertInstanceOf('Twig_Environment', $app['twig']);
 }
 public function registerServices(Application $app)
 {
     $app->register(new DoctrineServiceProvider());
     $app->register(new MigrationServiceProvider(array('migration.path' => $this->migrationPath)));
     $app->register(new ConsoleServiceProvider(), array('console.name' => $this->consoleName, 'console.version' => $this->consoleVersion, 'console.project_directory' => __DIR__ . '/'));
     return $app;
 }
Example #17
0
 public function register(Application $app)
 {
     if (!isset($app['profiler'])) {
         $app->register(new Silex\Provider\WebProfilerServiceProvider(), ['profiler.cache_dir' => $app['resources']->getPath('cache/profiler'), 'web_profiler.debug_toolbar.enable' => false]);
     }
     $app->register(new DebugToolbarEnabler());
     $app['data_collector.templates'] = $app->share($app->extend('data_collector.templates', function ($templates) {
         // Set the 'bolt' toolbar item as the first one, and overriding the 'Symfony' one.
         array_unshift($templates, ['bolt', '@BoltProfiler/bolt.html.twig']);
         $templates[] = ['db', '@BoltProfiler/db.html.twig'];
         // Hackishly replace the template for the first toolbar item with our own.
         $templates[1][1] = '@BoltProfiler/config.html.twig';
         return $templates;
     }));
     $app['data_collectors'] = $app->share($app->extend('data_collectors', function ($collectors, $app) {
         // @codingStandardsIgnoreStart
         $collectors['bolt'] = $app->share(function ($app) {
             return new BoltDataCollector($app);
         });
         $collectors['db'] = $app->share(function ($app) {
             return new DatabaseDataCollector($app['db.logger']);
         });
         // @codingStandardsIgnoreEnd
         return $collectors;
     }));
     $app['twig.loader.bolt_filesystem'] = $app->share($app->extend('twig.loader.bolt_filesystem', function ($filesystem) {
         $filesystem->addPath('bolt://app/view/toolbar', 'BoltProfiler');
         return $filesystem;
     }));
     $app['db.logger'] = $app->share(function () {
         return new DebugStack();
     });
 }
Example #18
0
 /**
  * @param Application $app
  */
 private static function registerProviders(Application $app)
 {
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new DoctrineServiceProvider());
     $app->register(new SerializerServiceProvider());
     $app->register(new EntityManagerServiceProvider());
     $app->register(new ConfigServiceProvider(\APP_PATH . '/config/config.json'));
 }
Example #19
0
 /**
  * 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)
 {
     // if console register console providers
     if (php_sapi_name() === 'cli') {
         $app->register(new ConsoleProvider());
     }
     $app->register(new DoctrineOrmManagerRegistryProvider());
 }
 /**
  * Setup the application.
  *
  * @return array
  **/
 public function setUp()
 {
     $this->pdo = new \PDO('sqlite::memory:?cache=shared');
     $this->pdo->exec(file_get_contents(__DIR__ . '/fixtures/books.sql'));
     $this->app = new Application();
     $this->app->register(new CapsuleServiceProvider(), ['capsule.connection' => ['driver' => 'sqlite', 'database' => ':memory:?cache=shared', 'prefix' => '']]);
     $this->app['capsule'];
 }
 /**
  * @return Application
  */
 protected function getPreparedApp()
 {
     $app = new Application();
     $app->register(new LocaleServiceProvider());
     $app->register(new TranslationServiceProvider());
     $app['translator.domains'] = array('messages' => array('en' => array('key1' => 'The translation', 'key_only_english' => 'Foo', 'key2' => 'One apple|%count% apples', 'test' => array('key' => 'It works')), 'de' => array('key1' => 'The german translation', 'key2' => 'One german apple|%count% german apples', 'test' => array('key' => 'It works in german'))));
     return $app;
 }
 public function testRegisterAndPersistent()
 {
     $app = new Application();
     $app->register(new PHPRedisServiceProvider(), array('redis.engine' => $this->buildMock(), 'redis.persistent' => true));
     $app->register(new RateLimitServiceProvider());
     $bucket = $app['ratelimit']->createUserBucket('testguy');
     $this->assertInstanceOf('bandwidthThrottle\\tokenBucket\\TokenBucket', $bucket);
 }
 public function testServiceCreatesResource()
 {
     $app = new Application();
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new RestApplicationServiceProvider());
     $resource = $app['rest']->resource('/items');
     $this->assertInstanceOf('Mach\\Silex\\Rest\\Resource', $resource);
 }
 /**
  * Registra os provedores de serviço necessários ao funcionamento do framework.
  *
  * @param Application $app
  */
 private function registerRequiredProviders(Application $app)
 {
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new DirectServiceProvider());
     $app->register(new TwigServiceProvider());
     $app->register(new SessionServiceProvider());
     $app->register(new UrlGeneratorServiceProvider());
 }
Example #25
0
function create_application($debug = false)
{
    $app = new Application(compact('debug'));
    $app->register(new TwigServiceProvider());
    $app->register(new JunoServiceProvider());
    $app->register(new BernardServiceProvider());
    return $app;
}
 protected function getMinimalApp()
 {
     $app = new Application();
     $app->register(new Provider\SecurityServiceProvider(), array('security.firewalls' => array('dummy-firewall' => array('form' => array()))));
     $app->register(new Provider\DoctrineServiceProvider());
     $app->register(new UserServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'memory' => true)));
     return $app;
 }
 /**
  * Bootstrap
  */
 public function setUp()
 {
     parent::setUp();
     $app = new Application();
     $app->register(new YamlConfigServiceProvider(__DIR__ . '/../Resources/di.yml'));
     $app->register(new DiServiceProvider($app['config']['services']));
     $this->app = $app;
 }
 /**
  * @param array $options
  * @return AnnotationService
  */
 protected function registerAnnotations($options = array())
 {
     if (!isset($options['annot.controllers'])) {
         $options['annot.controllerDir'] = self::$CONTROLLER_DIR;
     }
     $this->app->register(new AnnotationServiceProvider(), $options);
     return $this->app['annot'];
 }
Example #29
0
 public function setUp()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../resources/templates']);
     $app->register(new BreadcrumbServiceProvider());
     $this->app = $app;
 }
Example #30
0
 public function setUp()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new TwigServiceProvider(), ['twig.path' => getcwd() . '/resources/templates']);
     $app->register(new MenuServiceProvider(), ['menu.config' => getcwd() . '/resources/yaml/menus.yml']);
     $this->app = $app;
 }