LazyLoadingMetadataFactory
in package
implements
MetadataFactoryInterface
Creates new {@link ClassMetadataInterface} instances.
Whenever 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 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 .
You can also optionally pass a instance to the constructor. This cache will be used for persisting the generated metadata between multiple PHP requests.
Tags
Interfaces, Classes, Traits and Enums
- MetadataFactoryInterface
- Returns {@link \Symfony\Component\Validator\Mapping\MetadataInterface} instances for values.
Table of Contents
- $cache : mixed
- $loadedClasses : array<string|int, ClassMetadata>
- The loaded metadata, indexed by class name.
- $loader : mixed
- __construct() : mixed
- Creates a new metadata factory.
- getMetadataFor() : MetadataInterface
- Returns the metadata for the given value.
- hasMetadataFor() : bool
- Returns whether the class is able to return metadata for the given value.
- escapeClassName() : string
- Replaces backslashes by dots in a class name.
- mergeConstraints() : mixed
Properties
$cache
protected
mixed
$cache
$loadedClasses
The loaded metadata, indexed by class name.
protected
array<string|int, ClassMetadata>
$loadedClasses
= []
$loader
protected
mixed
$loader
Methods
__construct()
Creates a new metadata factory.
public
__construct([LoaderInterface $loader = null ][, CacheItemPoolInterface|null $cache = null ]) : mixed
Parameters
- $loader : LoaderInterface = null
- $cache : CacheItemPoolInterface|null = null
-
The cache for persisting metadata between multiple PHP requests
Return values
mixed —getMetadataFor()
Returns the metadata for the given value.
public
getMetadataFor(mixed $value) : MetadataInterface
If the method was called with the same class name (or an object of that class) before, the same metadata instance is returned.
If the factory was configured with a cache, this method will first look for an existing metadata instance in the cache. If an existing instance is found, it will be returned without further ado.
Otherwise, a new metadata instance is created. If the factory was configured with a loader, the metadata is passed to the method for further configuration. At last, the new object is returned.
Parameters
- $value : mixed
-
Some value
Return values
MetadataInterface —The metadata for the value
hasMetadataFor()
Returns whether the class is able to return metadata for the given value.
public
hasMetadataFor(mixed $value) : bool
Parameters
- $value : mixed
-
Some value
Return values
bool —Whether metadata can be returned for that value
escapeClassName()
Replaces backslashes by dots in a class name.
private
escapeClassName(string $class) : string
Parameters
- $class : string
Return values
string —mergeConstraints()
private
mergeConstraints(ClassMetadata $metadata) : mixed
Parameters
- $metadata : ClassMetadata