public static function loadClosest($context = '')
{
/**
* The number of replaces done by `preg_replace`.
* This actually represents whether a new context was generated or not.
*
* @var int $count
*/
$count = 0;
// As long as a new context can be generated, we try to load it.
do {
try {
// Trying to load the new context.
static::load($context);
} catch (\Exception $e) {
// If it didn't work, we are looking for a new one and skipping
// over to the next generation that will try the new context.
$context = preg_replace('/[1-9](0*)$/', '0$1', $context, -1, $count);
continue;
}
// Last generated context was valid (did not throw any exceptions).
// So we return it, to let the user know what context was loaded.
return $context;
} while ($count !== 0);
return null;
}