SchemaValidator
in package
Validate project XML against a caller-supplied trusted XSD or DTD.
Table of Contents
Constants
Methods
-
validate()
: array{valid: bool, errors: array
>} - Validate XML against a trusted local schema.
- collectErrors() : array<int, array<string, mixed>>
- Convert libxml errors to stable arrays.
-
failure()
: array{valid: bool, errors: array
>} - Build a single stable validation failure.
- insertDoctype() : string
- Insert a trusted DOCTYPE after the XML declaration when present.
- localFileUri() : string
- Convert an absolute local path to a file URI.
-
validateDtd()
: array{valid: bool, errors: array
>} - Validate XML against DTD.
-
validateXsd()
: array{valid: bool, errors: array
>} - Validate XML against XSD.
Constants
TYPE_DTD
public
mixed
TYPE_DTD
= 'dtd'
TYPE_XSD
public
mixed
TYPE_XSD
= 'xsd'
Methods
validate()
Validate XML against a trusted local schema.
public
validate(string $xmlContent, string $schemaPath[, string $type = self::TYPE_XSD ]) : array{valid: bool, errors: array>}
Parameters
- $xmlContent : string
-
XML content.
- $schemaPath : string
-
Trusted local XSD or DTD path.
- $type : string = self::TYPE_XSD
-
Schema type.
Return values
array{valid: bool, errors: arraycollectErrors()
Convert libxml errors to stable arrays.
private
collectErrors() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>failure()
Build a single stable validation failure.
private
failure(string $code, string $message) : array{valid: bool, errors: array>}
Parameters
- $code : string
-
Error code.
- $message : string
-
Error message.
Return values
array{valid: bool, errors: arrayinsertDoctype()
Insert a trusted DOCTYPE after the XML declaration when present.
private
insertDoctype(string $xml, string $doctype) : string
Parameters
- $xml : string
-
XML content without a DOCTYPE.
- $doctype : string
-
Trusted DOCTYPE declaration.
Return values
stringlocalFileUri()
Convert an absolute local path to a file URI.
private
localFileUri(string $path) : string
Parameters
- $path : string
-
Absolute local path.
Return values
stringvalidateDtd()
Validate XML against DTD.
private
validateDtd(string $xmlContent, string $schemaPath) : array{valid: bool, errors: array>}
The package-supplied DOCTYPE is removed and replaced with the trusted local DTD path supplied by the caller.
Parameters
- $xmlContent : string
-
XML content.
- $schemaPath : string
-
Trusted DTD path.
Return values
array{valid: bool, errors: arrayvalidateXsd()
Validate XML against XSD.
private
validateXsd(string $xmlContent, string $schemaPath) : array{valid: bool, errors: array>}
Parameters
- $xmlContent : string
-
XML content.
- $schemaPath : string
-
Trusted XSD path.