[MODULE][DB] Added support for loading entity definitions from modules
This commit is contained in:
parent
7de1654f9a
commit
5fc7647c40
@ -34,12 +34,13 @@
|
||||
namespace App\Core;
|
||||
|
||||
use App\Util\Formatting;
|
||||
|
||||
use AppendIterator;
|
||||
use FilesystemIterator;
|
||||
use Functional as F;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ModuleManager
|
||||
{
|
||||
@ -82,18 +83,31 @@ class ModuleManager
|
||||
}
|
||||
}
|
||||
|
||||
public static function process()
|
||||
public static function process(ContainerBuilder $container)
|
||||
{
|
||||
$module_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php'));
|
||||
$module_manager = new self();
|
||||
$entity_paths = [];
|
||||
$default_driver = $container->findDefinition('doctrine.orm.default_metadata_driver');
|
||||
foreach ($module_paths as $path) {
|
||||
// 'modules' and 'plugins' have the same length
|
||||
$type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path));
|
||||
$module = basename(dirname($path));
|
||||
$dir = dirname($path);
|
||||
$module = basename($dir);
|
||||
$fqcn = "\\{$type}\\{$module}\\{$module}";
|
||||
$module_manager->add($fqcn, $path);
|
||||
if (file_exists($dir = $dir . '/Entity') && is_dir($dir)) {
|
||||
$entity_paths[] = $dir;
|
||||
$default_driver->addMethodCall(
|
||||
'addDriver',
|
||||
[new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$container->findDefinition('app.core.schemadef_driver')
|
||||
->addMethodCall('addPaths', ['$paths' => $entity_paths]);
|
||||
|
||||
$module_manager->preRegisterEvents();
|
||||
|
||||
file_put_contents(CACHE_FILE, "<?php\nreturn " . var_export($module_manager, true) . ';');
|
||||
|
@ -36,17 +36,11 @@ namespace App\DependencyInjection\Compiler;
|
||||
use App\Core\ModuleManager;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class ModuleManagerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
ModuleManager::process();
|
||||
$container->findDefinition('doctrine.orm.default_metadata_driver')
|
||||
->addMethodCall('addDriver',
|
||||
[new Reference('app.core.schemadef_driver'), 'Plugin\\Entity'])
|
||||
->addMethodCall('addDriver',
|
||||
[new Reference('app.core.schemadef_driver'), 'Component\\Entity']);
|
||||
ModuleManager::process($container);
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class Kernel extends BaseKernel
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
$container->addCompilerPass(new SchemaDefPass());
|
||||
$container->addCompilerPass(new ModuleManagerPass());
|
||||
$container->addCompilerPass(new SchemaDefPass());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user