From 0aa1a6812b21a8558a40b00b277ab736beabfbea Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Mon, 2 Mar 2015 17:49:26 +0100 Subject: [PATCH] plugin manager --- src/Psy/Command/DemoCommand.php | 37 +++++++++++++++++ src/Psy/Plugin/AbstractPlugin.php | 68 +++++++++++++++++++++++++++++++ src/Psy/Plugin/DemoPlugin.php | 16 ++++++++ src/Psy/Plugin/Manager.php | 31 ++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 src/Psy/Command/DemoCommand.php create mode 100644 src/Psy/Plugin/AbstractPlugin.php create mode 100644 src/Psy/Plugin/DemoPlugin.php create mode 100644 src/Psy/Plugin/Manager.php diff --git a/src/Psy/Command/DemoCommand.php b/src/Psy/Command/DemoCommand.php new file mode 100644 index 000000000..e31bc2e94 --- /dev/null +++ b/src/Psy/Command/DemoCommand.php @@ -0,0 +1,37 @@ +setName('demo') + ->setDefinition(array( + new InputOption('message', 'm', InputOption::VALUE_REQUIRED, 'Message to send.'), + )) + ->setDescription('Sample command just for testing.') + ->setHelp( + <<getOption('message'); + $output->writeln(sprintf('Received message "%s". ', $message)); + } +} diff --git a/src/Psy/Plugin/AbstractPlugin.php b/src/Psy/Plugin/AbstractPlugin.php new file mode 100644 index 000000000..f67947544 --- /dev/null +++ b/src/Psy/Plugin/AbstractPlugin.php @@ -0,0 +1,68 @@ +getShortName()); + } + + /** + * @param array $configuration + * + * @return array + */ + final public static function getConfiguration($configuration = array()) + { + return array_merge_recursive( + $configuration, + array( + 'commands' => static::getCommands(), + 'presenters' => static::getPresenters(), + 'matchers' => static::getMatchers() + // if any more parts of the config are exposed publicly, remember to add here with the static ref. + ) + ); + } + + // any publicly exposed configuration piece below here ↓ + + /** + * @return array + */ + public static function getCommands() + { + // add your own commands + return array(); + } + + /** + * @return array + */ + public static function getPresenters() + { + // add your own presenters + return array(); + } + + /** + * @return array + */ + public static function getMatchers() + { + // add your own presenters + return array(); + } +} diff --git a/src/Psy/Plugin/DemoPlugin.php b/src/Psy/Plugin/DemoPlugin.php new file mode 100644 index 000000000..f626aadee --- /dev/null +++ b/src/Psy/Plugin/DemoPlugin.php @@ -0,0 +1,16 @@ +