PHPackages                             imponeer/smarty-sunrise-http-router - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. imponeer/smarty-sunrise-http-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

imponeer/smarty-sunrise-http-router
===================================

Smarty extensions to use with amazing router from sunrise-php

v3.0.0(2y ago)117.1k↓81.8%MITPHPPHP ^8.1CI passing

Since Nov 4Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/imponeer/smarty-sunrise-http-router)[ Packagist](https://packagist.org/packages/imponeer/smarty-sunrise-http-router)[ RSS](/packages/imponeer-smarty-sunrise-http-router/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (0)

[![License](https://camo.githubusercontent.com/e0a9276cce704d39fd85e8a7a2b780fad27da7d1696c84f3e1d392f71d9fb10b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d706f6e6565722f736d617274792d73756e726973652d687474702d726f757465722e737667)](LICENSE) [![GitHub release](https://camo.githubusercontent.com/f257ac893898d4d13772c544d311be5681c629bd178febb96eec2789893a79d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696d706f6e6565722f736d617274792d73756e726973652d687474702d726f757465722e737667)](https://github.com/imponeer/smarty-sunrise-http-router/releases) [![PHP](https://camo.githubusercontent.com/f22b7427f4ddee9079bbe6f6ec995e385629d70031e21f344cf2fbf3784bf89e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696d706f6e6565722f736d617274792d73756e726973652d687474702d726f757465722e737667)](http://php.net) [![Packagist](https://camo.githubusercontent.com/2cb6b088ffa9aa43ae84e998a8e3464fd0d92ebcb7d98e7556a29bdf9f71eeb8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696d706f6e6565722f736d617274792d73756e726973652d687474702d726f757465722e737667)](https://packagist.org/packages/imponeer/smarty-sunrise-http-router) [![Smarty version requirement](https://camo.githubusercontent.com/f963adc73591090e71de994d365fb2b06d2d54a0460142292e6cd32da4a4422f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f696d706f6e6565722f736d617274792d73756e726973652d687474702d726f757465722f736d61727479253246736d61727479)](https://smarty-php.github.io)

Smarty Sunrise HTTP Router
==========================

[](#smarty-sunrise-http-router)

This library exposes Sunrise HTTP Router named routes to Smarty through a `{url}` template function, allowing templates to generate links without hardcoding paths. It is designed for applications that keep routing logic in [Sunrise HTTP Router](https://github.com/sunrise-php/http-router) and want those routes available directly inside Smarty views.

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

[](#installation)

To install and use this package, we recommend to use [Composer](https://getcomposer.org):

```
composer require imponeer/smarty-sunrise-http-router
```

Otherwise, you need to include manually files from `src/` directory.

Setup
-----

[](#setup)

### Modern Smarty Extension (Recommended)

[](#modern-smarty-extension-recommended)

Register the extension with your Smarty instance and provide a configured router:

```
use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;

// $router is a configured Sunrise\Http\Router\RouterInterface instance
$router = $container->get(RouterInterface::class);

$smarty = new \Smarty\Smarty();
$smarty->addExtension(new SunriseHttpRouterExtension($router));
```

### Using with Dependency Injection Containers

[](#using-with-dependency-injection-containers)

#### Symfony Container

[](#symfony-container)

```
# config/services.yaml
services:
    _defaults:
        autowire: true
        autoconfigure: true

    Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension:
        arguments:
            - '@Sunrise\Http\Router\RouterInterface'

    \Smarty\Smarty:
        calls:
            - [addExtension, ['@Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension']]
```

#### PHP-DI Container

[](#php-di-container)

```
use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;
use function DI\create;
use function DI\get;

return [
    SunriseHttpRouterExtension::class => create()->constructor(get(RouterInterface::class)),
    \Smarty\Smarty::class => create()->method('addExtension', get(SunriseHttpRouterExtension::class)),
];
```

#### League Container

[](#league-container)

```
use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;

$container = new \League\Container\Container();

$container->add(RouterInterface::class, function () {
    // Build and return your RouterInterface implementation
});

$container->add(\Smarty\Smarty::class, function () use ($container) {
    $smarty = new \Smarty\Smarty();
    $smarty->addExtension(new SunriseHttpRouterExtension($container->get(RouterInterface::class)));

    return $smarty;
});
```

Usage
-----

[](#usage)

The `{url}` function renders a URL for a named route defined in Sunrise HTTP Router.

### Generate a route URL

[](#generate-a-route-url)

```
{url name="home"}
```

### Passing route attributes

[](#passing-route-attributes)

```
{url name="article" attributes=["slug" => "introduction-to-router"]}
{* or the shorter alias *}
{url name="article" attr=["slug" => "introduction-to-router"]}
```

### Handling missing attributes

[](#handling-missing-attributes)

If required route attributes are not provided or the route name does not exist, the router will throw an exception so you can catch and handle the error in your application.

Development
-----------

[](#development)

### Code Quality Tools

[](#code-quality-tools)

- **PHPUnit** - For unit testing

    ```
    composer test
    ```
- **PHP CodeSniffer** - For coding standards (PSR-12)

    ```
    composer phpcs    # Check code style
    composer phpcbf   # Fix code style issues automatically
    ```
- **PHPStan** - For static analysis

    ```
    composer phpstan
    ```

Documentation
-------------

[](#documentation)

Routes are defined and built using [Sunrise HTTP Router](https://github.com/sunrise-php/http-router), and Smarty extension details are available in the [Smarty documentation](https://www.smarty.net/docs/en/). Review those resources for deeper customization tips.

Contributing
------------

[](#contributing)

Contributions are welcome! Here's how you can contribute:

1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin feature-name`
5. Submit a pull request

Please make sure your code follows the PSR-12 coding standard and include tests for any new features or bug fixes.

If you find a bug or have a feature request, please create an issue in the [issue tracker](https://github.com/imponeer/smarty-sunrise-http-router/issues).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance58

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~87 days

Recently: every ~121 days

Total

11

Last Release

823d ago

Major Versions

v1.1.5 → v2.0.02023-01-03

v2.0.2 → v3.0.02024-04-02

PHP version history (3 changes)v1.0PHP &gt;=7.2

v2.0.0PHP ^7.3 || ^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/dba53e399a507d1f60626164c8b1e340a5cc0dc4f0637f4c6aaff8fc239fdaee?d=identicon)[fiammybe](/maintainers/fiammybe)

![](https://avatars.githubusercontent.com/u/342641?v=4)[Raimondas Rimkevičius](/maintainers/MekDrop)[@MekDrop](https://github.com/MekDrop)

![](https://avatars.githubusercontent.com/u/2429107?v=4)[Steve Kenow](/maintainers/skenow)[@skenow](https://github.com/skenow)

---

Top Contributors

[![MekDrop](https://avatars.githubusercontent.com/u/342641?v=4)](https://github.com/MekDrop "MekDrop (43 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (20 commits)")[![Codex](https://avatars.githubusercontent.com/in/2248422?v=4)](https://github.com/Codex "Codex (15 commits)")[![Claude](https://avatars.githubusercontent.com/in/2246796?v=4)](https://github.com/Claude "Claude (4 commits)")[![fiammybe](https://avatars.githubusercontent.com/u/3736946?v=4)](https://github.com/fiammybe "fiammybe (3 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

hacktoberfestsmartysmarty-plugins

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/imponeer-smarty-sunrise-http-router/health.svg)

```
[![Health](https://phpackages.com/badges/imponeer-smarty-sunrise-http-router/health.svg)](https://phpackages.com/packages/imponeer-smarty-sunrise-http-router)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M91](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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