guzzle-bundle icon indicating copy to clipboard operation
guzzle-bundle copied to clipboard

[doc] Avoid runtime file read

Open adrienbrault opened this issue 10 years ago • 4 comments

adrienbrault avatar Mar 05 '14 19:03 adrienbrault

:+1:

bwoodmansee avatar Mar 05 '14 20:03 bwoodmansee

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?

thewilkybarkid avatar Mar 06 '14 08:03 thewilkybarkid

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)
);

adrienbrault avatar Mar 06 '14 10:03 adrienbrault

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).

thewilkybarkid avatar Mar 08 '14 10:03 thewilkybarkid