/** * Drop and recreate the test database. * * @return void */ public function clearDatabase() { $this->getGlobalConnection()->getSchemaManager()->dropAndCreateDatabase($this->getApplication()['vbee.parameter.database']); // TODO: move this into a provider $schemaManager = new SchemaManager($this->getConnection()); $schemaManager->update(); }
/** * Constructor. * * @param array $values */ public function __construct(array $values = array()) { parent::__construct(); $app = $this; // default values $this['debug'] = true; $this['vbee.parameter.database'] = 'vbee_site'; // overwrite container value for special setup foreach ($values as $key => $value) { $this[$key] = $value; } $this->register(new FormServiceProvider()); $this->register(new ServiceControllerServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new TranslationServiceProvider()); $this->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../views']); $this->register(new DoctrineServiceProvider(), ['dbs.options' => ['application' => ['dbname' => $this['vbee.parameter.database'], 'host' => 'localhost', 'user' => 'root', 'password' => 'azerty'], 'global' => ['host' => 'localhost', 'user' => 'root', 'password' => 'azerty']]]); // Mappers $this['vbee.mapping.provider'] = $this->share(function () { return new MappingProvider(); }); // Hydrators $this['vbee.hydrator'] = $this->share(function () { return new Hydrator($this['vbee.mapping.provider']); }); // Repositories $this['vbee.repository.person'] = $this->share(function ($app) { return new PersonRepository($app['dbs']['application'], $this['vbee.hydrator'], $this['vbee.mapping.provider']); }); $this['vbee.repository.organization'] = $this->share(function ($app) { return new OrganizationRepository($app['dbs']['application'], $this['vbee.hydrator'], $this['vbee.mapping.provider']); }); $this['vbee.repository.experience'] = $this->share(function ($app) { return new ExperienceRepository($app['dbs']['application'], $this['vbee.hydrator'], $this['vbee.mapping.provider']); }); $this['vbee.repository.mission'] = $this->share(function ($app) { return new MissionRepository($app['dbs']['application']); }); $this['vbee.repository.skill'] = $this->share(function ($app) { return new SkillRepository($app['dbs']['application']); }); $this['vbee.repository.study'] = $this->share(function ($app) { return new StudyRepository($app['dbs']['application'], $this['vbee.hydrator'], $this['vbee.mapping.provider']); }); // Managers $this['vbee.manager.person'] = $this->share(function ($app) { return new PersonManager($app['vbee.repository.person']); }); $this['vbee.manager.organization'] = $this->share(function ($app) { return new OrganizationManager($app['vbee.repository.organization']); }); $this['vbee.manager.study'] = $this->share(function ($app) { return new StudyManager($app['vbee.repository.study']); }); $this['vbee.manager.experience'] = $this->share(function ($app) { return new ExperienceManager($app['vbee.repository.experience']); }); // Controllers $this['vbee.controller.person'] = $this->share(function () use($app) { return new PersonController($app['vbee.manager.person']); }); $this['vbee.controller.organization'] = $this->share(function () use($app) { return new OrganizationController($app['vbee.manager.organization']); }); $this['vbee.controller.study'] = $this->share(function () use($app) { return new StudyController($app['vbee.manager.study'], $this['vbee.manager.person']); }); $this['vbee.controller.experience'] = $this->share(function () use($app) { return new ExperienceController($app['vbee.manager.experience'], $this['vbee.manager.person']); }); // Form Type $this['form.types'] = $app->share($app->extend('form.types', function ($types, $app) { return array_merge($types, [new OrganizationChoiceType($this['vbee.repository.organization']), new PersonType(), new OrganizationType(), new StudyType(), new ExperienceType()]); })); /** @var \Doctrine\DBAL\Connection $globalConnection */ $globalConnection = $app['dbs']['global']; $databases = $globalConnection->getSchemaManager()->listDatabases(); if (!in_array($this['vbee.parameter.database'], $databases)) { $globalConnection->getSchemaManager()->createDatabase($this['vbee.parameter.database']); } // TODO: move this into a provider $schemaManager = new SchemaManager($app['dbs']['application']); $schemaManager->update(); $this->mount('/admin', new AdminControllerProvider()); $this->mount('/', new HomeControllerProvider()); }