diff --git a/src/Common/Options.php b/src/Common/Options.php index c2848bc..4776d3b 100644 --- a/src/Common/Options.php +++ b/src/Common/Options.php @@ -10,6 +10,7 @@ class Options // Common public bool $assoc = false; + public ?string $adapter = null; /** * @var string[] */ diff --git a/src/SpreadCompat.php b/src/SpreadCompat.php index 590b0d0..785784f 100644 --- a/src/SpreadCompat.php +++ b/src/SpreadCompat.php @@ -83,6 +83,16 @@ public static function getAdapter(string $ext): SpreadInterface return new ($class); } + public static function getAdapterByName(string $ext, string $name): SpreadInterface + { + $ext = ucfirst($ext); + $class = 'LeKoala\\SpreadCompat\\' . $ext . '\\' . $name; + if (!class_exists($class)) { + throw new Exception("Invalid adapter $class"); + } + return new ($class); + } + public static function getAdapterForFile(string $filename, string $ext = null): SpreadInterface { if ($ext === null) {