public function validates($options = [])
    {
        $this->sync();
        $exists = $this->exists();
        $defaults = [
            'events'   => $exists ? 'update' : 'create',
            'required' => $exists ? false : true,
            'entity'   => $this,
            'embed'    => true
        ];
        $options += $defaults;
        $validator = static::validator();

        $valid = $this->_validates(['embed' => $options['embed']]);

        $success = $validator->validates($this->get(), $options);
        $this->_errors = [];
        $this->invalidate($validator->errors());
        return $success && $valid;
    }
public function validates($options = [])
    {
        $this->sync();
        $exists = $this->exists();
        $defaults = [
            'events'   => $exists ? 'update' : 'create',
            'required' => $exists ? false : true,
            'entity'   => $this,
            'embed'    => true
        ];
        $options += $defaults;
        $validator = static::validator();

        $valid = $this->_validates(['embed' => $options['embed']]);

        $success = $validator->validates($this->get(), $options);
        $this->_errors = [];
        $this->invalidate($validator->errors());
        return $success && $valid;
    }
public function validates ( $ options = [ ] ) { $ this -> sync ( ) ; $ exists = $ this -> exists ( ) ; $ defaults = [ 'events' => $ exists ? 'update' : 'create' , 'required' => $ exists ? false : true , 'entity' => $ this , 'embed' => true ] ; $ options += $ defaults ; $ validator = static :: validator ( ) ; $ valid = $ this -> _validates ( [ 'embed' => $ options [ 'embed' ] ] ) ; $ success = $ validator -> validates ( $ this -> get ( ) , $ options ) ; $ this -> _errors = [ ] ; $ this -> invalidate ( $ validator -> errors ( ) ) ; return $ success && $ valid ; }
Validates the entity data.

@param  array  $options Available options:
- `'events'` _mixed_    : A string or array defining one or more validation
events. Events are different contexts in which data events can occur, and
correspond to the optional `'on'` key in validation rules. For example, by
default, `'events'` is set to either `'create'` or `'update'`, depending on
whether the entity already exists. Then, individual rules can specify
`'on' => 'create'` or `'on' => 'update'` to only be applied at certain times.
You can also set up custom events in your rules as well, such as `'on' => 'login'`.
Note that when defining validation rules, the `'on'` key can also be an array of
multiple events.
- `'required'` _boolean_ : Sets the validation rules `'required'` default value.
- `'embed'`    _array_   : List of relations to validate.
@return boolean         Returns `true` if all validation rules on all fields succeed, otherwise
`false`. After validation, the messages for any validation failures are assigned
to the entity, and accessible through the `errors()` method of the entity object.
Validates the entity data .