$toolbox : \RedBeanPHP\Util\Toolbox
Tired of creating login systems and password-forget systems? MatchUp is an ORM-translation of these kind of problems. A matchUp is a match-and-update combination in terms of beans. Typically login related problems are all about a match and a conditional update.
The MatchUp class requires a toolbox
matchUp(string $type, string $sql, array $bindings = array(), array $onFoundDo = NULL, array $onNotFoundDo = NULL, $bean = NULL) : mixed
MatchUp is a powerful productivity boosting method that can replace simple control scripts with a single RedBeanPHP command. Typically, matchUp() is used to replace login scripts, token generation scripts and password reset scripts.
The MatchUp method takes a bean type, an SQL query snippet (starting at the WHERE clause), SQL bindings, a pair of task arrays and a bean reference.
If the first 3 parameters match a bean, the first task list will be considered, otherwise the second one will be considered. On consideration, each task list, an array of keys and values will be executed. Every key in the task list should correspond to a bean property while every value can either be an expression to be evaluated or a closure (PHP 5.3+). After applying the task list to the bean it will be stored. If no bean has been found, a new bean will be dispensed.
This method will return TRUE if the bean was found and FALSE if not AND there was a NOT-FOUND task list. If no bean was found AND there was also no second task list, NULL will be returned.
To obtain the bean, pass a variable as the sixth parameter. The function will put the matching bean in the specified variable.
Usage (this example resets a password in one go):
$newpass = '1234';
$didResetPass = R::matchUp(
'account', ' token = ? AND tokentime > ? ',
[ $token, time()-100 ],
[ 'pass' => $newpass, 'token' => '' ],
type of bean you're looking for
SQL snippet (starting at the WHERE clause, omit WHERE-keyword)
array of parameter bindings for SQL snippet
task list to be considered on finding the bean
task list to be considered on NOT finding the bean