Skip to content

Commit

Permalink
add getAdapterByName
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Feb 7, 2024
1 parent ae6dabf commit 2f41509
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Common/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Options

// Common
public bool $assoc = false;
public ?string $adapter = null;
/**
* @var string[]
*/
Expand Down
10 changes: 10 additions & 0 deletions src/SpreadCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2f41509

Please sign in to comment.