-
-
Notifications
You must be signed in to change notification settings - Fork 5
Configuration
Configuration shapes the application's behaviour without changing the source code. Database credentials, logging behaviour, session setup, routing defaults, and deployment-specific values are all examples of configuration rather than application logic.
The configuration package is documented in more detail at https://www.php.gt/docs/Config/.
WebEngine starts with its own default config and then layers the project's own config files on top. Environment-specific overrides can then refine those values again.
At a high level the load order is:
- WebEngine defaults (
vendor/phpgt/webengine/config.default.ini) - project
config.ini - environment-specific config files such as development or production overrides, such as
config.dev.iniorconfig.production.ini - environment variables
That gives us a predictable starting point while still letting each environment change only the values it actually needs to change.
See the configuration reference page for a full list of every default value in a WebEngine application.
The most important config areas early on are usually:
- application settings such as namespace and directories
- routing behaviour
- session settings
- database connection settings
- logging
- security-related values
As the project grows, these settings make it possible to change deployment details without changing page logic.
Configuration reaches page logic and services through the normal service container. That means a page or class can receive the full config object or, better still, the specific config section it actually needs.
use GT\Config\Config;
function go(Config $config, ExampleRepository $exampleRepository, PaymentProvider $payment):void {
// Pass specific config values to an object:
$exampleRepository->connect(
$config->getString("database.host"),
$config->getInt("database.port"),
);
// Pass a whole section of config to an object:
$paymentProvider->setup($config->getSection("paymentApi"));
}Passing focused configuration into application classes usually keeps those classes easier to understand. It also makes it clearer which parts of the system are responsible for secrets, credentials, and other environment-specific values.
In the next section we will connect to databases.
- File-based routing
- Page views
- Page logic
- Dynamic URIs
- Headers and footers
- Custom HTML components
- Page partials
- Binding data to the DOM
- DOM manipulation
- Hello You tutorial
- Todo list tutorial
- Address book tutorial WIP
- Blueprints
- Application architecture
- Coding styleguide WIP
- PHP environment setup WIP
- Web servers WIP
- Background cron tasks
- Database setup WIP
- Client-side compilation WIP
- Testing WebEngine applications WIP
- Production checklist WIP
- Security WIP