Skip to content

App class configuration

The configuration object is created by setting the config directives in the Koded\Framework\App constructor.

Argument Type Required Default
modules array no [] A list of DIModules for the app
middleware array no [] The app middleware stack
config object, string no '' A path to a config file, FQCN of the configuration class, or an instance of a config object
renderer string no 'start_response' Response renderer function/method

All directives are optional.

<?php

new App(
    modules: [
        // a list of DIModule implementation(s)
    ],
    middleware: [
        // a list of PSR-15 middleware classes (global)
    ],
    config: __DIR__ . '/path/to/my/config.php', 
    // or
    config: '.env', 
    // or
    config: new MyConfig(),

    renderer: MyRenderer::class,
    // or
    renderer: 'my_renderer_function'
);

Constructor arguments

modules

optional

This argument accepts a list of DIModule instances that configures the Dependency Injection Container for your app. See more about DI modules.

Example:

[
    new My\App\Module(),
]

middleware

optional

A list of PSR-15 middleware classes for your application.

Example:

[
    // ... your middleware classes
    My\App\Middleware\CustomMiddleware::class,
    new My\App\Middleware\Other(),
]

Check the PSR-15 middleware stack page for details how Koded framework implements this functionality.

config

optional

Configuration values for your application. It supports

  • .php file that returns an array, or
  • .env file, or
  • instance of Koded\Stdlib\Configuration object.

Examples:

<?php

# conf.php
return [
    'key' => 'value',
];

# /var/www/public/index.php
new App(config: '/path/to/conf.php');
# .env is always loaded (if exist)
key=value
<?php
use Koded\Framework\App;
use Koded\Stdlib\{Config, Immutable}

$config = new Config('/path/to/app/dir', new Immutable([
    'key' => 'value',
]));

new App(config: $config);

.env support

Make sure .env file is not accessible from the outside.

renderer

optional

A custom renderer for the processed ResponseInterface object. This method/function is executed by the DI container, meaning the depencencies can be anything that the container is able to resolve.

default 'start_response'

<?php
new App(renderer: MyCustomRenderer::class);

new App(renderer: 'My\App\custom_renderer');

The purpose of this class method (or function) is to provide a custom processing of the ServerRequestInterface and ResponseInterface objects BEFORE it is finally sent to the client, for example a custom-made HTML renderer for server-side template engines, or a response streaming, etc.