Skip to content

Instantly share code, notes, and snippets.

@stephpy
Created July 10, 2012 10:20
Show Gist options
  • Save stephpy/3082511 to your computer and use it in GitHub Desktop.
Save stephpy/3082511 to your computer and use it in GitHub Desktop.
parameters.yml
# security
security.acl.object_identity_retrieval_strategy.class: Acme\Bundle\MainBundle\Security\ObjectIdentityRetrievalStrategy
<?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