-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feedback / Questions #1
Comments
Hi, @samuelgfeller! It seems a little bit hard to enable DI container compilation using this template. Would you happen to have any suggestions on how to make it easy? Here's what I mean. We want to enable compilation only when in production. Still, we know it only after settings were set, but settings were available only after the container was built (I don't think we wanna So, in that case, the only obvious way I see to compile it is to use a separate command (CLI script) that should be used in the deployment process. |
I don't have a lot of experience with container compilation, but if I understand correctly, the issue is that Currently, in this template, the There are certainly better other ways to do this, but you could, for example, create a file <?php
$_ENV['APP_ENV'] = 'prod'; Then in the <?php
use DI\ContainerBuilder;
use Slim\App;
require __DIR__ . '/../vendor/autoload.php';
// Set the APP_ENV to prod if the file exists
if (file_exists(__DIR__ . '/set-prod-env.php')) {
require __DIR__ . '/set-prod-env.php';
} elseif (!isset($_ENV['APP_ENV'])) {
// Set the APP_ENV to dev if it is not already set
$_ENV['APP_ENV'] = 'dev';
}
// Instantiate DI ContainerBuilder
$containerBuilder = new ContainerBuilder();
// Add container definitions
$containerBuilder->addDefinitions(__DIR__ . '/container.php');
// Compile or use the cache if prod env
if ($_ENV['APP_ENV'] === 'prod') {
$containerBuilder->enableCompilation(__DIR__ . '/var/cache');
}
$container = $containerBuilder->build();
// Create app instance
return $container->get(App::class); Or if you don't want to create an additional file, you could extract the Let me know if that helps and how you end up doing it. |
If you have questions or suggestions, please don't hesitate to let me know here.
The text was updated successfully, but these errors were encountered: