Created
July 10, 2012 10:20
-
-
Save stephpy/3082511 to your computer and use it in GitHub Desktop.
parameters.yml
This file contains hidden or 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
# security | |
security.acl.object_identity_retrieval_strategy.class: Acme\Bundle\MainBundle\Security\ObjectIdentityRetrievalStrategy |
This file contains hidden or 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 | |
/* | |
* This file is part of the Symfony package. | |
* | |
* (c) Fabien Potencier <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Acme\Bundle\MainBundle\Security; | |
use Symfony\Component\Security\Acl\Exception\InvalidDomainObjectException; | |
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface; | |
use Symfony\Component\Security\Acl\Domain\ObjectIdentity; | |
/** | |
* Strategy to be used for retrieving object identities from domain objects | |
* | |
* @author Johannes M. Schmitt <[email protected]> | |
*/ | |
class ObjectIdentityRetrievalStrategy implements ObjectIdentityRetrievalStrategyInterface | |
{ | |
/** | |
* {@inheritDoc} | |
*/ | |
public function getObjectIdentity($domainObject) | |
{ | |
try { | |
if($domainObject instanceof \Doctrine\ORM\Proxy\Proxy) { | |
$refl = new \ReflectionClass($domainObject); | |
$className = $refl->getParentClass()->getName(); | |
return new ObjectIdentity($domainObject->getId(), $className); | |
} | |
return ObjectIdentity::fromDomainObject($domainObject); | |
} catch (InvalidDomainObjectException $failed) { | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment