Skip to content

Instantly share code, notes, and snippets.

@gyndav
Created November 9, 2012 09:26
Show Gist options
  • Save gyndav/4044758 to your computer and use it in GitHub Desktop.
Save gyndav/4044758 to your computer and use it in GitHub Desktop.
Other implementation for decoupling controllers in Silex
# app.php
$app->mount('/', new MyCompany\ControllerProvider\MyClassControllerProvider());
<?php
namespace MyCompany\ControllerProvider;
use Silex\ControllerProviderInterface,
Silex\ControllerCollection,
Silex\Application,
Silex\Route;
/**
* My class
*/
class MyClassControllerProvider implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = new ControllerCollection(new Route());
/**
* Closure logic for my-uri
*/
$controllers->match('/my-uri', function () use ($app) {
// Business logic goes there
})
->bind('my_uri')
->method('GET');
return $controllers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment