Skip to content

Instantly share code, notes, and snippets.

@khepin
Created March 23, 2012 09:58
Show Gist options
  • Save khepin/2169164 to your computer and use it in GitHub Desktop.
Save khepin/2169164 to your computer and use it in GitHub Desktop.
<?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