| @@ 629-649 (lines=21) @@ | ||
| 626 | * @param bool $reset |
|
| 627 | * @throws DocumentException |
|
| 628 | */ |
|
| 629 | protected function validate($reset = false) |
|
| 630 | { |
|
| 631 | $this->nestedErrors = []; |
|
| 632 | ||
| 633 | //Validating all compositions |
|
| 634 | foreach ($this->odmSchema[ODM::D_COMPOSITIONS] as $field) { |
|
| 635 | $composition = $this->getField($field); |
|
| 636 | if (!$composition instanceof CompositableInterface) { |
|
| 637 | //Something weird. |
|
| 638 | continue; |
|
| 639 | } |
|
| 640 | ||
| 641 | if (!$composition->isValid()) { |
|
| 642 | $this->nestedErrors[$field] = $composition->getErrors($reset); |
|
| 643 | } |
|
| 644 | } |
|
| 645 | ||
| 646 | parent::validate($reset); |
|
| 647 | ||
| 648 | return empty($this->errors + $this->nestedErrors); |
|
| 649 | } |
|
| 650 | ||
| 651 | /** |
|
| 652 | * {@inheritdoc} |
|
| @@ 784-807 (lines=24) @@ | ||
| 781 | * |
|
| 782 | * Will validate every loaded and embedded relation. |
|
| 783 | */ |
|
| 784 | protected function validate($reset = false) |
|
| 785 | { |
|
| 786 | $this->nestedErrors = []; |
|
| 787 | ||
| 788 | //Validating all compositions/accessors |
|
| 789 | foreach ($this->fields as $field => $value) { |
|
| 790 | //Ensuring value state |
|
| 791 | $value = $this->getField($field); |
|
| 792 | if (!$value instanceof ValidatesInterface) { |
|
| 793 | continue; |
|
| 794 | } |
|
| 795 | ||
| 796 | if (!$value->isValid()) { |
|
| 797 | $this->nestedErrors[$field] = $value->getErrors($reset); |
|
| 798 | } |
|
| 799 | } |
|
| 800 | ||
| 801 | //We have to validate some relations before saving them |
|
| 802 | $this->validateRelations($reset); |
|
| 803 | ||
| 804 | parent::validate($reset); |
|
| 805 | ||
| 806 | return empty($this->errors + $this->nestedErrors); |
|
| 807 | } |
|
| 808 | ||
| 809 | /** |
|
| 810 | * {@inheritdoc} |
|