misd-service-development / guzzle-bundle

[NOT MAINTAINED] Integrates Guzzle into your Symfony2 application
99 stars 54 forks source link

[doc] Avoid runtime file read #55

Open adrienbrault opened 10 years ago

bwoodmansee commented 10 years ago

:+1:

thewilkybarkid commented 10 years ago

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?

adrienbrault commented 10 years ago

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)
);
thewilkybarkid commented 10 years ago

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