PHP Class Dice\Dice

Afficher le fichier Open project: level-2/dice Class Usage Examples

Méthodes publiques

Méthode Description
addRule ( string $name, array $rule ) Add a rule $rule to the class $name
create ( $name, array $args = [], array $share = [] ) : object Returns a fully constructed object based on $name using $args and $share as constructor arguments if supplied
getRule ( $name ) : array Returns the rule that will be applied to the class $name when calling create()

Private Methods

Méthode Description
expand ( mixed $param, array $share = [], boolean $createFromString = false ) : mixed Looks for 'instance' array keys in $param and when found returns an object based on the value see {@link https:// r.je/dice.html#example3-1}
getClosure ( string $name, array $rule ) : callable Returns a closure for creating object $name based on $rule, caching the reflection object for later use
getParams ( ReflectionMethod $method, array $rule ) : callable Returns a closure that generates arguments for $method based on $rule and any $args passed into the closure

Method Details

addRule() public méthode

Add a rule $rule to the class $name
public addRule ( string $name, array $rule )
$name string The name of the class to add the rule for
$rule array The container can be fully configured using rules provided by associative arrays. See {@link https://r.je/dice.html#example3} for a description of the rules.

create() public méthode

Returns a fully constructed object based on $name using $args and $share as constructor arguments if supplied
public create ( $name, array $args = [], array $share = [] ) : object
$args array An array with any additional arguments to be passed into the constructor upon instantiation
$share array Whether or not this class instance be shared, so that the same instance is passed around each time
Résultat object A fully constructed object based on the specified input arguments

getRule() public méthode

Returns the rule that will be applied to the class $name when calling create()
public getRule ( $name ) : array
Résultat array The rules for the specified class