public function validate()
{
if ($this->triggerEvent('beforeValidate')->isCancelled()) {
return $this;
}
if (!$this->isValid()) {
$exception = new InvalidDocumentException('Document not valid');
$exception->setDocument($this);
$this->triggerEvent('validateError');
throw $exception;
}
$this->triggerEvent('afterValidate');
return $this;
}