/** * Check that $value is $expected_types. */ public function checkTypes($name, $value, $expected_types) { // Convert expected type string into array $expected_types = is_string($expected_types) ? [$expected_types] : $expected_types; $validators = array_map(function ($expectedType) use($name, $value) { $validator = new \app\locker\statements\xAPIValidation(); $validator->checkTypes($name, $value, $expectedType, 'params'); return $this->jsonParam($expectedType, $value); }, $expected_types); $passes = array_filter($validators, function (\app\locker\statements\xAPIValidation $validator) { return $validator->getStatus() === 'passed'; }); if (count($passes) < 1) { \App::abort(400, sprintf("`%s` is not a %s", $name, implode(',', $expected_types))); } return $value; }