Configure
in package
Utility for configuring things.
Table of Contents
Methods
- all() : array<string|int, object>
- Configure all objects in an array.
- configure() : object
- Configure an object.
- create() : T
- Instance a single object.
- createAll() : array<string|int, T>
- Create lots of objects with these configs.
- initAll() : void
- Initialize all objects in an array.
- instance() : T
- Construct a new instance of this class.
- update() : void
- Set variables on an object.
Methods
all()
Configure all objects in an array.
public
static all(array<string|int, array<string|int, mixed>|object|string> $configs[, class-string|null $assert = null ][, bool $init = true ]) : array<string|int, object>
Parameters
- $configs : array<string|int, array<string|int, mixed>|object|string>
- $assert : class-string|null = null
- $init : bool = true
Return values
array<string|int, object>configure()
Configure an object.
public
static configure(string|array<string|int, mixed>|object $config[, class-string|null $assert = null ][, bool $init = true ]) : object
If 'configurable' this will use the 'update()' method. Otherwise it'll set properties directly on the object.
The config is a key-value array, for example:
[
'\\My\\Big\\Class' => [
'foo' => 'bar',
'baz' => 'qux',
]
]
Given a string the 'config' is implicitly an empty array.
Parameters
- $config : string|array<string|int, mixed>|object
-
[ class => config ]
- $assert : class-string|null = null
-
class name to verify
- $init : bool = true
-
whether to initialize the object after creation
Tags
Return values
objectcreate()
Instance a single object.
public
static create(T> $class, array<string|int, mixed> $config) : T
Parameters
- $class : T>
- $config : array<string|int, mixed>
Tags
Return values
TcreateAll()
Create lots of objects with these configs.
public
static createAll(T> $class, array<string|int, array<string|int, mixed>> $items) : array<string|int, T>
Parameters
- $class : T>
- $items : array<string|int, array<string|int, mixed>>
Tags
Return values
array<string|int, T>initAll()
Initialize all objects in an array.
public
static initAll(array<string|int, object> $objects[, bool $force = false ]) : void
This only calls init() on objects that implement ConfigurableInit.
Optionally provide 'force' to call with a method_exists check. This
provides compatibility with external code that doesn't implement these
configurable interfaces.
Parameters
- $objects : array<string|int, object>
- $force : bool = false
-
always init
instance()
Construct a new instance of this class.
public
static instance(T> $class[, class-string|array<string|int, class-string> $assert = null ]) : T
Parameters
- $class : T>
- $assert : class-string|array<string|int, class-string> = null
Tags
Return values
Tupdate()
Set variables on an object.
public
static update(object $object, array<string|int, mixed> $config) : void
This will use the Configurable interface or falls back to
dynamic properties.
Note, in PHP 8.2 you will need the #[\AllowDynamicProperties]
attribute to set dynamic properties. Even then, this behaviour
is deprecated.
Parameters
- $object : object
- $config : array<string|int, mixed>