Created
June 21, 2013 10:39
-
-
Save davidreuss/5830386 to your computer and use it in GitHub Desktop.
Silex controller skeleton
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 | |
use Silex\Application; | |
use Symfony\Component\HttpFoundation\Request; | |
abstract class MyController { | |
protected $request; | |
protected $application; | |
public function __construct(Request $req, Application $app) { | |
$this->request = $req; | |
$this->application = $app; | |
} | |
public function getApplication() { | |
return $this->application; | |
} | |
public function isPostRequest() { | |
return strtolower($this->request->getMethod() == 'post'); | |
} | |
public function getRequest() { | |
return $this->request; | |
} | |
public function willHandleRequest(Silex\Controller $controller) { | |
$controller->before(function() { | |
// do stuff | |
}); | |
} | |
public function handleRequest() { | |
// handle the actual request here | |
} | |
public function didHandleRequest(Silex\Controller $controller) { | |
$controller->after(function() { | |
// do stuff | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment