Neuron-PHP

Factory
in package

Factory class for creating Data Transfer Objects (DTOs) from YAML configuration files or arrays.

This factory can read YAML files containing DTO definitions OR accept arrays with DTO definitions, and creates corresponding Dto objects with properties, validation rules, and nested structures.

Table of Contents

Properties

$dtoCache  : array<string|int, mixed>
$source  : string|array<string|int, mixed>

Methods

__construct()  : mixed
create()  : Dto
getSource()  : string|array<string|int, mixed>
createArray()  : Collection
createDto()  : Dto
createProperty()  : Property
isAbsolutePath()  : bool
Check if a path is absolute
loadReferencedDto()  : Dto
Load a referenced DTO from a file path, with caching
resolveReferencePath()  : string
Resolve a reference path relative to the current source
setLengthRange()  : Property
setValueRange()  : mixed

Properties

$dtoCache

private static array<string|int, mixed> $dtoCache = []

$source

private string|array<string|int, mixed> $source

Methods

__construct()

public __construct(string|array<string|int, mixed> $source) : mixed
Parameters
$source : string|array<string|int, mixed>

YAML file path or array of DTO properties

create()

public create() : Dto
Tags
throws
Exception
Return values
Dto

getSource()

public getSource() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed>

createArray()

protected createArray(string $name, array<string|int, mixed> $data) : Collection
Parameters
$name : string
$data : array<string|int, mixed>
Tags
throws
Validation
Return values
Collection

createDto()

protected createDto(string $name, array<string|int, mixed> $data) : Dto
Parameters
$name : string
$data : array<string|int, mixed>
Tags
throws
Exception
Return values
Dto

createProperty()

protected createProperty(int|string $name, array<string|int, mixed> $propertyData, Dto $parent) : Property
Parameters
$name : int|string
$propertyData : array<string|int, mixed>
$parent : Dto
Tags
throws
Validation
Return values
Property

isAbsolutePath()

Check if a path is absolute

protected isAbsolutePath(string $path) : bool
Parameters
$path : string
Return values
bool

loadReferencedDto()

Load a referenced DTO from a file path, with caching

protected loadReferencedDto(string $ref) : Dto
Parameters
$ref : string

The reference path to the DTO YAML file

Tags
throws
Exception
Return values
Dto

resolveReferencePath()

Resolve a reference path relative to the current source

protected resolveReferencePath(string $ref) : string
Parameters
$ref : string
Return values
string

setLengthRange()

protected setLengthRange(array<string|int, mixed> $propertyData, Property $property) : Property
Parameters
$propertyData : array<string|int, mixed>
$property : Property
Return values
Property

setValueRange()

protected setValueRange(array<string|int, mixed> $propertyData, Property $property) : mixed
Parameters
$propertyData : array<string|int, mixed>
$property : Property

        
On this page

Search results