PHPackages                             responsive-sk/slim4-themes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. responsive-sk/slim4-themes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

responsive-sk/slim4-themes
==========================

Theme system for Slim 4 applications with DI support

2.0.0(1y ago)023MITPHPPHP ^8.0CI failing

Since Apr 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/responsive-sk/slim4-themes)[ Packagist](https://packagist.org/packages/responsive-sk/slim4-themes)[ RSS](/packages/responsive-sk-slim4-themes/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (16)Used By (0)

Slim4 Themes
============

[](#slim4-themes)

Theme handling for Slim 4 applications.

Version 2.0 Changes
-------------------

[](#version-20-changes)

Version 2.0 introduces a new approach to theme handling using Dependency Injection (DI) instead of middleware. This provides several advantages:

1. **Separation of concerns**: Theme handling is a cross-cutting concern that should be handled at the container level, not in the HTTP request pipeline.
2. **Performance**: DI-based theme handling is more efficient because it doesn't require processing the request for every request.
3. **Flexibility**: DI-based theme handling allows you to use the theme in any part of your application, not just in the HTTP request pipeline.
4. **Testability**: DI-based theme handling is easier to test because you can mock the theme provider.

Installation
------------

[](#installation)

```
composer require responsive-sk/slim4-themes
```

Usage
-----

[](#usage)

### 1. Register the services

[](#1-register-the-services)

#### Using PHP-DI

[](#using-php-di)

```
use Slim4\Themes\Provider\ThemeServiceProvider;

// Create container
$container = new \DI\Container();

// Register theme services
$themeServiceProvider = new ThemeServiceProvider();
$themeServiceProvider->register($container, [
    'cookie_name' => 'theme',
    'query_param' => 'theme',
]);
```

#### Using Symfony Container

[](#using-symfony-container)

```
use Slim4\Themes\Provider\ThemeResolver;
use Slim4\Themes\Provider\ThemeProvider;
use Slim4\Themes\Middleware\RequestAwareMiddleware;
use Slim4\Themes\Interface\ThemeInterface;
use Slim4\Themes\Interface\ThemeLoaderInterface;

// Register theme services
$containerBuilder->register(ThemeResolver::class)
    ->setArguments([
        new Reference(ThemeLoaderInterface::class),
        '%theme.cookie_name%',
        '%theme.query_param%'
    ])
    ->setPublic(true);

$containerBuilder->register(ThemeProvider::class)
    ->setArguments([new Reference('service_container')])
    ->setPublic(true);

$containerBuilder->register(RequestAwareMiddleware::class)
    ->setArguments([
        new Reference(ThemeProvider::class),
        '%theme.cookie_name%',
        '%theme.query_param%'
    ])
    ->setPublic(true);

$containerBuilder->setAlias(ThemeInterface::class, ThemeProvider::class)
    ->setPublic(true);
```

### 2. Add the middleware

[](#2-add-the-middleware)

```
// Add middleware
$app->add($container->get(RequestAwareMiddleware::class));
```

### 3. Use the theme in your application

[](#3-use-the-theme-in-your-application)

```
// Get theme from container
$theme = $container->get(ThemeInterface::class);

// Use theme
$templatePath = $theme->getTemplatePath('home.twig');
```

Components
----------

[](#components)

### ThemeResolver

[](#themeresolver)

The `ThemeResolver` class is responsible for resolving the theme based on the request, cookies, or default theme.

```
use Slim4\Themes\Provider\ThemeResolver;

// Create theme resolver
$themeResolver = new ThemeResolver(
    $themeLoader,
    'theme',
    'theme'
);

// Resolve theme
$theme = $themeResolver->resolveTheme($request);
```

### ThemeProvider

[](#themeprovider)

The `ThemeProvider` class is responsible for providing the theme from the container.

```
use Slim4\Themes\Provider\ThemeProvider;

// Create theme provider
$themeProvider = new ThemeProvider($container);

// Set request
$themeProvider->setRequest($request);

// Get theme
$theme = $themeProvider->getTheme();
```

### RequestAwareMiddleware

[](#requestawaremiddleware)

The `RequestAwareMiddleware` class is responsible for making the request available to the `ThemeProvider`.

```
use Slim4\Themes\Middleware\RequestAwareMiddleware;

// Create middleware
$middleware = new RequestAwareMiddleware(
    $themeProvider,
    'theme',
    'theme'
);

// Add middleware
$app->add($middleware);
```

### ThemeServiceProvider

[](#themeserviceprovider)

The `ThemeServiceProvider` class is responsible for registering theme services in the container.

```
use Slim4\Themes\Provider\ThemeServiceProvider;

// Create service provider
$serviceProvider = new ThemeServiceProvider();

// Register services
$serviceProvider->register($container, [
    'cookie_name' => 'theme',
    'query_param' => 'theme',
]);
```

Migrating from Version 1.x
--------------------------

[](#migrating-from-version-1x)

If you're migrating from version 1.x, here are the main changes:

1. Replace `ThemeMiddleware` with `RequestAwareMiddleware`:

```
// Before
$app->add($container->get(\Slim4\Themes\Middleware\ThemeMiddleware::class));

// After
$app->add($container->get(\Slim4\Themes\Middleware\RequestAwareMiddleware::class));
```

2. Get the theme from the container instead of the request attribute:

```
// Before
$theme = $request->getAttribute('theme');

// After
$theme = $container->get(\Slim4\Themes\Interface\ThemeInterface::class);
```

3. Register the new services in your container:

```
// Register theme services
$themeServiceProvider = new \Slim4\Themes\Provider\ThemeServiceProvider();
$themeServiceProvider->register($container, [
    'cookie_name' => 'theme',
    'query_param' => 'theme',
]);
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance46

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

15

Last Release

407d ago

Major Versions

1.3.4 → 2.0.02025-05-22

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67433?v=4)[evan70](/maintainers/evan70)[@evan70](https://github.com/evan70)

---

Top Contributors

[![evan70](https://avatars.githubusercontent.com/u/67433?v=4)](https://github.com/evan70 "evan70 (19 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/responsive-sk-slim4-themes/health.svg)

```
[![Health](https://phpackages.com/badges/responsive-sk-slim4-themes/health.svg)](https://phpackages.com/packages/responsive-sk-slim4-themes)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
