When we are not using a framework,
what is the best way to store configs in a composer project and how we can load them from a controller or a model file? prefer we can store configs outside the
srcfolder.why nobody using class constants to store configs
ex. App/Config/AppConfig::TIMEZONE;
- composer.json
"autoload":
{
"psr-4":
{
"App\\": "src/app/"
}
}
- /src/app/Configs/AppConfig.php
namespace App\Configs;
class AppConfig {
const TIMEZONE = 'EST';
}
- src/app/Controllers/HelloWorld.php
namespace App\Controllers;
use App\Configs\AppConfig;
class HelloWorld
{
$timezone = AppConfig::TIMEZONE;
}
Thanks
In a modern world, things are going modern. Best approach for configurations are separately save in directory. Now it's time to talk on calling configuration values; Create helper function which will gather data for you and efficiently return as you wanted.