guzzle-bundle
guzzle-bundle copied to clipboard
[doc] Avoid runtime file read
:+1:
Definitely right for production, but what happens during development? IIRC Symfony recognises whether the container has changed rather than automatically compiling it on every request, so presumably it won't recognise whether client.json
has changed? That could lead to some confusion. Could someone test this?
Good point. This should work:
use Symfony\Component\Config\Resource\FileResource;
$serviceDescriptionPath = __DIR__ . '/../Resources/config/client.json';
$container->addResource(new FileResource($serviceDescriptionPath));
$container->setParameter(
'path.to.my.service_description.file',
json_decode(file_get_contents($serviceDescriptionPath), true)
);
Just done a quick test and it seems like Symfony automatically monitors the Resources/config
folder, so we should only suggest adding it if it's stored elsewhere.
This also means that we can just use the constructor rather than the factory method in the service config. We rename the parameter too (to, say, my.service_description
).