mediatekformation

PersistentObject
in package
implements ObjectManagerAware

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 ObjectManager, multiple ObjectManagers are not supported. You can set the ObjectManager with PersistentObject#setObjectManager().
  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.
Tags
deprecated

Deprecated PersistentObject class in 1.2. Please implement this functionality directly in your application if you want ActiveRecord style functionality.

example

PersistentObject::setObjectManager($em);

class Foo extends PersistentObject { private $id; }

$foo = new Foo(); $foo->getId(); // method exists through __call

Interfaces, Classes, Traits and Enums

ObjectManagerAware
Makes a Persistent Objects aware of its own object-manager.

Table of Contents

$cm  : ClassMetadata<string|int, object>|null
$objectManager  : ObjectManager|null
__call()  : mixed
Magic methods.
getObjectManager()  : ObjectManager|null
injectObjectManager()  : void
Injects the Doctrine Object Manager.
setObjectManager()  : void
Sets the object manager responsible for all persistent object base classes.
add()  : void
Adds an object to a collection.
completeOwningSide()  : void
If this is an inverse side association, completes the owning side.
get()  : mixed
Gets a persistent field value.
initializeDoctrine()  : void
Initializes Doctrine Metadata for this class.
set()  : void
Sets a persistent fields value.

Properties

$cm

private ClassMetadata<string|int, object>|null $cm = null
Tags
psalm-var

ClassMetadata|null

Methods

__call()

Magic methods.

public __call(string $method, array<string|int, mixed> $args) : mixed
Parameters
$method : string
$args : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

setObjectManager()

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

public static setObjectManager([ObjectManager|null $objectManager = null ]) : void
Parameters
$objectManager : ObjectManager|null = null
Return values
void

add()

Adds an object to a collection.

private add(string $field, array<string|int, mixed> $args) : void
Parameters
$field : string
$args : array<string|int, mixed>
Tags
throws
BadMethodCallException
throws
InvalidArgumentException
Return values
void

completeOwningSide()

If this is an inverse side association, completes the owning side.

private completeOwningSide(string $field, string $targetClass, object $targetObject) : void
Parameters
$field : string
$targetClass : string
$targetObject : object
Tags
psalm-param

class-string $targetClass

Return values
void

get()

Gets a persistent field value.

private get(string $field) : mixed
Parameters
$field : string
Tags
throws
BadMethodCallException

When no persistent field exists by that name.

Return values
mixed

initializeDoctrine()

Initializes Doctrine Metadata for this class.

private initializeDoctrine() : void
Tags
throws
RuntimeException
Return values
void

set()

Sets a persistent fields value.

private set(string $field, array<string|int, mixed> $args) : void
Parameters
$field : string
$args : array<string|int, mixed>
Tags
throws
BadMethodCallException

When no persistent field exists by that name.

throws
InvalidArgumentException

When the wrong target object type is passed to an association.

Return values
void

Search results