Skip to content

Commit e08eb58

Browse files
NGSTACK-1017 simplify prepend, move config under resources dir
1 parent 61adb77 commit e08eb58

3 files changed

Lines changed: 5 additions & 24 deletions

File tree

src/DependencyInjection/NetgenApiPlatformExtrasExtension.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44

55
namespace Netgen\ApiPlatformExtras\DependencyInjection;
66

7-
use RuntimeException;
87
use Symfony\Component\Config\Definition\ConfigurationInterface;
98
use Symfony\Component\Config\Resource\FileResource;
109
use Symfony\Component\DependencyInjection\ContainerBuilder;
1110
use Symfony\Component\DependencyInjection\Extension\Extension;
1211
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
13-
use Symfony\Component\Yaml\Exception\ParseException;
1412
use Symfony\Component\Yaml\Yaml;
1513

16-
use function dirname;
14+
use function file_get_contents;
1715
use function in_array;
1816
use function is_array;
19-
use function is_file;
20-
use function is_readable;
21-
use function sprintf;
2217

2318
final class NetgenApiPlatformExtrasExtension extends Extension implements PrependExtensionInterface
2419
{
@@ -44,24 +39,10 @@ public function prepend(ContainerBuilder $container): void
4439
return;
4540
}
4641

47-
$configFile = dirname(__DIR__, 2) . '/config/doctrine.yaml';
48-
49-
if (!is_file($configFile) || !is_readable($configFile)) {
50-
return;
51-
}
52-
53-
try {
54-
$config = Yaml::parseFile($configFile);
55-
} catch (ParseException $e) {
56-
throw new RuntimeException(sprintf('Could not parse YAML file "%s": %s', $configFile, $e->getMessage()), 0, $e);
57-
}
58-
59-
if (!is_array($config)) {
60-
return;
61-
}
62-
63-
$container->addResource(new FileResource($configFile));
42+
$configFile = __DIR__ . '/../Resources/config/doctrine.yaml';
43+
$config = Yaml::parse((string) file_get_contents($configFile));
6444
$container->prependExtensionConfig('doctrine', $config['doctrine']);
45+
$container->addResource(new FileResource($configFile));
6546
}
6647

6748
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ doctrine:
44
NetgenApiPlatformExtras:
55
type: xml
66
is_bundle: false
7-
dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/config/doctrine'
7+
dir: '%kernel.project_dir%/vendor/netgen/api-platform-extras/src/Resources/config/doctrine'
88
prefix: 'Netgen\ApiPlatformExtras\Entity'
File renamed without changes.

0 commit comments

Comments
 (0)