\RedBeanPHP\UtilMatchUp

MatchUp Utility

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.

Summary

Methods
Properties
Constants
__construct()
matchUp()
No public properties found
No constants found
No protected methods found
$toolbox
N/A
No private methods found
No private properties found
N/A

Properties

$toolbox

$toolbox : \RedBeanPHP\Util\Toolbox

Type

\RedBeanPHP\Util\Toolbox

Methods

__construct()

__construct(\RedBeanPHP\ToolBox  $toolbox) 

Constructor.

The MatchUp class requires a toolbox

Parameters

\RedBeanPHP\ToolBox $toolbox

matchUp()

matchUp(string  $type, string  $sql, array  $bindings = array(), array|NULL  $onFoundDo = NULL, array|NULL  $onNotFoundDo = NULL,   $bean = NULL) : boolean|NULL

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' => '' ], NULL, $account );

Parameters

string $type

type of bean you're looking for

string $sql

SQL snippet (starting at the WHERE clause, omit WHERE-keyword)

array $bindings

array of parameter bindings for SQL snippet

array|NULL $onFoundDo

task list to be considered on finding the bean

array|NULL $onNotFoundDo

task list to be considered on NOT finding the bean

$bean

Returns

boolean|NULL