class XmlFileLoader extends FileLoader

Loads validation metadata from an XML file.

Constants

DEFAULT_NAMESPACE

The namespace to load constraints from by default.

Properties

protected $namespaces from AbstractLoader
protected $file from FileLoader
protected SimpleXMLElement[]|null $classes The XML nodes of the mapping file.

Methods

addNamespaceAlias(string $alias, string $namespace)

Adds a namespace alias.

newConstraint(string $name, mixed $options = null)

Creates a new constraint instance for the given constraint name.

__construct(string $file)

Creates a new loader.

bool
loadClassMetadata(ClassMetadata $metadata)

Loads validation metadata into a {@link ClassMetadata} instance.

array
parseConstraints(SimpleXMLElement $nodes)

Parses a collection of "constraint" XML nodes.

array
parseValues(SimpleXMLElement $nodes)

Parses a collection of "value" XML nodes.

array
parseOptions(SimpleXMLElement $nodes)

Parses a collection of "option" XML nodes.

parseFile(string $path)

Loads the XML class descriptions from the given file.

Details

in AbstractLoader at line 50
protected addNamespaceAlias(string $alias, string $namespace)

Adds a namespace alias.

The namespace alias can be used to reference constraints from specific namespaces in {@link newConstraint()}:

$this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\');

$constraint = $this->newConstraint('mynamespace:NotNull');

Parameters

string $alias The alias
string $namespace The PHP namespace

in AbstractLoader at line 70
protected Constraint newConstraint(string $name, mixed $options = null)

Creates a new constraint instance for the given constraint name.

Parameters

string $name The constraint name. Either a constraint relative to the default constraint namespace, or a fully qualified class name. Alternatively, the constraint may be preceded by a namespace alias and a colon. The namespace alias must have been defined using {@link addNamespaceAlias()}.
mixed $options The constraint options

Return Value

Constraint

Exceptions

MappingException If the namespace prefix is undefined

in FileLoader at line 35
__construct(string $file)

Creates a new loader.

Parameters

string $file The mapping file to load

Exceptions

MappingException If the file does not exist or is not readable

at line 35
bool loadClassMetadata(ClassMetadata $metadata)

Loads validation metadata into a {@link ClassMetadata} instance.

Parameters

ClassMetadata $metadata

Return Value

bool Whether the loader succeeded

at line 71
protected array parseConstraints(SimpleXMLElement $nodes)

Parses a collection of "constraint" XML nodes.

Parameters

SimpleXMLElement $nodes The XML nodes

Return Value

array The Constraint instances

at line 105
protected array parseValues(SimpleXMLElement $nodes)

Parses a collection of "value" XML nodes.

Parameters

SimpleXMLElement $nodes The XML nodes

Return Value

array The values

at line 139
protected array parseOptions(SimpleXMLElement $nodes)

Parses a collection of "option" XML nodes.

Parameters

SimpleXMLElement $nodes The XML nodes

Return Value

array The options

at line 174
protected SimpleXMLElement parseFile(string $path)

Loads the XML class descriptions from the given file.

Parameters

string $path The path of the XML file

Return Value

SimpleXMLElement The class descriptions

Exceptions

MappingException If the file could not be loaded