Skip to content

Instantly share code, notes, and snippets.

@a-menshchikov
Created July 13, 2021 22:18
Show Gist options
  • Save a-menshchikov/08650c7b76154eb00c18d093e5087f0b to your computer and use it in GitHub Desktop.
Save a-menshchikov/08650c7b76154eb00c18d093e5087f0b to your computer and use it in GitHub Desktop.
Simplified CsvEnvVarProcessor
<?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