protected validate ( $opts ) : [String | ||
return | [String |
protected function validate($opts)
{
foreach ($opts as $key => $value) {
if ($value !== null && isset($this->types[$key]) && $this->types[$key] !== null) {
if (is_array($this->types[$key])) {
$class = '\\Locker\\XApi\\' . $this->types[$key][0];
if (!is_array($value)) {
throw new Exceptions\Exception("{$key} must be an array.");
}
foreach ($value as $item) {
Helpers::validateAtom(new $class($item));
}
} else {
$class = '\\Locker\\XApi\\' . $this->types[$key];
Helpers::validateAtom(new $class($value));
}
}
}
return $opts;
}
/** * Validates the given options as index options. * @param [String => Mixed] $opts * @return [String => Mixed] */ protected function validate($opts) { $opts = parent::validate($opts); // Validates values. if (!isset($opts['lrs_id'])) { throw new Exceptions\Exception('`lrs_id` must be set.'); } if ($opts['offset'] < 0) { throw new Exceptions\Exception('`offset` must be a positive interger.'); } if ($opts['limit'] < 1) { throw new Exceptions\Exception('`limit` must be a positive interger.'); } if (!in_array($opts['format'], ['exact', 'canonical', 'ids'])) { throw new Exceptions\Exception('`format` must be "exact", "canonical", or "ids".'); } return $opts; }