-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
Documentation enableCompilation incomplete #629
Comments
The compilation will prevent to evaluate the definitions when fetching entries. So you still need to add the definitions every time (the container is actually compiled when If you want to save even more time, you can store those definitions in separate files and call I'll keep this issue open, it might be good to improve the documentation. |
Hmm, I'm still puzzled why my code works. At build phase I create the compiled di-file. At run-time I check with an environment variable if I add the compilation file or if I add the definitions. This setup doesn't break any code. Even better, the compilationfile includes all my environment variables (whom I load through dotenv). Which is why I can eliminate the reading of my .env files in production. Note: I use the php-di/slim bridge. |
Note that environment variables are still read with the compiled container. That allows to change environment variables after the container has been compiled and those changes will be picked up.
Yes in your setup that might work because everything is compiled. If you use |
So if I precompile the following DI-entry, the environment variables can still be changed after the compilation step?
Because in the precompiled file I can see the environment variables hardcoded in the constructor. Which is not a problem, but helpful to know in CI-environments.
That clarifies alot! Thank you. |
In the compiled file you should still see As you can see |
Hmm, that's not what I see:
And in the definition file:
A search in the CompiledContainer.php for getenv has no results. |
OK I see, you are using |
My bad, I did not know the |
Could you clarify the moment related to reading the file, please?
I use the container for creating objects (using autowiring) that should not be stored inside the container, but that have dependencies defined in definitions.php:
Why does it read the file? Thanks in advance! |
@deftbrain ah right, if you use make or any entry that isn't compiled (your autowired entries here) then PHP-DI will check in the definition files if it can find them. So that's why the file is read. |
@mnapoli, could you explain in more detail, please, what is the reason to read definition files again if they are already transformed into a compiled container? Is there a case when some definition from a file will not be passed into the compiled container? |
@deftbrain you can read more about it here (http://php-di.org/doc/performances.html#optimizing-for-compilation) but basically some definitions cannot be compiled. For example wildcard definitions, or autowired definitions that are not declared in config files. |
I am puzzled how to use the enableCompilation() function after reading through the documentation. The documentation states you only have to call enableCompilation(), but for optimum speed you don't want to add the definitions after reading in the compilation file?
Isn't it an if-else story? E.g
instead of:
The text was updated successfully, but these errors were encountered: