Skip to content

Commit

Permalink
Fixed function getProvider, now she return (sub) provider like region…
Browse files Browse the repository at this point in the history
…, departement...
  • Loading branch information
R2c authored and vagrant committed Apr 14, 2016
1 parent 864d250 commit 5879133
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/Yasumi/Yasumi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

use DirectoryIterator;
use InvalidArgumentException;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use RuntimeException;
use Yasumi\Exception\UnknownLocaleException;
use Yasumi\Provider\AbstractProvider;
Expand All @@ -40,6 +42,17 @@ class Yasumi
*/
private static $globalTranslations;

/**
* Provider class to be ignored (Abstract, trait, other)
*
* @var array
*/
private static $ignoredProvider = [
'AbstractProvider.php',
'CommonHolidays.php',
'ChristianHolidays.php',
];

/**
* Create a new holiday provider instance.
*
Expand Down Expand Up @@ -104,19 +117,30 @@ public static function getAvailableLocales()
*/
public static function getProviders()
{
//Basic static cache
static $providers;
if ($providers !== null) {
return $providers;
}

$extension = 'php';
$providers = [];
foreach (new DirectoryIterator(__DIR__.'/Provider/') as $file) {
if ($file->isFile() === false || in_array($file->getBasename(), [
'AbstractProvider.php',
'CommonHolidays.php',
'ChristianHolidays.php',
]) || $file->getExtension() !== $extension
$filesIterator = new \RecursiveIteratorIterator(
new RecursiveDirectoryIterator(__DIR__.'/Provider/'),
RecursiveIteratorIterator::SELF_FIRST
);

foreach ($filesIterator as $file) {
if ($file->isFile() === false
|| in_array($file->getBasename(), self::$ignoredProvider)
|| $file->getExtension() !== $extension
) {
continue;
}

$providers[] = $file->getBasename('.'.$extension);
$provider = preg_replace('#^.+/Provider/(.+)\.php$#', '$1', $file->getPathName());

$providers[] = $provider;
}

return (array) $providers;
Expand Down

0 comments on commit 5879133

Please sign in to comment.