-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
154 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Psy\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DemoCommand extends Command | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('demo') | ||
->setDefinition(array( | ||
new InputOption('message', 'm', InputOption::VALUE_REQUIRED, 'Message to send.'), | ||
)) | ||
->setDescription('Sample command just for testing.') | ||
->setHelp( | ||
<<<HELP | ||
HELP | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$message = $input->getOption('message'); | ||
$output->writeln(sprintf('<info>Received message "%s". </info>', $message)); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace Psy\Plugin; | ||
|
||
abstract class AbstractPlugin | ||
{ | ||
public static function register() | ||
{ | ||
Manager::register(new static(), static::getName()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
final public static function getName() | ||
{ | ||
$class = new \ReflectionClass(get_called_class()); | ||
|
||
return preg_replace('#Plugin$#', '', $class->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(); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Psy\Plugin; | ||
|
||
use Psy\Command\DemoCommand; | ||
|
||
class DemoPlugin extends AbstractPlugin | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public static function getCommands() | ||
{ | ||
return array( | ||
new DemoCommand(), | ||
); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Psy\Plugin; | ||
|
||
class Manager | ||
{ | ||
/** @var AbstractPlugin[] */ | ||
protected static $plugins = array(); | ||
|
||
/** | ||
* @param AbstractPlugin $plugin | ||
* @param $name | ||
*/ | ||
public static function register(AbstractPlugin $plugin, $name) | ||
{ | ||
self::$plugins[$name] = $plugin; | ||
} | ||
|
||
/** | ||
* @param array $configuration | ||
* | ||
* @return array | ||
*/ | ||
public static function getConfiguration($configuration = array()) | ||
{ | ||
foreach (self::$plugins as $plugin) { | ||
$configuration = $plugin::getConfiguration($configuration); | ||
} | ||
|
||
return $configuration; | ||
} | ||
} |