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
Table of Contents
Interfaces
- MetadataFactoryInterface
- Returns {@link \Symfony\Component\Validator\Mapping\MetadataInterface} instances for values.
Properties
- $cache : mixed
- $loadedClasses : array<string|int, ClassMetadata>
- The loaded metadata, indexed by class name.
- $loader : mixed
Methods
- __construct() : mixed
- 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()
public
__construct([LoaderInterface $loader = null ][, CacheItemPoolInterface $cache = null ]) : mixed
Parameters
- $loader : LoaderInterface = null
- $cache : CacheItemPoolInterface = null
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
Return values
MetadataInterfacehasMetadataFor()
Returns whether the class is able to return metadata for the given value.
public
hasMetadataFor(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolescapeClassName()
Replaces backslashes by dots in a class name.
private
escapeClassName(string $class) : string
Parameters
- $class : string
Return values
stringmergeConstraints()
private
mergeConstraints(ClassMetadata $metadata) : mixed
Parameters
- $metadata : ClassMetadata