[DB] Merge definition of SchemaDefDriver with SchemaDefPass for clarity
This commit is contained in:
		@@ -24,10 +24,9 @@ services:
 | 
			
		||||
    App\Core\Router\RouteLoader:
 | 
			
		||||
        tags: ['routing.loader']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Wrapper arround Doctrine's StaticPHP metadata driver
 | 
			
		||||
    app.core.schemadef_driver:
 | 
			
		||||
        class: App\Core\DB\SchemaDefDriver
 | 
			
		||||
    app.schemadef_driver:
 | 
			
		||||
        class: App\DependencyInjection\Compiler\SchemaDefDriver
 | 
			
		||||
        arguments: 
 | 
			
		||||
            - '%kernel.project_dir%/src/Entity'
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,8 +26,8 @@
 | 
			
		||||
 * @package   GNUsocial
 | 
			
		||||
 * @category  Modules
 | 
			
		||||
 *
 | 
			
		||||
 * @author    Hugo Sales <hugo@fc.up.pt>
 | 
			
		||||
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @author    Hugo Sales <hugo@hsal.es>
 | 
			
		||||
 * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@@ -100,20 +100,20 @@ class ModuleManager
 | 
			
		||||
        foreach ($module_paths as $path) {
 | 
			
		||||
            $type   = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path));
 | 
			
		||||
            $dir    = dirname($path);
 | 
			
		||||
            $module = basename($dir);
 | 
			
		||||
            $module = basename($dir); // component or plugin
 | 
			
		||||
            $fqcn   = "\\{$type}\\{$module}\\{$module}";
 | 
			
		||||
            $module_manager->add($fqcn, $path);
 | 
			
		||||
            if (!is_null($container) && file_exists($dir = $dir . '/Entity') && is_dir($dir)) {
 | 
			
		||||
                $entity_paths[] = $dir;
 | 
			
		||||
                $container->findDefinition('doctrine.orm.default_metadata_driver')->addMethodCall(
 | 
			
		||||
                    'addDriver',
 | 
			
		||||
                    [new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"]
 | 
			
		||||
                    [new Reference('app.schemadef_driver'), "{$type}\\{$module}\\Entity"]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_null($container)) {
 | 
			
		||||
            $container->findDefinition('app.core.schemadef_driver')
 | 
			
		||||
            $container->findDefinition('app.schemadef_driver')
 | 
			
		||||
                      ->addMethodCall('addPaths', ['$paths' => $entity_paths]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,24 +18,43 @@
 | 
			
		||||
// }}}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Doctrine metadata driver which implements our old `schemaDef` interface
 | 
			
		||||
 * Compiler pass which triggers Symfony to tell Doctrine to
 | 
			
		||||
 * use our `SchemaDef` metadata driver
 | 
			
		||||
 *
 | 
			
		||||
 * @package  GNUsocial
 | 
			
		||||
 * @category DB
 | 
			
		||||
 *
 | 
			
		||||
 * @author    Hugo Sales <hugo@fc.up.pt>
 | 
			
		||||
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @author    Hugo Sales <hugo@hsal.es>
 | 
			
		||||
 * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\Core\DB;
 | 
			
		||||
namespace App\DependencyInjection\Compiler;
 | 
			
		||||
 | 
			
		||||
use App\Core\Log;
 | 
			
		||||
use Doctrine\Persistence\Mapping\ClassMetadata;
 | 
			
		||||
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
 | 
			
		||||
use Functional as F;
 | 
			
		||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
 | 
			
		||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
 | 
			
		||||
use Symfony\Component\DependencyInjection\Reference;
 | 
			
		||||
 | 
			
		||||
class SchemaDefDriver extends StaticPHPDriver
 | 
			
		||||
/**
 | 
			
		||||
 * Register a new ORM driver to allow use to use the old (and better) schemaDef format
 | 
			
		||||
 */
 | 
			
		||||
class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Register `app.schemadef_driver` (this class instantiated with argument src/Entity) as a metadata driver
 | 
			
		||||
     */
 | 
			
		||||
    public function process(ContainerBuilder $container)
 | 
			
		||||
    {
 | 
			
		||||
        $container->findDefinition('doctrine.orm.default_metadata_driver')
 | 
			
		||||
                  ->addMethodCall('addDriver',
 | 
			
		||||
                                  [new Reference('app.schemadef_driver'), 'App\\Entity']
 | 
			
		||||
                  );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * V2 DB type => Doctrine type
 | 
			
		||||
     */
 | 
			
		||||
@@ -75,6 +94,8 @@ class SchemaDefDriver extends StaticPHPDriver
 | 
			
		||||
    {
 | 
			
		||||
        $schema = $class_name::schemaDef();
 | 
			
		||||
 | 
			
		||||
        Log::emergency($class_name);
 | 
			
		||||
 | 
			
		||||
        $metadata->setPrimaryTable([
 | 
			
		||||
            'name'              => $schema['name'],
 | 
			
		||||
            'indexes'           => self::kv_to_name_col($schema['indexes'] ?? []),
 | 
			
		||||
@@ -1,50 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// {{{ License
 | 
			
		||||
// This file is part of GNU social - https://www.gnu.org/software/social
 | 
			
		||||
//
 | 
			
		||||
// GNU social is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU Affero General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// (at your option) any later version.
 | 
			
		||||
//
 | 
			
		||||
// GNU social is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
// GNU Affero General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU Affero General Public License
 | 
			
		||||
// along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
// }}}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Compiler pass which triggers Symfony to tell Doctrine to
 | 
			
		||||
 * use out `SchemaDef` metadata driver
 | 
			
		||||
 *
 | 
			
		||||
 * @package  GNUsocial
 | 
			
		||||
 * @category DB
 | 
			
		||||
 *
 | 
			
		||||
 * @author    Hugo Sales <hugo@fc.up.pt>
 | 
			
		||||
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\DependencyInjection\Compiler;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
 | 
			
		||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
 | 
			
		||||
use Symfony\Component\DependencyInjection\Reference;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Register a new ORM driver to allow use to use the old (and better) schemaDef format
 | 
			
		||||
 */
 | 
			
		||||
class SchemaDefPass implements CompilerPassInterface
 | 
			
		||||
{
 | 
			
		||||
    public function process(ContainerBuilder $container)
 | 
			
		||||
    {
 | 
			
		||||
        $container->findDefinition('doctrine.orm.default_metadata_driver')
 | 
			
		||||
                  ->addMethodCall('addDriver',
 | 
			
		||||
                                  [new Reference('app.core.schemadef_driver'), 'App\\Entity']
 | 
			
		||||
                  );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -23,15 +23,15 @@
 | 
			
		||||
 * @package GNUsocial
 | 
			
		||||
 * @category Kernel
 | 
			
		||||
 *
 | 
			
		||||
 * @author    Hugo Sales <hugo@fc.up.pt>
 | 
			
		||||
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @author    Hugo Sales <hugo@hsal.es>
 | 
			
		||||
 * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
 | 
			
		||||
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App;
 | 
			
		||||
 | 
			
		||||
use App\DependencyInjection\Compiler\ModuleManagerPass;
 | 
			
		||||
use App\DependencyInjection\Compiler\SchemaDefPass;
 | 
			
		||||
use App\DependencyInjection\Compiler\SchemaDefDriver;
 | 
			
		||||
use const PHP_VERSION_ID;
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
 | 
			
		||||
use Symfony\Component\Config\Loader\LoaderInterface;
 | 
			
		||||
@@ -152,6 +152,6 @@ class Kernel extends BaseKernel
 | 
			
		||||
        parent::build($container);
 | 
			
		||||
 | 
			
		||||
        $container->addCompilerPass(new ModuleManagerPass());
 | 
			
		||||
        $container->addCompilerPass(new SchemaDefPass());
 | 
			
		||||
        $container->addCompilerPass(new SchemaDefDriver(SRCDIR . '/Entity'));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user