PHPackages                             ddesrosiers/silex-annotation-provider - 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. [Framework](/categories/framework)
4. /
5. ddesrosiers/silex-annotation-provider

ActiveLibrary[Framework](/categories/framework)

ddesrosiers/silex-annotation-provider
=====================================

A silex service provider that allows the use of annotations in ServiceControllers.

v3.0.0(7y ago)25246.7k↓43.4%93MITPHPPHP &gt;=7.1.0

Since Sep 16Pushed 7y ago5 watchersCompare

[ Source](https://github.com/danadesrosiers/silex-annotation-provider)[ Packagist](https://packagist.org/packages/ddesrosiers/silex-annotation-provider)[ RSS](/packages/ddesrosiers-silex-annotation-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/c206956226f98a94c96ed62eff95240960b1f65901343a222720c93953c0830c/68747470733a2f2f706f7365722e707567782e6f72672f64646573726f73696572732f73696c65782d616e6e6f746174696f6e2d70726f76696465722f762f737461626c65)](https://packagist.org/packages/ddesrosiers/silex-annotation-provider)[![Build Status](https://camo.githubusercontent.com/a0bd6098b0fc9baf07adc742e0830bc5042b362a373c0ee64902a9e19ad10d20/68747470733a2f2f7472617669732d63692e6f72672f64616e61646573726f73696572732f73696c65782d616e6e6f746174696f6e2d70726f76696465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/danadesrosiers/silex-annotation-provider)[![Total Downloads](https://camo.githubusercontent.com/1da2d8433c32145c245e16f9a895179bbb3ef113366a210846c4097b50be280c/68747470733a2f2f706f7365722e707567782e6f72672f64646573726f73696572732f73696c65782d616e6e6f746174696f6e2d70726f76696465722f646f776e6c6f616473)](https://packagist.org/packages/ddesrosiers/silex-annotation-provider)[![License](https://camo.githubusercontent.com/835442c18abc4a1106a16b374e17de5eba4da116db4f53dc2bdca35c5b159cac/68747470733a2f2f706f7365722e707567782e6f72672f64646573726f73696572732f73696c65782d616e6e6f746174696f6e2d70726f76696465722f6c6963656e7365)](https://packagist.org/packages/ddesrosiers/silex-annotation-provider)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e999b83eb81934d0ba4b0aaf71c50667e056fc4dc91a696d32833ad6a7c8d8d7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64616e61646573726f73696572732f73696c65782d616e6e6f746174696f6e2d70726f76696465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/danadesrosiers/silex-annotation-provider/?branch=master)

silex-annotation-provider
=========================

[](#silex-annotation-provider)

A Silex ServiceProvider that defines annotations that can be used in a Silex controller. Define your controllers in a class and use annotations to setup routes and define modifiers.

Changes in v3
-------------

[](#changes-in-v3)

- Redesigned annotation format. No more Doctrine Annotations.
- Uses PSR-16 cache instead of Doctrine Cache.
- Simplified feature set. Removes support for ServiceProviders, custom Service Controller registration, and other obscure customization options in favor of simplicity.
- Minimum PHP version is now 7.1. No official support for HHVM.

Installation
============

[](#installation)

Install the silex-annotation-provider using composer.

```
{
    "require": {
        "ddesrosiers/silex-annotation-provider": "~3.0"
    }
}
```

Registration
============

[](#registration)

```
$app->register(new DDesrosiers\SilexAnnotations\AnnotationServiceProvider(), array(
    "annot.cache" => new MyPsr16Cache(),
    "annot.controllerDir" => "$srcDir/Controller",
    "annot.controllers" => [
        MyClass1::class,
        MyClass2::class
    ]
));
```

Parameters
==========

[](#parameters)

annot.controllerDir
-------------------

[](#annotcontrollerdir)

Specify the directory in which to search for controllers. This directory will be searched recursively for classes with the `@Controller` annotation. Found controller classes will be processed for route annotations. Either this or annot.controllers is required to locate controllers.

annot.controllers
-----------------

[](#annotcontrollers)

An array of fully qualified controller names. If set, the provider will automatically register each controller as a ServiceController and set up routes and modifiers based on annotations found.

annot.cache
-----------

[](#annotcache)

An instance of a class that implements Psr\\SimpleCache\\CacheInterface. This cache is used to cache annotation and the controller list to improve performance.

Faster Controller Registration
==============================

[](#faster-controller-registration)

Silex has to register every endpoint in your app on every request. If you have a lot of endpoints, that could be a significant overhead on each and every request. Silex Annotations can improve this by filtering the controllers that need to be registered using the `prefix` on the `Controller` annotation. We only need to register the endpoints in the Controller if the prefix matches the URI. In this way, Silex Annotations allows FASTER routing than pure Silex.

Annotate Controllers
====================

[](#annotate-controllers)

Create your controller. The following is an example demonstrating the use of annotations to register an endpoint.

```
namespace DDesrosiers\Controller;

use Symfony\Component\HttpFoundation\Response;

/**
 * @Controller(
 *     prefix => test
 *     after => \DDesrosiers\Controller\TestController::converter
 *     host => www.test.com
 *     requireHttp
 *     secure => ADMIN
 * )
 */
class TestController
{
    /**
     * @Route(
     *     uri => GET test/{var}
     *     assert => var, \d+
     *     convert => var, \DDesrosiers\Controller\TestController::converter
     *     after => \DDesrosiers\Controller\TestController::converter
     *     host => www.test.com
     *     requireHttps
     *     secure => DEV
     *     value => var, default
     * )
     */
    public function testMethod($var)
    {
        return new Response("test Method: $var");
    }

    public static function converter($var)
    {
        return $var;
    }
}
```

The annotations in our TestController are interpreted as follows:

```
$controllerCollection = $app['controller_factory']
    ->after('\DDesrosiers\Controller\TestController::converter');
    ->host('www.test.com');
    ->requireHttp();
    ->secure('ADMIN');
$controllerCollection->get("test/{var}", "\\DDesrosiers\\Controller\\TestController:testMethod")
    ->assert('var', '\d+')
    ->convert('var', "\\DDesrosiers\\Controller\\TestController::converter");
    ->host('www.test.com')
    ->requireHttps()
    ->secure('DEV')
    ->value('var', 'default');
$app->mount('/prefix', $controllerCollection);
```

Annotations
===========

[](#annotations)

**Controller**

The @Controller annotation marks a class as a controller. The 'prefix' option defines the mount point for the controller collection. The prefix must be the first option.

**@Route**

The @Route annotation defines an endpoint. 'uri' is required and must be the first option defined.

Short Annotation Notation
=========================

[](#short-annotation-notation)

In the Controller annotation, if prefix is the only option needed, the 'prefix' key can be omitted.

In the Route annotation, if uri is the only option needed, the 'uri' key can be omitted.

```
   namespace DDesrosiers\Controller;

   use Symfony\Component\HttpFoundation\Response;

   /**
    * @Controller(test)
    */
   class TestController
   {
       /**
        * @Route(GET test/{var})
        */
       public function testMethod($var)
       {
           return new Response("test Method: $var");
       }
   }
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~146 days

Recently: every ~50 days

Total

14

Last Release

2724d ago

Major Versions

v0.2.1 → v1.0.02014-06-15

v1.1.0 → v2.02017-01-25

v2.1.1 → v3.0.02018-12-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/379f19cd086a0ded41d10386e91116599b2450dc0855e6240b86ca9ca5bc3b74?d=identicon)[danadesrosiers](/maintainers/danadesrosiers)

---

Top Contributors

[![danadesrosiers](https://avatars.githubusercontent.com/u/4699783?v=4)](https://github.com/danadesrosiers "danadesrosiers (105 commits)")[![DerManoMann](https://avatars.githubusercontent.com/u/47783?v=4)](https://github.com/DerManoMann "DerManoMann (4 commits)")[![jsmith07](https://avatars.githubusercontent.com/u/6088805?v=4)](https://github.com/jsmith07 "jsmith07 (3 commits)")[![jdesrosiers](https://avatars.githubusercontent.com/u/716571?v=4)](https://github.com/jdesrosiers "jdesrosiers (2 commits)")[![iskandar](https://avatars.githubusercontent.com/u/17941?v=4)](https://github.com/iskandar "iskandar (2 commits)")[![olivier34000](https://avatars.githubusercontent.com/u/2056546?v=4)](https://github.com/olivier34000 "olivier34000 (2 commits)")[![marabesi](https://avatars.githubusercontent.com/u/2129872?v=4)](https://github.com/marabesi "marabesi (1 commits)")[![solcik](https://avatars.githubusercontent.com/u/1543737?v=4)](https://github.com/solcik "solcik (1 commits)")

---

Tags

serviceprovidersilexannotation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ddesrosiers-silex-annotation-provider/health.svg)

```
[![Health](https://phpackages.com/badges/ddesrosiers-silex-annotation-provider/health.svg)](https://phpackages.com/packages/ddesrosiers-silex-annotation-provider)
```

###  Alternatives

[jdesrosiers/silex-cors-provider

A silex service provider that adds CORS services to silex

83892.3k10](/packages/jdesrosiers-silex-cors-provider)[jdesrosiers/silex-jms-serializer-provider

A silex service provider that integrates jms/serializer into silex

11126.3k2](/packages/jdesrosiers-silex-jms-serializer-provider)

PHPackages © 2026

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