-
Notifications
You must be signed in to change notification settings - Fork 0
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
Does Configure::load() throw an exception and prevent loading of local file? #5
Comments
Yeah, I end up always doing the second with the two try-catch statements because sometimes (esp on CLI) the ENV isn't set and it causes the whole try/catch to fail, meaning my I actually error if the Here's a snippet from an actual app of mine /**
* Load app-env (OPTIONAL)
*
* Contains settings that should be overridden at the environment level
* e.g. setting debug => true for the 'dev' environment but not 'uat'
*
* make sure to set in VirtualHost ... SetEnv APP_ENV foo
*/
try {
$env = getenv('APP_ENV');
Configure::load("app-{$env}", 'default');
} catch (\Exception $e) {
# ignore, if not used
}
/**
* Load app-local (REQUIRED)
*
* It is expected that this file will contain, at the min, the database username/password
*/
try {
Configure::load("app-local", 'default');
} catch (\Exception $e) {
die($e->getMessage() . "\n");
} |
Yep, easily adaptable to each project's needs. 😄 👍 If I were working with a team, I would probably supplement the // formatted for readability here
die(
'Untracked (but mandatory) config/app-local.php missing. '
. ' Copy & review config/app-local-sample.php to start. Exception message: '
. $e->getMessage() . "\n"
); A new dev would only stumble on that exactly once, and also immediately understand how the system worked without any further documentation or "study". Quick recovery plus an environment lesson, in 3 lines of code. |
Great idea with smart die() 👍 |
Addresses the question raised in #5.
@garethellis36 / @garethellis mentioned to me at CakeFest that there might be an issue with this code snippet :
The answer is: I'm not sure-- I don't think I've tested it. If it does, it could be an issue specifically in production situations, where an
APP_ENV
var isn't meant to even be explicitly required or set. The solution is straightforward though:Not quite as succinct, but probably safer. Has anyone tested this? It shouldn't be too difficult using the demo vagrant box in this repo.
The text was updated successfully, but these errors were encountered: