Created
November 9, 2012 09:26
-
-
Save gyndav/4044758 to your computer and use it in GitHub Desktop.
Other implementation for decoupling controllers in Silex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app.php | |
$app->mount('/', new MyCompany\ControllerProvider\MyClassControllerProvider()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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