Yasumi\Yasumi::getProviders PHP Method

getProviders() public static method

Returns a list of available holiday providers.
public static getProviders ( ) : array
return array list of available holiday providers
    public static function getProviders()
    {
        // Basic static cache
        static $providers;
        if ($providers !== null) {
            return $providers;
        }
        $ds = DIRECTORY_SEPARATOR;
        $providers = [];
        $filesIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . $ds . 'Provider', FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($filesIterator as $file) {
            if ($file->isDir() || in_array($file->getBasename('.php'), self::$ignoredProvider) || $file->getExtension() !== 'php') {
                continue;
            }
            $quotedDs = preg_quote($ds);
            $provider = preg_replace("#^.+{$quotedDs}Provider{$quotedDs}(.+)\\.php\$#", '$1', $file->getPathName());
            $class = new ReflectionClass(sprintf('Yasumi\\Provider\\%s', str_replace('/', '\\', $provider)));
            $key = 'ID';
            if ($class->hasConstant($key)) {
                $providers[strtoupper($class->getConstant($key))] = $provider;
            }
        }
        return (array) $providers;
    }

Usage Example

Beispiel #1
0
 /**
  * Tests that the getProviders function returns an array containing all available holiday providers.
  */
 public function testGetProviders()
 {
     $providers = Yasumi::getProviders();
     $this->assertNotEmpty($providers);
     $this->assertInternalType('array', $providers);
     $this->assertContains('Netherlands', $providers);
 }