PR-6.1-dev Pending

User tests: Successful: Unsuccessful:

avatar voronkovich
voronkovich
15 Apr 2026
  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

This PR adds the ability to override container configuration by creating a special bootstrap.php file in the root directory. This allows developers to:

  • Customize the DI container before application bootstrap
  • Override or extend core services
  • Register custom service providers
  • Configure application-specific dependencies
  • Add custom event listeners
  • etc.

It works similarly to defines.php.

Example 1: Event listener

This is a very simple event listener created without a plugin:

<?php

\defined('_JEXEC') or die;

use Joomla\Event\DispatcherInterface;
use Joomla\Event\EventInterface;

$container->get(DispatcherInterface::class)->addListener('onAfterRoute', function (EventInterface $event) {
    echo $event->getName();
});

Example 2: DKIM

This is a more advanced example showing how to implement DKIM for mailer:

<?php

\defined('_JEXEC') or die;

use Joomla\CMS\Mail\MailerFactoryInterface;
use Joomla\CMS\Mail\MailerInterface;
use Joomla\DI\Container;
use Joomla\Registry\Registry;

/** @var \Joomla\DI\Container $container */

function unprotect(Container $container, string $key): Container
{
    $resource   = $container->getResource($key);
    $reflection = (new \ReflectionClass($resource));
    $property   = $reflection->getProperty('protected');
    $property->setValue($resource, false);

    return $container;
}

unprotect($container, MailerFactoryInterface::class);
$container->extend(MailerFactoryInterface::class, function (MailerFactoryInterface $factory) {
    return new class ($factory) implements MailerFactoryInterface {
        public function __construct(
            private MailerFactoryInterface $factory
        ) {
        }

        public function createMailer(?Registry $settings = null): MailerInterface
        {
            $mailer = $this->factory->createMailer($settings);

            $mailer->DKIM_domain   = substr(strrchr($mailer->From, '@'), 1);
            $mailer->DKIM_identity = $mailer->From;
            $mailer->DKIM_private  = '/path/to/private/key';
            $mailer->DKIM_selector = 'phpmailer';

            return $mailer;
        }
    };
});

Testing Instructions

Create a bootstrap.php file in the root directory with the following content:

<?php

\defined('_JEXEC') or die;

use Joomla\Event\DispatcherInterface;
use Joomla\Event\EventInterface;

$container->get(DispatcherInterface::class)->addListener('onAfterRoute', function (EventInterface $event) {
    echo $event->getName();
});

Reload the page and ensure that the value onAfterRoute is present on the page.

Actual result BEFORE applying this Pull Request

You shouldn't see the onAfterRoute value on the page.

Expected result AFTER applying this Pull Request

The onAfterRoute value should be displayed.

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar voronkovich voronkovich - open - 15 Apr 2026
avatar voronkovich voronkovich - change - 15 Apr 2026
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 15 Apr 2026
Category Administration CLI
avatar voronkovich voronkovich - change - 15 Apr 2026
Labels Added: PR-6.1-dev
avatar voronkovich voronkovich - change - 15 Apr 2026
The description was changed
avatar voronkovich voronkovich - edited - 15 Apr 2026
avatar voronkovich voronkovich - change - 20 Apr 2026
The description was changed
avatar voronkovich voronkovich - edited - 20 Apr 2026
avatar voronkovich voronkovich - change - 20 Apr 2026
The description was changed
avatar voronkovich voronkovich - edited - 20 Apr 2026

Add a Comment

Login with GitHub to post a comment