| @@ 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} |
|
| @@ 788-811 (lines=24) @@ | ||
| 785 | * |
|
| 786 | * Will validate every loaded and embedded relation. |
|
| 787 | */ |
|
| 788 | protected function validate($reset = false) |
|
| 789 | { |
|
| 790 | $this->nestedErrors = []; |
|
| 791 | ||
| 792 | //Validating all compositions/accessors |
|
| 793 | foreach ($this->fields as $field => $value) { |
|
| 794 | //Ensuring value state |
|
| 795 | $value = $this->getField($field); |
|
| 796 | if (!$value instanceof ValidatesInterface) { |
|
| 797 | continue; |
|
| 798 | } |
|
| 799 | ||
| 800 | if (!$value->isValid()) { |
|
| 801 | $this->nestedErrors[$field] = $value->getErrors($reset); |
|
| 802 | } |
|
| 803 | } |
|
| 804 | ||
| 805 | //We have to validate some relations before saving them |
|
| 806 | $this->validateRelations($reset); |
|
| 807 | ||
| 808 | parent::validate($reset); |
|
| 809 | ||
| 810 | return empty($this->errors + $this->nestedErrors); |
|
| 811 | } |
|
| 812 | ||
| 813 | /** |
|
| 814 | * {@inheritdoc} |
|