Skip to content
Snippets Groups Projects
Commit bc5d37af authored by elise's avatar elise
Browse files

add doctrine to slim dependencies

parent 8a34cc31
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,11 @@ use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Tools\Setup;
return function (ContainerBuilder $containerBuilder) {
$containerBuilder->addDefinitions([
......@@ -24,5 +29,32 @@ return function (ContainerBuilder $containerBuilder) {
return $logger;
},
EntityManager::class => function (ContainerInterface $container): EntityManager {
$settings = $container->get('settings');
$config = Setup::createAnnotationMetadataConfiguration(
$settings['doctrine']['metadata_dirs'],
$settings['doctrine']['dev_mode']
);
$config->setMetadataDriverImpl(
new AnnotationDriver(
new AnnotationReader,
$settings['doctrine']['metadata_dirs']
)
);
$config->setMetadataCacheImpl(
new FilesystemCache(
$settings['doctrine']['cache_dir']
)
);
return EntityManager::create(
$settings['doctrine']['connection'],
$config
);
},
]);
};
......@@ -14,6 +14,27 @@ return function (ContainerBuilder $containerBuilder) {
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log',
'level' => Logger::DEBUG,
],
'doctrine' => [
// if true, metadata caching is forcefully disabled
'dev_mode' => true,
// path where the compiled metadata info will be cached
// make sure the path exists and it is writable
'cache_dir' => __DIR__ . '/../var/doctrine',
// you should add any other path containing annotated entity classes
'metadata_dirs' => [__DIR__ . '/../src/Domain'],
'connection' => [
'driver' => 'pdo_mysql',
'host' => 'db',
'port' => 3306,
'dbname' => 'covid',
'user' => 'root',
'password' => 'root',
//'charset' => 'utf-8'
]
]
],
]);
};
<?php
// cli-config.php
require_once "./config/config-doctrine.php";
$entityManager = GetEntityManager();
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
\ No newline at end of file
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
use DI\ContainerBuilder;
require __DIR__ . '/vendor/autoload.php';
// Instantiate PHP-DI ContainerBuilder
$containerBuilder = new ContainerBuilder();
if (false) { // Should be set to true in production
$containerBuilder->enableCompilation(__DIR__ . '/var/cache');
}
// Set up settings
$settings = require __DIR__ . '/app/settings.php';
$settings($containerBuilder);
// Set up dependencies
$dependencies = require __DIR__ . '/app/dependencies.php';
$dependencies($containerBuilder);
// Build PHP-DI Container instance
$container = $containerBuilder->build();
return ConsoleRunner::createHelperSet($container->get(EntityManager::class));
......@@ -24,11 +24,11 @@
"require": {
"php": "^7.2",
"ext-json": "*",
"doctrine/orm": "^2.7",
"monolog/monolog": "^2.1",
"php-di/php-di": "^6.2",
"slim/psr7": "^1.1",
"slim/slim": "^4.5",
"doctrine/orm": "^2.6.2",
"symfony/yaml": "2.*"
},
"require-dev": {
......
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment