| @@ 817-840 (lines=24) @@ | ||
| 814 | * |
|
| 815 | * Will validate every loaded and embedded relation. |
|
| 816 | */ |
|
| 817 | protected function validate($reset = false) |
|
| 818 | { |
|
| 819 | $this->nestedErrors = []; |
|
| 820 | ||
| 821 | //Validating all compositions/accessors |
|
| 822 | foreach ($this->fields as $field => $value) { |
|
| 823 | //Ensuring value state |
|
| 824 | $value = $this->getField($field); |
|
| 825 | if (!$value instanceof ValidatesInterface) { |
|
| 826 | continue; |
|
| 827 | } |
|
| 828 | ||
| 829 | if (!$value->isValid()) { |
|
| 830 | $this->nestedErrors[$field] = $value->getErrors($reset); |
|
| 831 | } |
|
| 832 | } |
|
| 833 | ||
| 834 | //We have to validate some relations before saving them |
|
| 835 | $this->validateRelations($reset); |
|
| 836 | ||
| 837 | parent::validate($reset); |
|
| 838 | ||
| 839 | return empty($this->errors + $this->nestedErrors); |
|
| 840 | } |
|
| 841 | ||
| 842 | /** |
|
| 843 | * {@inheritdoc} |
|
| @@ 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} |
|