PHP Joomla! 6 Joomla! 5 Plugin Intermediate

Build a Native Joomla 5 and 6 Plugin with ServiceProvider and SubscriberInterface

Wires a modern plugin via DI container with SubscriberInterface and explicit typed event subscriptions.

Updated on 24 November 2026 59 copies 202 views
plugins/system/example/services/provider.php
<?php

declare(strict_types=1);

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Vendor\Plugin\System\Example\Extension\Example;

return new class () implements ServiceProviderInterface {
    public function register(Container $container): void
    {
        $container->set(
            PluginInterface::class,
            function (Container $container) {
                $plugin = new Example(
                    $container->get(DispatcherInterface::class),
                    (array) PluginHelper::getPlugin('system', 'example')
                );
                $plugin->setApplication(Factory::getApplication());
                $plugin->setDatabase($container->get(DatabaseInterface::class));

                return $plugin;
            }
        );
    }
};
Injects Application and DatabaseInterface cleanly via the DI container.

Technical explanation and best practices

Modern Joomla 5 and 6 plugins implement SubscriberInterface and declare their listeners explicitly in getSubscribedEvents(), receiving strongly typed Event objects with zero reflection overhead.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.