3
我正在使用一些控制器的ACL,並且一直在徘徊是否有一種「乾淨」的方式來使用ACL,而無需反覆寫入相同的代碼。作爲服務實施的Symfony2 ACL?
我談論的ACL代碼
// creating the ACL
$aclProvider = $this->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($comment);
$acl = $aclProvider->createAcl($objectIdentity);
// retrieving the security identity of the currently logged-in user
$securityContext = $this->get('security.context');
$user = $securityContext->getToken()->getUser();
$securityIdentity = UserSecurityIdentity::fromAccount($user);
// grant owner access
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);
從
the sf2 cookbook.
會是一個好主意是實現此代碼作爲一個服務,然後如果需要擴展它,並用它來代替寫在每個控制器相同的代碼?
事實上,[我已經完成了它](https://github.com/Problematic/ProblematicAclManagerBundle) – Problematic 2012-02-24 15:57:04
@Problematic感謝您的鏈接,現在查看它。 – 2012-02-24 16:00:58
謝謝!這真太了不起了。好套餐。 – Tool 2012-02-24 16:48:57