From 52a21533887c866dfd033656b6255180fc7937bb Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Wed, 4 Mar 2026 13:59:50 +0100 Subject: [PATCH 1/3] NGSTACK-1017 register bundle Doctrine mapping via prepend to support auto_mapping=false --- .../NetgenApiPlatformExtrasExtension.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php index f75f49c..e652a57 100644 --- a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php +++ b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php @@ -7,11 +7,13 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; +use function dirname; use function in_array; use function is_array; -final class NetgenApiPlatformExtrasExtension extends Extension +final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface { private const array SCALAR_ARRAY_PARAMS = [ 'ignored_routes', @@ -29,6 +31,29 @@ public function load(array $configs, ContainerBuilder $container): void $this->setParameters($container, $config, $this->getAlias()); } + public function prepend(ContainerBuilder $container): void + { + if (!$container->hasExtension('doctrine')) { + return; + } + + $container->prependExtensionConfig( + 'doctrine', + [ + 'orm' => [ + 'mappings' => [ + 'NetgenApiPlatformExtras' => [ + 'type' => 'xml', + 'is_bundle' => false, + 'dir' => dirname(__DIR__, 2) . '/config/doctrine', + 'prefix' => 'Netgen\ApiPlatformExtras\Entity', + ], + ], + ], + ], + ); + } + /** * @param mixed[] $config */ From 61adb771981c9325305cf33fdc3c341115e4367d Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Wed, 4 Mar 2026 15:09:26 +0100 Subject: [PATCH 2/3] NGSTACK-1017 move doctrine config to yaml file --- composer.json | 1 + config/doctrine.yaml | 8 ++++ .../NetgenApiPlatformExtrasExtension.php | 40 ++++++++++++------- 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 config/doctrine.yaml diff --git a/composer.json b/composer.json index 000a0d1..180612f 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "symfony/console": "^7.3 || ^8.0", "symfony/security-core": "^7.3 || ^8.0", "symfony/security-http": "^7.3 || ^8.0", + "symfony/yaml": "^7.3 || ^8.0", "api-platform/symfony": "^4.2", "api-platform/doctrine-orm": "^4.2", "lexik/jwt-authentication-bundle": "^3.1", diff --git a/config/doctrine.yaml b/config/doctrine.yaml new file mode 100644 index 0000000..1f1e01c --- /dev/null +++ b/config/doctrine.yaml @@ -0,0 +1,8 @@ +doctrine: + orm: + mappings: + NetgenApiPlatformExtras: + type: xml + is_bundle: false + dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/config/doctrine' + prefix: 'Netgen\ApiPlatformExtras\Entity' diff --git a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php index e652a57..3e94924 100644 --- a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php +++ b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php @@ -4,14 +4,21 @@ namespace Netgen\ApiPlatformExtras\DependencyInjection; +use RuntimeException; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; +use Symfony\Component\Yaml\Exception\ParseException; +use Symfony\Component\Yaml\Yaml; use function dirname; use function in_array; use function is_array; +use function is_file; +use function is_readable; +use function sprintf; final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface { @@ -37,21 +44,24 @@ public function prepend(ContainerBuilder $container): void return; } - $container->prependExtensionConfig( - 'doctrine', - [ - 'orm' => [ - 'mappings' => [ - 'NetgenApiPlatformExtras' => [ - 'type' => 'xml', - 'is_bundle' => false, - 'dir' => dirname(__DIR__, 2) . '/config/doctrine', - 'prefix' => 'Netgen\ApiPlatformExtras\Entity', - ], - ], - ], - ], - ); + $configFile = dirname(__DIR__, 2) . '/config/doctrine.yaml'; + + if (!is_file($configFile) || !is_readable($configFile)) { + return; + } + + try { + $config = Yaml::parseFile($configFile); + } catch (ParseException $e) { + throw new RuntimeException(sprintf('Could not parse YAML file "%s": %s', $configFile, $e->getMessage()), 0, $e); + } + + if (!is_array($config)) { + return; + } + + $container->addResource(new FileResource($configFile)); + $container->prependExtensionConfig('doctrine', $config['doctrine']); } /** From e08eb585c6fa6f19e7ac87edc2da75a58a77c47d Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Wed, 4 Mar 2026 15:32:31 +0100 Subject: [PATCH 3/3] NGSTACK-1017 simplify prepend, move config under resources dir --- .../NetgenApiPlatformExtrasExtension.php | 27 +++---------------- .../Resources/config}/doctrine.yaml | 2 +- .../config}/doctrine/RefreshToken.orm.xml | 0 3 files changed, 5 insertions(+), 24 deletions(-) rename {config => src/Resources/config}/doctrine.yaml (85%) rename {config => src/Resources/config}/doctrine/RefreshToken.orm.xml (100%) diff --git a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php index 3e94924..cc05ad6 100644 --- a/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php +++ b/src/DependencyInjection/NetgenApiPlatformExtrasExtension.php @@ -4,21 +4,16 @@ namespace Netgen\ApiPlatformExtras\DependencyInjection; -use RuntimeException; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; -use function dirname; +use function file_get_contents; use function in_array; use function is_array; -use function is_file; -use function is_readable; -use function sprintf; final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface { @@ -44,24 +39,10 @@ public function prepend(ContainerBuilder $container): void return; } - $configFile = dirname(__DIR__, 2) . '/config/doctrine.yaml'; - - if (!is_file($configFile) || !is_readable($configFile)) { - return; - } - - try { - $config = Yaml::parseFile($configFile); - } catch (ParseException $e) { - throw new RuntimeException(sprintf('Could not parse YAML file "%s": %s', $configFile, $e->getMessage()), 0, $e); - } - - if (!is_array($config)) { - return; - } - - $container->addResource(new FileResource($configFile)); + $configFile = __DIR__ . '/../Resources/config/doctrine.yaml'; + $config = Yaml::parse((string) file_get_contents($configFile)); $container->prependExtensionConfig('doctrine', $config['doctrine']); + $container->addResource(new FileResource($configFile)); } /** diff --git a/config/doctrine.yaml b/src/Resources/config/doctrine.yaml similarity index 85% rename from config/doctrine.yaml rename to src/Resources/config/doctrine.yaml index 1f1e01c..0cc548a 100644 --- a/config/doctrine.yaml +++ b/src/Resources/config/doctrine.yaml @@ -4,5 +4,5 @@ doctrine: NetgenApiPlatformExtras: type: xml is_bundle: false - dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/config/doctrine' + dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/src/Resources/config/doctrine' prefix: 'Netgen\ApiPlatformExtras\Entity' diff --git a/config/doctrine/RefreshToken.orm.xml b/src/Resources/config/doctrine/RefreshToken.orm.xml similarity index 100% rename from config/doctrine/RefreshToken.orm.xml rename to src/Resources/config/doctrine/RefreshToken.orm.xml