/** * @param $value * @throws \InvalidArgumentException */ public function validate($value) { parent::validate($value); if (is_int($value)) { if ($value <= 0) { throw new \InvalidArgumentException("Field '{$this->name}' must be integer > 0"); } } elseif (is_object($value)) { if (!$value instanceof \Dja\Db\Model\Model) { throw new \InvalidArgumentException("Field '{$this->name}' must be instance of \\Dja\\Db\\Model\\Model"); } if (get_class($value) !== $this->relationClass) { throw new \InvalidArgumentException("Field '{$this->name}' must be instance of {$this->relationClass}"); } } else { throw new \InvalidArgumentException("Field '{$this->name}' must be integer or object"); } }