Skip to content

Commit

Permalink
Merge pull request #10 from ekyna/fix-di-param
Browse files Browse the repository at this point in the history
Use 'kernel.project_dir' parameter if available.
  • Loading branch information
bresam authored Jul 1, 2022
2 parents 1bb72e7 + 31a7e7c commit 450abf7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 20 additions & 4 deletions DependencyInjection/IvoryGoogleMapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,28 @@ private function loadServicesConfig(array $config, ContainerBuilder $container,
'time_zone' => true,
];

$serializerLoaded = false;
$loadSerializer = function() use ($container, $loader) {
$loader->load('service/serializer.xml');

if ($container->hasParameter('kernel.project_dir')) {
$container
->getDefinition('ivory.google_map.serializer.loader')
->replaceArgument(0, '%kernel.project_dir%/vendor/ivory/google-map/src/Service/Serializer');
}
};

foreach ($services as $service => $http) {
if (isset($config[$service])) {
$this->loadServiceConfig($service, $config[$service], $container, $loader, $http);
if (!isset($config[$service])) {
continue;
}

if ($http && !$serializerLoaded) {
$loadSerializer();
$serializerLoaded = true;
}

$this->loadServiceConfig($service, $config[$service], $container, $loader, $http);
}
}

Expand All @@ -139,8 +157,6 @@ private function loadServiceConfig(
$definition = $container->getDefinition($serviceName = 'ivory.google_map.'.$service);

if ($http) {
$loader->load('service/serializer.xml');

$definition
->addArgument(new Reference($config['client']))
->addArgument(new Reference($config['message_factory']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function setUp()
{
$this->container = new ContainerBuilder();
$this->container->setParameter('kernel.root_dir', __DIR__.'/..');
$this->container->setParameter('kernel.project_dir', realpath(__DIR__.'/../..'));
$this->container->setParameter('kernel.debug', $this->debug = false);
$this->container->setParameter('locale', $this->locale = 'en');
$this->container->set('httplug.client', $this->client = $this->createClientMock());
Expand Down Expand Up @@ -274,6 +275,7 @@ public function testDirection()
$this->assertSame($this->serializer, $direction->getSerializer());
$this->assertSame(DirectionService::FORMAT_JSON, $direction->getFormat());
$this->assertFalse($direction->hasBusinessAccount());
self::assertTrue($this->container->has('ivory.google_map.serializer.loader'));
}

public function testDirectionFormat()
Expand Down

0 comments on commit 450abf7

Please sign in to comment.