類AceBuilderListener實現EventSubscriber {
private $container;
public function setContainer($container){
$his->container = $container;
}
public function getSubscribedEvents()
{
return array(
Events::prePersist,
Events::preUpdate,
Events::preRemove,
Events::postPersist,
Events::postUpdate,
Events::postRemove,
Events::loadClassMetadata,
);
}
public function prePersist(){ echo(get_class($entity)); }
public function preUpdate(){ echo(get_class($entity)); }
public function preRemove(){ echo(get_class($entity)); }
public function postPersist(){ echo(get_class($entity)); }
public function postUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
echo get_class($entity);
// perhaps you only want to act on some "Product" entity
if ($entity instanceof Product | x) {
// ... do something with the Product
}
}
public function postRemove(){ die(get_class($entity)); }
public function loadClassMetadata(LoadClassMetadataEventArgs $args){
$classMetadata = $args->getClassMetadata();
$entityManager = $args->getEntityManager();
$user = $this->container->get('security.context')->getToken()->getUser();
// you can check here if isGranted();
// and get the entity from the object $classMetadata
$this->container->get('security.context')->isGranted('EDIT', $entity);
}
}
好主意,但算不上什麼我要找的。我通過在security.yml中設置常規訪問規則解決了這個問題,使用JMSSecurityExtraBundle爲特定控制器註釋以及單個對象的ACL。 – 2012-08-16 15:50:58
@ serious.siriso考慮發佈你的問題的答案! – JeanValjean 2013-01-20 14:26:17