Skip to main content
Version: v2.0 (upcoming)

Container Configuration

Most configuration for your application is stored in the config/ folder. The services.php file contains the most important settings you need to set up for most applications to function correctly.

config/services.php

This file returns a PHP-DI container definitions array. Each key is a service or parameter name, and its value defines how that service or parameter is resolved. The file uses PHP-DI helper functions (env, get, create, factory, add, string) to wire everything together.

use function DI\add;
use function DI\create;
use function DI\env;
use function DI\factory;
use function DI\get;
use function DI\string;

Application

KeyDefaultDescription
app.name'Application'Human-readable name for your application.
app.version'dev-main'Current version string.
app.environmentENVIRONMENT env varRuntime environment (dev, prod, etc.).
app.project_rootResolved from __DIR__/..Absolute path to the project root directory.
app.web_root{app.project_root}/publicAbsolute path to the public web root.
app.base_uriBASE_URI env var (http://localhost:8080)Base URI of the application as a UriInterface instance.
app.debugDerived from app.environmenttrue when app.environment is dev, false otherwise.

app.base_uri is built by a factory that creates a UriInterface from BASE_URI. Set BASE_URI in your .env file to the public URL of your application.

app.debug is automatically derived — you do not need to set it manually. Change the ENVIRONMENT variable to toggle debug mode.


Security

CORS

KeyDefaultDescription
security.cors.allow_origins[BASE_URI]List of allowed CORS origins. Defaults to your application's base URI.
security.cors.allow_methods['GET', 'POST', 'OPTIONS']HTTP methods allowed in cross-origin requests.
security.cors.allow_headers['Content-Type', 'Authorization']HTTP headers allowed in cross-origin requests.

All three keys use add([...]), meaning additional values can be merged in from other config files. To allow additional origins, add them to the array:

'security.cors.allow_origins' => add([
env('BASE_URI', 'http://localhost:8080'),
'https://my-other-domain.com',
]),

Trusted Hosts

KeyDefaultDescription
security.allowed_hosts[TRUSTED_HOST]Hostnames the application will respond to. Defaults to the TRUSTED_HOST env var (localhost).

Set TRUSTED_HOST in your .env file to match your production domain to prevent host header injection attacks.


GraphQL

KeyDefaultDescription
graphql.transformers[DateTimeImmutableTransformer]List of scalar transformers registered with the GraphQL engine.

Transformers convert PHP types to and from GraphQL scalar values. The DateTimeImmutableTransformer is included by default to handle DateTimeImmutable objects. To add your own transformer, append it to the array:

'graphql.transformers' => add([
get(\ForestCityLabs\Framework\GraphQL\Transformer\DateTimeImmutableTransformer::class),
get(\Application\GraphQL\Transformer\MoneyTransformer::class),
]),

Cache

KeyDefaultDescription
cache.paths[{app.project_root}/var/cache/CompiledContainer.php]Paths to files that should be invalidated when the cache is cleared.
cache.pool.defaultPredisCachePool using redis.cache_clientThe default PSR-6 cache pool used by the application.

The standard install uses Redis via Predis as the default cache backend. The Redis connection is configured separately under the redis.cache_client service. Set REDIS_URI in your .env file to point to your Redis instance (e.g. tcp://cache:6379).

To swap out the cache backend, replace cache.pool.default with a different PSR-6 pool implementation. See the Caching documentation for available drivers.


Logger

KeyDefaultDescription
logger.pathphp://stderrLog output destination. Can be a file path or a PHP stream wrapper.
logger.handlers[FingersCrossedHandler]Monolog handlers attached to the application logger.

By default, logs are written to stderr through a FingersCrossedHandler, which buffers log records and only flushes them when an error-level message is emitted. To write logs to a file instead:

'logger.path' => string('{app.project_root}/var/log/app.log'),

ORM

KeyDefaultDescription
orm.entity_paths[{app.project_root}/src/Entity]Directories scanned by Doctrine ORM for entity classes.

Add additional directories if your entities are spread across multiple namespaces or packages:

'orm.entity_paths' => add([
string('{app.project_root}/src/Entity'),
string('{app.project_root}/src/AnotherModule/Entity'),
]),

The database connection is configured via the DATABASE_URI environment variable (e.g. pdo-mysql://root:root@db:3306/app).


Migrations

KeyDefaultDescription
migration.paths['Application\\Migrations' => {app.project_root}/migrations]Map of namespace to directory for Doctrine Migrations.

The key is the PHP namespace for generated migration classes and the value is the filesystem path where those classes are stored. To add a second migration set:

'migration.paths' => add([
'Application\\Migrations' => string('{app.project_root}/migrations'),
'Application\\AnotherModule\\Migrations' => string('{app.project_root}/src/AnotherModule/migrations'),
]),

Twig

KeyDefaultDescription
twig.cache_directory{app.project_root}/var/cache/twigDirectory where Twig stores compiled template files.
twig.extensions[]Additional Twig extensions to register.
twig.template_directories[{app.project_root}/templates]Directories scanned for Twig template files.

To register a Twig extension:

'twig.extensions' => add([
get(\Application\Twig\MyExtension::class),
]),

Console

KeyDefaultDescription
console.commands[]Additional console commands to register with the application.

Register your own Symfony Console commands here:

'console.commands' => add([
get(\Application\Command\MyCommand::class),
]),

Environment Variables Reference

All environment variables are read from your .env file. Copy .env.dist to .env to get started:

$ cp .env.dist .env
VariableDescriptionExample
BASE_URIPublic base URL of the applicationhttp://localhost:8080
ENVIRONMENTRuntime environmentdev or prod
DATABASE_URIDoctrine DBAL DSN for the databasepdo-mysql://root:root@db:3306/app
TRUSTED_HOSTHostname the app accepts requests forlocalhost
REDIS_URIPredis connection URI for cache and sessionstcp://cache:6379