abstract class PersistentObject implements EntityManagerAware (View source)

PersistentObject base class that implements getter/setter methods for all mapped fields and associations by overriding __call.

This class is a forward compatible implementation of the PersistentObject trait.

Limitations:

  1. All persistent objects have to be associated with a single EntityManager, multiple EntityManagers are not supported. You can set the EntityManager with PersistentObject#setEntityManager().
  2. Setters and getters only work if a ClassMetadata instance was injected into the PersistentObject. This is either done on postLoad of an object or by accessing the global object manager.
  3. There are no hooks for setters/getters. Just implement the method yourself instead of relying on __call().
  4. Slower than handcoded implementations: An average of 7 method calls per access to a field and 11 for an association.
  5. Only the inverse side associations get autoset on the owning side as well. Setting objects on the owning side will not set the inverse side associations.

Methods

static 
setEntityManager(EntityManagerInterface|null $entityManager = null)

Sets the entity manager responsible for all persistent object base classes.

static EntityManagerInterface|null
getEntityManager()

No description

injectEntityManager(EntityManagerInterface $entityManager, ClassMetadata $classMetadata)

Injects the Doctrine Object Manager.

mixed
__call(string $method, mixed[] $args)

Magic methods.

Details

static setEntityManager(EntityManagerInterface|null $entityManager = null)

Sets the entity manager responsible for all persistent object base classes.

Parameters

EntityManagerInterface|null $entityManager

static EntityManagerInterface|null getEntityManager()

Return Value

EntityManagerInterface|null

injectEntityManager(EntityManagerInterface $entityManager, ClassMetadata $classMetadata)

Injects the Doctrine Object Manager.

Parameters

EntityManagerInterface $entityManager
ClassMetadata $classMetadata

Exceptions

RuntimeException

mixed __call(string $method, mixed[] $args)

Magic methods.

Parameters

string $method
mixed[] $args

Return Value

mixed

Exceptions

BadMethodCallException