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\Core\DiscoveryCacheStrategy;

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

    public static function fromArray(array $config): self;
    public function isDebugEnabled(): 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
debugboolWP_DEBUG valueEnable debug logging for discovery

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\Core\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,

Defaults to the value of WP_DEBUG when not explicitly set.

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
RestConfigapp/rest.config.phpREST API permissions
RenderApiConfigapp/render-api.config.phpRender API allowlisting

Released under the MIT License.