Created
July 13, 2021 22:18
-
-
Save a-menshchikov/08650c7b76154eb00c18d093e5087f0b to your computer and use it in GitHub Desktop.
Simplified CsvEnvVarProcessor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface; | |
use Symfony\Component\DependencyInjection\Exception\RuntimeException; | |
final class CsvEnvVarProcessor implements EnvVarProcessorInterface | |
{ | |
private const DELIMITERS = [ | |
'dot' => '.', | |
'colon' => ':', | |
'dash' => '-', | |
'bar' => '|', | |
]; | |
public static function getProvidedTypes(): array | |
{ | |
return [ | |
'csv-dot' => 'array', | |
'csv-colon' => 'array', | |
'csv-dash' => 'array', | |
'csv-bar' => 'array', | |
]; | |
} | |
/** | |
* @return non-empty-list<string|null> | |
*/ | |
public function getEnv(string $prefix, string $name, Closure $getEnv): array | |
{ | |
$delimiter = self::DELIMITERS[$prefix]; | |
$env = $getEnv($name); | |
return str_getcsv($env, $delimiter, '"', \PHP_VERSION_ID >= 70400 ? '' : '\\'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment