Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Avoid runtime file read #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adrienbrault
Copy link

No description provided.

@bwoodmansee
Copy link

👍

@thewilkybarkid
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants