public static function create($class, $year = null, $locale = self::DEFAULT_LOCALE)
{
// Find and return holiday provider instance
$providerClass = sprintf('Yasumi\\Provider\\%s', str_replace('/', '\\', $class));
if (class_exists($class) && (new ReflectionClass($class))->implementsInterface(ProviderInterface::class)) {
$providerClass = $class;
}
if (!class_exists($providerClass) || $class === 'AbstractProvider') {
throw new InvalidArgumentException(sprintf('Unable to find holiday provider "%s".', $class));
}
// Assert year input
if ($year < 1000 || $year > 9999) {
throw new InvalidArgumentException(sprintf('Year needs to be between 1000 and 9999 (%s given).', $year));
}
// Load internal locales variable
if (!isset(static::$locales)) {
static::$locales = self::getAvailableLocales();
}
// Load internal translations variable
if (!isset(static::$globalTranslations)) {
static::$globalTranslations = new Translations(static::$locales);
static::$globalTranslations->loadTranslations(__DIR__ . '/data/translations');
}
// Assert locale input
if (!in_array($locale, static::$locales)) {
throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $locale));
}
return new $providerClass($year, $locale, self::$globalTranslations);
}