function realistic_dummy_content_api_argcheck in Realistic Dummy Content 7.2
Same name and namespace in other branches
- 8.2 api/realistic_dummy_content_api.module \realistic_dummy_content_api_argcheck()
- 3.x api/realistic_dummy_content_api.module \realistic_dummy_content_api_argcheck()
Check arguments' types.
Meant to be called by functions which receive parameters. This function can be called to make sure each parameter is of the correct type using a callback.
Parameters
array $callbacks: Array of callbacks for each parameter of the calling function.
Throws
\Exception
2 calls to realistic_dummy_content_api_argcheck()
- RealisticDummyContentEntityBase::__construct in api/
src/ includes/ RealisticDummyContentEntityBase.php - Constructor.
- realistic_dummy_content_api_improve_dummy_content in api/
realistic_dummy_content_api.module - Insert or improve dummy data in an entity of a given type.
File
- api/
realistic_dummy_content_api.module, line 26 - API code allowing other modules to generate realistic dummy content.
Code
function realistic_dummy_content_api_argcheck($callbacks) {
$trace = debug_backtrace();
$checks = array();
$errors = FALSE;
foreach ($callbacks as $index => $callback) {
$argument = $trace[1]['args'][$index];
if (!$callback($argument)) {
$checks[] = t('Argument @index is a @realtype, so @callback returned FALSE.', array(
'@index' => $index,
'@realtype' => gettype($argument),
'@callback' => $callback,
));
$errors = TRUE;
}
$checks[] = t('Argument @index is OK: it is a @realtype, so @callback returned TRUE.', array(
'@index' => $index,
'@realtype' => gettype($argument),
'@callback' => $callback,
));
}
if ($errors) {
$calling_function = realistic_dummy_content_api_calling_function(3);
$called_function = realistic_dummy_content_api_calling_function(2);
throw new \Exception(t('@calling called @called with bad argument types:', array(
'@calling' => $calling_function,
'@called' => $called_function,
)) . ' ' . implode('; ', $checks));
}
}