Documentation

Dice
in package

Table of Contents

Constants

CHAIN_CALL  = 'Dice::CHAIN_CALL'
CONSTANT  = 'Dice::CONSTANT'
GLOBAL  = 'Dice::GLOBAL'
INSTANCE  = 'Dice::INSTANCE'
SELF  = 'Dice::SELF'

Properties

$cache  : array<string|int, mixed>
$instances  : array<string|int, mixed>
$rules  : array<string|int, mixed>

Methods

addRule()  : self
Add a rule $rule to the class $name
addRules()  : self
Add rules as array. Useful for JSON loading $dice->addRules(json_decode(file_get_contents('foo.json'));
create()  : object
Returns a fully constructed object based on $name using $args and $share as constructor arguments if supplied
getRule()  : array<string|int, mixed>
Returns the rule that will be applied to the class $name when calling create()
addRuleTo()  : mixed
expand()  : mixed
Looks for Dice::INSTANCE, Dice::GLOBAL or Dice::CONSTANT array keys in $param and when found returns an object based on the value see {@link https:// r.je/dice.html#example3-1}
getClosure()  : callable
Returns a closure for creating object $name based on $rule, caching the reflection object for later use
getParams()  : callable
Returns a closure that generates arguments for $method based on $rule and any $args passed into the closure
matchParam()  : mixed
Looks through the array $search for any object which can be used to fulfil $param The original array $search is modifed so must be passed by reference.

Constants

CHAIN_CALL

public mixed CHAIN_CALL = 'Dice::CHAIN_CALL'

CONSTANT

public mixed CONSTANT = 'Dice::CONSTANT'

GLOBAL

public mixed GLOBAL = 'Dice::GLOBAL'

INSTANCE

public mixed INSTANCE = 'Dice::INSTANCE'

SELF

public mixed SELF = 'Dice::SELF'

Properties

$cache

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

A cache of closures based on class name so each class is only reflected once

$instances

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

Stores any instances marked as 'shared' so create() can return the same instance

$rules

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

Rules which have been set using addRule()

Methods

addRule()

Add a rule $rule to the class $name

public addRule(string $name, array<string|int, mixed> $rule) : self
Parameters
$name : string

The name of the class to add the rule for

$rule : array<string|int, mixed>

The container can be fully configured using rules provided by associative arrays. See for a description of the rules.

Return values
self

addRules()

Add rules as array. Useful for JSON loading $dice->addRules(json_decode(file_get_contents('foo.json'));

public addRules(mixed $rules) : self
Parameters
$rules : mixed
Return values
self

create()

Returns a fully constructed object based on $name using $args and $share as constructor arguments if supplied

public create(string $name[, array<string|int, mixed> $args = [] ][, array<string|int, mixed> $share = [] ]) : object
Parameters
$name : string
$args : array<string|int, mixed> = []

An array with any additional arguments to be passed into the constructor upon instantiation

$share : array<string|int, mixed> = []

a list of defined in shareInstances for objects higher up the object graph, should only be used internally

Return values
object

A fully constructed object based on the specified input arguments

getRule()

Returns the rule that will be applied to the class $name when calling create()

public getRule(string $name) : array<string|int, mixed>
Parameters
$name : string
Return values
array<string|int, mixed>

The rules for the specified class

addRuleTo()

private addRuleTo(Dice $dice, string $name, array<string|int, mixed> $rule) : mixed
Parameters
$dice : Dice
$name : string
$rule : array<string|int, mixed>

expand()

Looks for Dice::INSTANCE, Dice::GLOBAL or Dice::CONSTANT array keys in $param and when found returns an object based on the value see {@link https:// r.je/dice.html#example3-1}

private expand(mixed $param[, array<string|int, mixed> $share = [] ][, bool $createFromString = false ]) : mixed
Parameters
$param : mixed

Either a string or an array,

$share : array<string|int, mixed> = []

Array of instances from 'shareInstances', required for calls to create

$createFromString : bool = false

getClosure()

Returns a closure for creating object $name based on $rule, caching the reflection object for later use

private getClosure(string $name, array<string|int, mixed> $rule) : callable
Parameters
$name : string

the Name of the class to get the closure for

$rule : array<string|int, mixed>

The container can be fully configured using rules provided by associative arrays. See for a description of the rules.

Return values
callable

A closure

getParams()

Returns a closure that generates arguments for $method based on $rule and any $args passed into the closure

private getParams(object $method, array<string|int, mixed> $rule) : callable
Parameters
$method : object

An instance of ReflectionMethod (see: php.net/manual/en/class.reflectionmethod.php)

$rule : array<string|int, mixed>

The container can be fully configured using rules provided by associative arrays. See for a description of the rules.

Return values
callable

A closure that uses the cached information to generate the arguments for the method

matchParam()

Looks through the array $search for any object which can be used to fulfil $param The original array $search is modifed so must be passed by reference.

private matchParam(ReflectionParameter $param, mixed $class, array<string|int, mixed> &$search) : mixed
Parameters
$param : ReflectionParameter
$class : mixed
$search : array<string|int, mixed>

        
On this page

Search results