PHPackages                             bcen/silex-dispatcher - 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. bcen/silex-dispatcher

AbandonedArchivedLibrary[Framework](/categories/framework)

bcen/silex-dispatcher
=====================

A Silex plugin

0.5.1(12y ago)7379MITPHP

Since Feb 1Pushed 12y agoCompare

[ Source](https://github.com/bcen/silex-dispatcher)[ Packagist](https://packagist.org/packages/bcen/silex-dispatcher)[ Docs](https://github.com/bcen/silex-dispatcher)[ RSS](/packages/bcen-silex-dispatcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (14)Versions (19)Used By (0)

Silex-Dispatcher
================

[](#silex-dispatcher)

[![Build Status](https://camo.githubusercontent.com/2afd43017fbf41bdc3ffde763a51d3924fbeb5bba579819141906d8a73c15964/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6263656e2f73696c65782d646973706174636865722e706e67)](http://travis-ci.org/bcen/silex-dispatcher)

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

[](#installation)

Via [Composer](http://getcomposer.org/):

```
{
    "require": {
        "bcen/silex-dispatcher": "0.5.*"
    }
}

```

Then run `$ composer.phar install`

Usage
-----

[](#usage)

```
$app->register(new \SDispatcher\SDispatcherServiceProvider());
```

Features
--------

[](#features)

- Django-alike CBV controller

    ```
    class HomeController
    {
        public function get(Request $req)
        {
            return 'Hi, '.$req->getClientIp();
        }

        public function post(Request $req)
        {
            return 'This is a post';
        }
    }

    $app->match('/', 'HomeController');
    ```

    *Handle missing method*:

    ```
    class HomeController
    {
        public function get(Request $req)
        {
        }

        public function handleMissingMethod(Request $req)
        {
            // HEAD, OPTIONS, PUT, POST everything goes here
            // except GET, which is handle by the above method.
        }
    }
    ```
- Hybrid-alike Service Locator/Dependency Injection pattern

    ```
    $app['my_obj'] = function () {
        $obj = new \stdClass;
        $obj->message = 'hi';
        return $obj;
    };

    class HomeController implements \SDispatcher\Common\RequiredServiceMetaProviderInterface
    {
        public function __construct(\stdClass $obj)
        {
            var_dump($obj);
        }

        public function get($req)
        {
            return 'Hi, '.$req->getClientIp();
        }

        public static function getRequiredServices()
        {
            return array('my_obj');
        }
    }

    $app->match('/', 'HomeController');

    // or by annotation

    use SDispatcher\Common\Annotation as REST;

    /**
     * @REST\RequiredServices("my_obj")
     */
    class HomeController
    {
        public function __construct(\stdClass $obj)
        {
            var_dump($obj);
        }

        public function get($req)
        {
            return 'Hi, '.$req->getClientIp();
        }
    }
    ```
- Helpers/Middlewares for creating "RESTful" API

    ```
    require __DIR__ . '/vendor/autoload.php';

    class NumberListResource
    {
        public function get()
        {
            return array(1, 2, 3, 4, 5, 6);
        }
    }

    class NumberDetailResource
    {
        public function get(Request $req, $nid)
        {
            return new \SDispatcher\DataResponse(array(
                'id' => $nid,
                'value' => 'some value',
                'filters' => $req->query->all(),
            ));
        }
    }

    $app = new \Silex\Application();
    $app->register(new \SDispatcher\SDispatcherServiceProvider());
    $app['controllers']->setOption('sdispatcher.route.rest', true);

    $app->match('/numbers', 'NumberListResource');
    $app->match('/numbers/{nid}', 'NumberDetailResource');

    $app->run();
    ```

    *Content Negotiation*:

    ```
    $ curl local.domain.org/api-test/numbers/1 -H "Accept:application/xml" -i
    HTTP/1.1 406 Not Acceptable
    Date: Sat, 18 May 2013 00:28:58 GMT
    Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
    X-Powered-By: PHP/5.4.7
    Cache-Control: no-cache
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    ```

    *Automated Serialization*:

    ```
    $ curl local.domain.org/api-test/numbers/1 -H "Accept:application/json" -i
    HTTP/1.1 200 OK
    Date: Sat, 18 May 2013 00:29:30 GMT
    Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
    X-Powered-By: PHP/5.4.7
    Cache-Control: no-cache
    Content-Length: 50
    Content-Type: application/json

    {"id":"some_id","value":"some value","filters":[]}
    ```

    *Automated Pagination*:

    ```
    $ curl local.domain.org/api-test/numbers
    {"meta":{"offset":0,"limit":20,"total":6,"prevLink":null,"nextLink":null},"objects":[1,2,3,4,5,6]}
    ```

    *Automated 405 Response for missing method handler*:

    ```
    $ curl local.domain.org/api-test/numbers -i -X POST
    HTTP/1.1 405 Method Not Allowed
    Date: Sat, 18 May 2013 01:21:20 GMT
    Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
    X-Powered-By: PHP/5.4.7
    Cache-Control: no-cache
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    ```

    **NOTE**: Remember to turn on URL rewrite!!

Known Issues:
-------------

[](#known-issues)

- Incompaitible with some other resolvers
- `FilterControllerEvent::getController` will return a closure due to `SilexCbvControllerResolver` wraps the actual class controller instance with closure.

Testing
-------

[](#testing)

```
$ composer.phar install --dev
$ vendor/bin/phpspec
$ vendor/bin/behat

```

License
-------

[](#license)

Silex-Dispatcher is licensed under the MIT license.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~9 days

Total

17

Last Release

4700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d050227e0a8e153eb088072eb77df2342324db2eb690b6708937729310f44cb?d=identicon)[bcen](/maintainers/bcen)

---

Top Contributors

[![bcen](https://avatars.githubusercontent.com/u/2433267?v=4)](https://github.com/bcen "bcen (202 commits)")

---

Tags

controllerrestful

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/bcen-silex-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/bcen-silex-dispatcher/health.svg)](https://phpackages.com/packages/bcen-silex-dispatcher)
```

###  Alternatives

[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k235.4M9.7k](/packages/symfony-framework-bundle)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19562.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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