Skip to content

Instantly share code, notes, and snippets.

@zyphlar
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyphlar/036ce72a0a868b98490d to your computer and use it in GitHub Desktop.
Save zyphlar/036ce72a0a868b98490d to your computer and use it in GitHub Desktop.
Prototype of a Symfony2 PHP securitycontext filter helper
<?php
class SomeController {
private function filterSecurityContext($action, $items){
$user = $this->get('security.context')->getToken()->getUser();
$results = array();
foreach($items as $item){
if($this->get('security.context')->isGranted($action, $item)){
$results[] = $item;
}
}
return $results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment