PHP Class Dice\Dice

显示文件 Open project: level-2/dice Class Usage Examples

Public Methods

Method 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

Method 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 method

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 method

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
return object A fully constructed object based on the specified input arguments

getRule() public method

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