/** * You should override this if you want a custom exception or if you want to have a ZeroId. * * @param int $id * * @throws InvalidArgumentException */ protected function setId($id) { if (!Validator::isRequiredPositiveInteger($id)) { throw InvalidArgumentException::notPositiveInteger('id', $id); } $this->id = $id; }
/** * {@inheritDoc} */ public function isRequiredPositiveInteger($value, $suppressException = true) { /* Clear the last error. */ $this->lastError = null; /* If valid just return true. */ if (Validator::isRequiredPositiveInteger($value)) { return true; } /* Set the error message. */ $type = gettype($value); $this->lastError = sprintf('Expected positive integer, \'%s\' given.', 'integer' === $type ? 'zero or negative integer' : $type); return $this->validationFailed($suppressException); }