/**
* Assert that the callback returns true for each variable.
*
* @param callable $callback
* @param string $message
*
* @return \Dotenv\Validator
*/
protected function assertCallback($callback, $message = 'failed callback assertion')
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Callback must be callable');
}
$variablesFailingAssertion = array();
foreach ($this->variables as $variableName) {
$variableValue = $this->loader->getEnvironmentVariable($variableName);
if (call_user_func($callback, $variableValue) === false) {
$variablesFailingAssertion[] = $variableName . " {$message}";
}
}
if (count($variablesFailingAssertion) > 0) {
throw new \RuntimeException(sprintf('One or more environment variables failed assertions: %s', implode(', ', $variablesFailingAssertion)));
}
return $this;
}