Skip to content

FoehnConfig ​

Core configuration class for Føhn. Like all other config classes, it can be auto-discovered via a foehn.config.php file. A legacy array-based approach via Kernel::boot() is also supported.

Signature ​

php
<?php

namespace Studiometa\Foehn\Config;

use Tempest\Discovery\DiscoveryCacheStrategy;

final readonly class FoehnConfig
{
    public function __construct(
        public DiscoveryCacheStrategy $discoveryCacheStrategy = DiscoveryCacheStrategy::NONE,
        public ?string $discoveryCachePath = null,
        /** @var list<class-string> */
        public array $hooks = [],
        /** @var class-string|null */
        public ?string $imageTransformer = null,
        public bool $debug = false,
        public ?bool $recordErrors = null,
        public ?bool $traceRequests = null,
        public string $cliNamespace = 'app',
    );

    public static function fromArray(array $config): self;
    public function isDebugEnabled(): bool;
    public function recordsErrors(): bool;
    public function tracesRequests(): bool;
    public function isDiscoveryCacheEnabled(): bool;
    public function getDiscoveryCachePath(): string;
}

Properties ​

PropertyTypeDefaultDescription
discoveryCacheStrategyDiscoveryCacheStrategyNONECache strategy for discoveries
discoveryCachePathstring|nullnullCustom path for cache files
hooksclass-string[][]Opt-in hook classes to activate
imageTransformerclass-string|nullnullThe ImageTransformer class image_url() uses, for example GlideTransformer::class. null gives back the URL unchanged. See Images
debugboolfalseRaise PHP warnings: each class discovery skips, a discovery cache it cannot write, a missing block editor registrar
recordErrorsbool|nullnullWrite errors to the log wp foehn errors reads. null records them in the local and development environments
traceRequestsbool|nullnullStore a trace of each front-end request for wp foehn trace. null traces them in local and development
cliNamespacestring'app'The WP-CLI command the project's #[AsCliCommand] classes go under: wp app <name>

Usage ​

Create a config file in your app directory:

php
<?php
// app/foehn.config.php

use Studiometa\Foehn\Config\FoehnConfig;
use Studiometa\Foehn\Hooks\Cleanup\CleanHeadTags;
use Studiometa\Foehn\Hooks\Security\SecurityHeaders;
use Tempest\Discovery\DiscoveryCacheStrategy;

return new FoehnConfig(
    discoveryCacheStrategy: DiscoveryCacheStrategy::FULL,
    discoveryCachePath: WP_CONTENT_DIR . '/cache/foehn',
    hooks: [
        CleanHeadTags::class,
        SecurityHeaders::class,
    ],
    debug: WP_DEBUG,
);

Then boot the kernel without any config array:

php
Kernel::boot(__DIR__ . '/app');

Via Kernel::boot() (legacy) ​

You can also pass configuration directly to Kernel::boot():

php
use Studiometa\Foehn\Kernel;

Kernel::boot(__DIR__ . '/app', [
    'discovery_cache' => 'full',
    'discovery_cache_path' => WP_CONTENT_DIR . '/cache/foehn',
    'hooks' => [
        CleanHeadTags::class,
        SecurityHeaders::class,
    ],
    'debug' => WP_DEBUG,
]);

Note: If both a foehn.config.php file and boot array are provided, the config file takes precedence.

Discovery Cache Strategies ​

StrategyValueDescription
NONE'none'No caching (default, for development)
FULL'full'Cache all discoveries (production)
PARTIAL'partial'Cache only vendor discoveries

Opt-in Hooks ​

Føhn includes built-in hook classes that you can opt into:

php
'hooks' => [
    \Studiometa\Foehn\Hooks\Cleanup\CleanHeadTags::class,
    \Studiometa\Foehn\Hooks\Cleanup\DisableEmoji::class,
    \Studiometa\Foehn\Hooks\Security\SecurityHeaders::class,
],

These classes are not auto-discovered — they must be explicitly listed.

Debug Mode ​

When enabled, discovery failures (reflection errors, missing classes) are logged via trigger_error():

php
'debug' => true,

The default is false. To follow WP_DEBUG, write debug: WP_DEBUG in foehn.config.php. Only the legacy Kernel::boot() array uses WP_DEBUG when it has no 'debug' key.

Image Transformer ​

imageTransformer is the class that image_url() uses to resize images. Give a class that implements ImageTransformer, for example GlideTransformer::class. null, the default, gives back the URL unchanged. The array config takes 'image_transformer' => GlideTransformer::class. See Images.

Error Log ​

recordErrors decides when uncaught exceptions, fatal errors and the warnings of the theme are written to the log wp foehn errors reads. null, the default, records them when the environment is local or development; recordsErrors() gives the answer. The array config takes 'record_errors' => true. See The error log.

Request Trace ​

traceRequests decides when each front-end request sends its id in the X-Foehn-Trace header and stores what it ran for wp foehn trace. null, the default, traces them when the environment is local or development; tracesRequests() gives the answer. The array config takes 'trace_requests' => true. See Request Trace.

CLI Namespace ​

cliNamespace is the WP-CLI command the #[AsCliCommand] classes of the project go under: wp app <name> by default. The commands of Føhn stay under wp foehn <name>, and the commands of each other package go under the namespace of that package. It is one word of lowercase letters, digits, - and _, and not foehn: another value throws an InvalidArgumentException. The array config takes 'cli_namespace' => 'site'. See Command Namespace.

All Config Classes ​

All Føhn config classes follow the same pattern — discoverable via *.config.php files:

Config ClassConfig filePurpose
FoehnConfigapp/foehn.config.phpCore bootstrap settings
TimberConfigapp/timber.config.phpTemplate directories
AcfConfigapp/acf.config.phpACF field transformation. Needs studiometa/foehn-acf
RestConfigapp/rest.config.phpREST API permissions
QueryFiltersConfigapp/query-filters.config.phpQuery filters
PageCacheConfigapp/page-cache.config.phpPage cache
DatabaseExportConfigapp/db-export.config.phpDatabase export
GlideConfigapp/glide.config.phpImage transforms

The file name is free: Føhn loads every *.config.php file of the app directory and binds each object it returns. The names above are the convention.

Føhn is released under the GPL-3.0-or-later license. The starter, the installer and the Vite plugin are MIT.