Created
March 23, 2012 09:58
-
-
Save khepin/2169164 to your computer and use it in GitHub Desktop.
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 | |
namespace Khepin; | |
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface; | |
use Symfony\Component\Security\Acl\Domain\ObjectIdentity; | |
class DoctrineProxyIdRetrievalStrategy implements ObjectIdentityRetrievalStrategyInterface { | |
const PROXY_CLASS_NAME = 'Doctrine\ORM\Proxy\Proxy'; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function getObjectIdentity($domainObject) { | |
if (!is_object($domainObject)) { | |
return null; | |
} | |
if ($domainObject instanceof DomainObjectInterface) { | |
return new ObjectIdentity($domainObject->getObjectIdentifier(), $this->getObjectClass($domainObject)); | |
} elseif (method_exists($domainObject, 'getId')) { | |
return new ObjectIdentity($domainObject->getId(), $this->getObjectClass($domainObject)); | |
} | |
return null; | |
} | |
protected function getObjectClass($domainObject){ | |
if(in_array(self::PROXY_CLASS_NAME, class_implements($domainObject))){ | |
return get_parent_class($domainObject); | |
} | |
return get_class($domainObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment