PHPackages                             thispagecannotbefound/silex-action-controller - 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. thispagecannotbefound/silex-action-controller

ActiveLibrary[Framework](/categories/framework)

thispagecannotbefound/silex-action-controller
=============================================

Service provider for extended (class-) controller functionality.

0.0.0(12y ago)0901MITPHP

Since Oct 28Pushed 12y ago1 watchersCompare

[ Source](https://github.com/thispagecannotbefound/SilexActionController)[ Packagist](https://packagist.org/packages/thispagecannotbefound/silex-action-controller)[ Docs](http://github.com/thispagecannotbefound/SilexActionController)[ RSS](/packages/thispagecannotbefound-silex-action-controller/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

SilexActionController
=====================

[](#silexactioncontroller)

Extended controller functionality for [Silex](http://silex.sensiolabs.org).

Introduction -- workflow
------------------------

[](#introduction----workflow)

I have developed a personal workflow in which I organize my controllers in classes, while keeping Silex functionality. This is different from Silex's [ServiceControllerServiceProvider](http://silex.sensiolabs.org/doc/providers/service_controller.html), because that is meant to completely separate your controllers from the framework. In my controllers I want to have the framework functionality, for example to redirect requests or return a JSON response. Small example controller:

```
class UserController
{
	function getUser($name) {
		$user = $this->app['service.user']->getByName($name);

		if ($user) {
			return $this->app['twig']->render('user.twig');
		}

		return $this->app->redirect('/noUser');
	}
}

```

I like this way of organizing my code, which to some extent resembles Symfony 2's and Zend Framework 2's method of controller classes. This Silex extension makes this workflow less verbose.

README example classes
----------------------

[](#readme-example-classes)

To explain the usage of this extension, the following example classes are used:

#### Example\\ServiceController

[](#exampleservicecontroller)

```
namespace Example;

class ServiceController
{
	function show() {
		return __METHOD__;
	}
}

```

#### Example\\ActionController

[](#exampleactioncontroller)

```
namespace Example;

use Silex\Application;
use ThisPageCannotBeFound\Silex\ApplicationAwareInterface;

class ApplicationAwareController implements ApplicationAwareInterface
{
	protected $app;

	function setApplication(Application $app) {
		$this->app = $app;
	}

	function show() {
		return __METHOD__;
	}
}

```

Usage
-----

[](#usage)

### ActionControllerServiceProvider

[](#actioncontrollerserviceprovider)

First you'll need to register the provider with your app, after which you can define controllers:

```
use Silex\Application;
use ThisPageCannotBeFound\Silex\Provider\ActionControllerServiceProvider;

$app = new Application();

$app->register(new ActionControllerServiceProvider());

// Map controller, comparable to Silex's ServiceControllerServiceProvider,
// except by using just the controller class name. The service provider will
// create the class instance for you.
$app['controller.example.service'] = 'Example\\ServiceController';
$app['controller.example.action'] = 'Example\\ActionController';

```

#### Defining routes: 'service controller'

[](#defining-routes-service-controller)

```
// Map route to a class method.
$app->get('/example', 'controller.example.service:show');

```

#### Defining routes: 'action controller'

[](#defining-routes-action-controller)

```
// Map route to an entire class, method will be the action parameter.
$app->get('/example/{action}', 'controller.example.action');

```

### ApplicationAwareInterface

[](#applicationawareinterface)

Implement this interface to have the ActionControllerServiceProvider inject a Silex app instance into the class. (see ApplicationAwareController example class)

### AbstractController

[](#abstractcontroller)

This class provides helper methods to make the calls cleaner. It contains the Silex Application request - response methods (e.g. redirect, abort) and the methods from the default service providers, copied from their traits. It also implements the ApplicationAwareInterface, so it receives the Application instance upon instantiation. This class can be extended to add functionality to your controller classes.

Example - revised UserController:

```
class UserController extends AbstractController
{
	function getUser($name) {
		$user = $this->app['service.user']->getByName($name);

		if ($user) {
			return $this->render('user.twig');
		}

		return $this->redirect('/noUser');
	}
}

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

4629d ago

### Community

Maintainers

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

---

Top Contributors

[![thispagecannotbefound](https://avatars.githubusercontent.com/u/5628997?v=4)](https://github.com/thispagecannotbefound "thispagecannotbefound (6 commits)")

---

Tags

serviceprovidercontrollersilex

### Embed Badge

![Health badge](/badges/thispagecannotbefound-silex-action-controller/health.svg)

```
[![Health](https://phpackages.com/badges/thispagecannotbefound-silex-action-controller/health.svg)](https://phpackages.com/packages/thispagecannotbefound-silex-action-controller)
```

###  Alternatives

[ddesrosiers/silex-annotation-provider

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

28251.1k3](/packages/ddesrosiers-silex-annotation-provider)

PHPackages © 2026

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