-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDTT-12: Support custom transformation plugins (#13)
- Loading branch information
1 parent
81b57d2
commit 0777ebc
Showing
8 changed files
with
183 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mdtt\Transform; | ||
|
||
class DefaultPluginManager implements PluginManager | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function loadById(string $id): Transform | ||
{ | ||
$pluginId = ucwords($id); | ||
|
||
require "tests/mdtt/src/Plugin/Transform/$pluginId.php"; | ||
|
||
/** @var \Mdtt\Transform\Transform $pluginInstance */ | ||
$pluginInstance = new $pluginId(); | ||
return $pluginInstance; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Mdtt\Transform; | ||
|
||
interface PluginManager | ||
{ | ||
/** | ||
* Scans all transform plugins and instantiates them. | ||
* | ||
* @param string $id | ||
* | ||
* @return \Mdtt\Transform\Transform | ||
*/ | ||
public function loadById(string $id): Transform; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mdtt\Transform; | ||
|
||
interface Transform | ||
{ | ||
/** | ||
* Name of the plugin. | ||
* | ||
* @return string | ||
*/ | ||
public function name(): string; | ||
|
||
/** | ||
* Alters the provided data. | ||
* | ||
* @param string|int $data | ||
* | ||
* @return string|int | ||
*/ | ||
public function process(mixed $data): mixed; | ||
} |