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(11mo ago)023MITPHPPHP ^8.0CI failing

Since Apr 30Pushed 11mo 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 1mo ago

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

30

—

LowBetter than 64% of packages

Maintenance50

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

355d ago

Major Versions

1.3.4 → 2.0.02025-05-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9ca94d5516a8f930325df47de8418a33caf484280105d108a693533c73d4699?d=identicon)[evan70](/maintainers/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.3k86.3M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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