Lottery
Properties
$chances int|float
The number of expected wins.
$outOf int|null
The number of potential opportunities to win.
$winner null|callable
The winning callback.
$loser null|callable
The losing callback.
$resultFactory callable|null
The factory that should be used to generate results.
Methods
__construct ( $chances , $outOf ) : void
Create a new Lottery instance.
Parameters
- $chances int|float
- $outOf int|null
odds ( $chances , $outOf ) : static
Create a new Lottery instance.
Parameters
- $chances int|float
- $outOf int|null
winner ( $callback ) : $this
Set the winner callback.
Parameters
- $callback callable
loser ( $callback ) : $this
Set the loser callback.
Parameters
- $callback callable
__invoke ( $args ) : mixed
Run the lottery.
Parameters
- $args mixed
choose ( $times ) : mixed
Run the lottery.
Parameters
- $times null|int
runCallback ( $args ) : callable
Run the winner or loser callback, randomly.
Parameters
- $args mixed
wins ( ) : bool
Determine if the lottery "wins" or "loses".
resultFactory ( ) : callable
The factory that determines the lottery result.
alwaysWin ( $callback ) : void
Force the lottery to always result in a win.
Parameters
- $callback callable|null
alwaysLose ( $callback ) : void
Force the lottery to always result in a lose.
Parameters
- $callback callable|null
fix ( $sequence , $whenMissing ) : void
Set the sequence that will be used to determine lottery results.
Parameters
- $sequence array
- $whenMissing callable|null
forceResultWithSequence ( $sequence , $whenMissing ) : void
Set the sequence that will be used to determine lottery results.
Parameters
- $sequence array
- $whenMissing callable|null
determineResultNormally ( ) : void
Indicate that the lottery results should be determined normally.
setResultFactory ( $factory ) : void
Set the factory that should be used to determine the lottery results.
Parameters
- $factory callable