Skip to content

Commit 8534b34

Browse files
authored
Merge pull request #10 from netgen/NGSTACK-1017-doctrine-config
NGSTACK-1017 register bundle Doctrine mapping via prepend
2 parents d496c38 + e08eb58 commit 8534b34

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"symfony/console": "^7.3 || ^8.0",
3434
"symfony/security-core": "^7.3 || ^8.0",
3535
"symfony/security-http": "^7.3 || ^8.0",
36+
"symfony/yaml": "^7.3 || ^8.0",
3637
"api-platform/symfony": "^4.2",
3738
"api-platform/doctrine-orm": "^4.2",
3839
"lexik/jwt-authentication-bundle": "^3.1",

src/DependencyInjection/NetgenApiPlatformExtrasExtension.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
namespace Netgen\ApiPlatformExtras\DependencyInjection;
66

77
use Symfony\Component\Config\Definition\ConfigurationInterface;
8+
use Symfony\Component\Config\Resource\FileResource;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\DependencyInjection\Extension\Extension;
11+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
12+
use Symfony\Component\Yaml\Yaml;
1013

14+
use function file_get_contents;
1115
use function in_array;
1216
use function is_array;
1317

14-
final class NetgenApiPlatformExtrasExtension extends Extension
18+
final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface
1519
{
1620
private const array SCALAR_ARRAY_PARAMS = [
1721
'ignored_routes',
@@ -29,6 +33,18 @@ public function load(array $configs, ContainerBuilder $container): void
2933
$this->setParameters($container, $config, $this->getAlias());
3034
}
3135

36+
public function prepend(ContainerBuilder $container): void
37+
{
38+
if (!$container->hasExtension('doctrine')) {
39+
return;
40+
}
41+
42+
$configFile = __DIR__ . '/../Resources/config/doctrine.yaml';
43+
$config = Yaml::parse((string) file_get_contents($configFile));
44+
$container->prependExtensionConfig('doctrine', $config['doctrine']);
45+
$container->addResource(new FileResource($configFile));
46+
}
47+
3248
/**
3349
* @param mixed[] $config
3450
*/

src/Resources/config/doctrine.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
doctrine:
2+
orm:
3+
mappings:
4+
NetgenApiPlatformExtras:
5+
type: xml
6+
is_bundle: false
7+
dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/src/Resources/config/doctrine'
8+
prefix: 'Netgen\ApiPlatformExtras\Entity'
File renamed without changes.

0 commit comments

Comments
 (0)