How to stop Symfony project execution from a filter

When you need to stop execution of your project from a Symfony filter, for example, when you’re checking all requests to your application for some correct GUID, you need to do one simple thing:

* Checks the GUID and allow/deny the request
class sfCheckGUIDFilter extends sfFilter

public function execute($filterChain)
$sfContext = $this->getContext();
if ($this->isGUIDCorrect($sfContext->getRequest()->getParameter(‘GUID’))) {
} else {
$response = $sfContext->getResponse();
$response->setHttpHeader(‘Content-Type’, ‘text/plain’, true);
$response->setContent(‘Not allowed’);

private function isGUIDCorrect($guid) {
// TODO: implement your GUID checker

and in the filters.yml file of your application you just add this filter in a following way:

# You can find more information about this file on the symfony website:

rendering: ~
security: ~

# insert your own filters here
class: sfCheckGUIDFilter

cache: ~
execution: ~

In this case this filter is used for entire application. When you need to cover with checker only few actions please use other ways, like preExecute method of an Action.