LazyLoadingMetadataFactory

class LazyLoadingMetadataFactory implements MetadataFactoryInterface

Creates new {@link ClassMetadataInterface} instances.

Whenever {@link getMetadataFor()} is called for the first time with a given class name or object of that class, a new metadata instance is created and returned. On subsequent requests for the same class, the same metadata instance will be returned.

You can optionally pass a {@link LoaderInterface} instance to the constructor. Whenever a new metadata instance is created, it is passed to the loader, which can configure the metadata based on configuration loaded from the filesystem or a database. If you want to use multiple loaders, wrap them in a {@link LoaderChain}.

You can also optionally pass a {@link CacheInterface} instance to the constructor. This cache will be used for persisting the generated metadata between multiple PHP requests.

Methods

__construct(LoaderInterface $loader = null, CacheInterface $cache = null)

Creates a new metadata factory.

MetadataInterface getMetadataFor(mixed $value)

Returns the metadata for the given value.

bool hasMetadataFor(mixed $value)

Returns whether the class is able to return metadata for the given value.

Details

__construct(LoaderInterface $loader = null, CacheInterface $cache = null)

Creates a new metadata factory.

Parameters

LoaderInterface $loader The loader for configuring new metadata
CacheInterface $cache The cache for persisting metadata between multiple PHP requests

MetadataInterface getMetadataFor(mixed $value)

Returns the metadata for the given value.

Parameters

mixed $value Some value

Return Value

MetadataInterface The metadata for the value

Exceptions

NoSuchMetadataException If no metadata exists for the given value

bool hasMetadataFor(mixed $value)

Returns whether the class is able to return metadata for the given value.

Parameters

mixed $value Some value

Return Value

bool Whether metadata can be returned for that value