KoniKode · Software built with intention

KNOWLEDGE BASE

Documentation

DOCUMENTATION
CURRENT APPLICATIONClean Framework
DocumentationClean Framework

Clean Framework · DOCUMENTATION

Source: bootstrap.php

Source: bootstrap.php

Bounded candidate reference — 2026-10-20: 0.2.0-rc.1 is committed locally through 84f415b3098af5653577b2c65eea31fca21df79c, unpublished and not production-approved; stable PHP >=8.5.11 <8.6.0 is required. This is documentation, not adoption: this knowledge base retains its installed 0.1.0-rc.1 dependency and PHP 8.2.11 local profile. Dated PHP 8.2 evidence is historical; earlier dirty-source reports retain their original test provenance, not retroactive clean-commit proof. Candidate examples are illustrative: API signatures were reviewed, but candidate code was not executed by this editorial update. See current checkpoint, open criteria and adoption boundary.

Origin: examples/reading-list/bootstrap.php

<?php

declare(strict_types=1);

use Clean\Framework\Application\Kernel;
use Clean\Framework\Application\RuntimeContext;
use Clean\Framework\Config\Config;
use Clean\Framework\Config\ConfigRepository;
use Clean\Framework\Container\Container;
use Clean\Framework\Error\ExceptionHandler;
use Clean\Framework\Logging\ContextLogger;
use Clean\Framework\Logging\ErrorLogLogger;
use Clean\Framework\Logging\Logger;
use Clean\Framework\Routing\CanonicalPathPolicy;
use Clean\Framework\Routing\Middleware\CorrelationIdMiddleware;
use Clean\Framework\Routing\Middleware\ExceptionMiddleware;
use Clean\Framework\Routing\Middleware\SecurityHeadersMiddleware;
use Clean\Framework\Routing\Router;
use Clean\Framework\Support\RandomSource;
use Clean\Framework\Support\SystemRandomSource;
use Clean\Framework\View\Renderer;
use Clean\Framework\View\ViewFactory;
use Portability\ReadingList\Controllers\ReadingListController;
use Portability\ReadingList\Domain\ReadingItem;
use Portability\ReadingList\Repositories\InMemoryReadingListRepository;
use Portability\ReadingList\Repositories\ReadingListRepository;
use Portability\ReadingList\Services\BrowseReadingList;

/*
 * This composition root returns a kernel without opening a database, starting
 * a session, contacting a provider, or inspecting the current HTTP request.
 */
return static function (Config $config, string $root): Kernel {
    $container = new Container();
    $context = new RuntimeContext(
        $config->environment(),
        (string) $config->get('app.version'),
        (string) $config->get('app.release_id')
    );
    $logger = new ContextLogger(new ErrorLogLogger(), $context->baseLogContext());
    $container->instance(Config::class, $config);
    $container->alias(ConfigRepository::class, Config::class);
    $container->instance(RuntimeContext::class, $context);
    $container->instance(Logger::class, $logger);
    $container->instance(RandomSource::class, new SystemRandomSource());

    $views = new ViewFactory(new Renderer($root . '/resources/views'));
    $views->share(['app_name' => (string) $config->get('app.name')]);
    $container->instance(ViewFactory::class, $views);

    // The fixture data and repository adapter belong to this example, not to
    // framework source or bootstrap discovery.
    $repository = new InMemoryReadingListRepository([
        new ReadingItem('a-clean-architecture', 'A Clean Architecture', 'Sample Author'),
        new ReadingItem('practical-php', 'Practical PHP', 'Example Writer'),
    ]);
    $container->instance(ReadingListRepository::class, $repository);
    $container->singleton(BrowseReadingList::class, static fn (Container $services): BrowseReadingList =>
        new BrowseReadingList($services->make(ReadingListRepository::class))
    );
    $container->factory(ReadingListController::class, static fn (Container $services): ReadingListController =>
        new ReadingListController(
            $services->make(BrowseReadingList::class),
            $services->make(ViewFactory::class)
        )
    );
    $container->freeze();

    $router = new Router(
        $container,
        (string) $config->get('http.base_path', ''),
        new CanonicalPathPolicy((string) $config->get('http.canonical_path_mode'))
    );
    $registerRoutes = require $root . '/resources/routes.php';
    $registerRoutes($router);
    $exceptions = new ExceptionHandler(
        $logger,
        $container->make(RandomSource::class),
        $context->isDevelopmentOrTest() && (bool) $config->get('app.debug', false)
    );
    $kernel = new Kernel($router, $exceptions, $container, $logger, $context);
    $kernel->middleware(
        new SecurityHeadersMiddleware(),
        new CorrelationIdMiddleware($container->make(RandomSource::class)),
        new ExceptionMiddleware($exceptions)
    );
    return $kernel;
};

Editorial provenance

Source: examples/reading-list/bootstrap.php. Source SHA-256: adf094e24824e853509ff27ae066ab97e129f8cbc5edf18579ba9a799a92eb1f.

Framework candidate reference; editorial checkpoint 2026-10-20. See candidate status and adoption boundary.

EXPLORE FURTHER

Drag a divider or use Left and Right Arrow keys to resize. Hold Shift for larger steps. Enter hides or restores the sidebar; Home and End select its minimum or maximum width. Double-click resets the width.

Install KoniKode