-
-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DoctrineObjectConstructor: how to use it without Symfony, in a PHP project #741
Comments
Are you using the serializer builder class? |
The serializer builder has a method "setobjectconstructor", pass to this method an instance of the doctrine object constructor |
Thank you for your fast response. Yes, that's what I am trying to do, but I can't find a way to instantiate it (DoctrineObjectConstructor so). To be exact, I don't know what to give to the first param $managerRegistry:
Thank you. |
The interface is relatively simple, you have to provide an implementation depending on the framework you are using. If you are using symfony, zend, Silex or laravel, there are various implementation available. |
The implementation should be trivial, since is just a registry of doctrine entity managers and connections. If you have one single entity manager and you are not aiming for lazy loading, then should be even easier |
https://github.com/saxulum/saxulum-doctrine-orm-manager-registry-provider is an example for silex |
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManager;
class SimpleManagerRegistry implements ManagerRegistry
{
/**
* @var EntityManager
*/
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function getDefaultConnectionName()
{
return 'blah';
}
public function getConnection($name = null)
{
return $this->entityManager->getConnection();
}
public function getConnections()
{
return [$this->getDefaultConnectionName() => $this->getConnection()];
}
public function getConnectionNames()
{
return [$this->getDefaultConnectionName()];
}
public function getDefaultManagerName()
{
return 'em';
}
public function getManager($name = null)
{
return $this->entityManager;
}
public function getManagers()
{
return [$this->getDefaultManagerName() => $this->entityManager];
}
public function resetManager($name = null)
{
// todo
}
public function getAliasNamespace($alias)
{
return 'App';
}
public function getManagerNames()
{
return [$this->getDefaultManagerName()];
}
public function getRepository($persistentObject, $persistentManagerName = null)
{
return $this->entityManager->getRepository(ClassUtils::getRealClass($persistentObject));
}
public function getManagerForClass($class)
{
return $this->entityManager->getRepository($class);
}
} This can be a skeleton... i suggest you to do something better, but is a starting point |
Thank you, I will look at it right away and let you know how it goes.. |
Should I use Doctrine\Common\Persistence\AbstractManagerRegistry? |
up to you, using |
Finally a simple implementation of ManagerRegistry was enough. Just need to clean this up and refactor a bit. Thank you for your help! :) |
Hello JodyLognoul, |
Hello JMS,
In order to attach a deserialized existing entity to doctrine entity manager, I would like to use the DoctrineObjectConstructor (instantiate it, and give it to the SerializerBuilder). How can I do it? Do I have to give an implementation to ManagerRegistry interface?
Thank you ! (And thank you for the lib)!
The text was updated successfully, but these errors were encountered: