protected function extractModelFromKey($chain)
{
$chain = is_array($chain) ? $chain : array($chain);
$iterator = new \ArrayIterator($chain);
$model = $iterator->current();
// we cant do anything with null models so throw an error
if (is_null($model)) {
$variableName = $iterator->key();
throw new Exceptions\InvalidDeviseTagException("Cannot use '{$variableName}'' as a devise model because it is null");
}
// make sure this model is a model
if (is_a($model, '\\Illuminate\\Database\\Eloquent\\Model')) {
return array($model, null);
}
// didn't find the model so maybe it is an attribute
// of a specific model, so advance the iterator
$attribute = $iterator->key();
$iterator->next();
$model = $iterator->valid() ? $iterator->current() : null;
// let's try this again
if (is_a($model, '\\Illuminate\\Database\\Eloquent\\Model')) {
return array($model, $attribute);
}
throw new Exceptions\InvalidDeviseTagException('Could not extract Eloquent model from devise tag');
}