pushEvent() public method

The events are executed one after another in the added order as long as they return "true". The first event returning "false" will stop the process.
public pushEvent ( string $moment, string $action, Closure $function )
$moment string the "moment" of the event, can be either "before" or "after"
$action string the "action" of the event, can be either "create", "update" or "delete"
$function Closure the event function to be called if set
Beispiel #1
0
 /**
  * Setups CRUDlex with some events so the passwords get salted and
  * hashed properly.
  *
  * @param AbstractData $data
  * the AbstractData instance managing the users
  *
  * @param string $passwordField
  * the Entity fieldname of the password hash
  *
  * @param string $saltField
  * the Entity fieldname of the password hash salt
  */
 public function addEvents(AbstractData $data, $passwordField = 'password', $saltField = 'salt')
 {
     $that = $this;
     $saltGenFunction = function (Entity $entity) use($saltField, $that) {
         $salt = $that->getSalt(40);
         $entity->set($saltField, $salt);
         return true;
     };
     $data->pushEvent('before', 'create', $saltGenFunction);
     $pwHashFunction = $this->getPWHashFunction($data, $passwordField, $saltField);
     $data->pushEvent('before', 'create', $pwHashFunction);
     $data->pushEvent('before', 'update', $pwHashFunction);
 }