diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-11-11 04:44:39 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-11-11 04:44:39 +0400 |
commit | 225998cbfa9435fbd42edb6b474cc0ca2bd56337 (patch) | |
tree | 260b33ad454dfa7f8d22d805c8a156dd6862a46d /plugins/ExampleCommand | |
parent | 085c55f95f0d5b95549dec9daca7e7ff9d81d4ab (diff) |
refs #4241 added example command
Diffstat (limited to 'plugins/ExampleCommand')
-rw-r--r-- | plugins/ExampleCommand/Commands/HelloWorld.php | 43 | ||||
-rw-r--r-- | plugins/ExampleCommand/ExampleCommand.php | 32 | ||||
-rw-r--r-- | plugins/ExampleCommand/plugin.json | 6 |
3 files changed, 81 insertions, 0 deletions
diff --git a/plugins/ExampleCommand/Commands/HelloWorld.php b/plugins/ExampleCommand/Commands/HelloWorld.php new file mode 100644 index 0000000000..92f543609f --- /dev/null +++ b/plugins/ExampleCommand/Commands/HelloWorld.php @@ -0,0 +1,43 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package CoreConsole + */ + +namespace Piwik\Plugins\ExampleCommand\Commands; + +use Piwik\Plugin\ConsoleCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * @package ExampleCommand + */ +class HelloWorld extends ConsoleCommand +{ + protected function configure() + { + $this->setName('examplecommand:helloworld'); + $this->setDescription('ExampleCommand'); + $this->addOption('name', null, InputOption::VALUE_REQUIRED, 'Your name:'); + } + + /** + * Execute command like: ./console examplecommand:helloworld --name="The Piwik Team" + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = $input->getOption('name'); + + $message = sprintf('<info>HelloWorld: %s</info>', $name); + + $output->writeln($message); + } +}
\ No newline at end of file diff --git a/plugins/ExampleCommand/ExampleCommand.php b/plugins/ExampleCommand/ExampleCommand.php new file mode 100644 index 0000000000..d818366edb --- /dev/null +++ b/plugins/ExampleCommand/ExampleCommand.php @@ -0,0 +1,32 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package ExampleCommand + */ +namespace Piwik\Plugins\ExampleCommand; + +/** + * @package ExampleCommand + */ +class ExampleCommand extends \Piwik\Plugin +{ + /** + * @see Piwik\Plugin::getListHooksRegistered + */ + public function getListHooksRegistered() + { + return array( + 'Console.addCommands' => 'addConsoleCommands' + ); + } + + public function addConsoleCommands(&$commands) + { + $commands[] = 'Piwik\Plugins\ExampleCommand\Commands\HelloWorld'; + } +} diff --git a/plugins/ExampleCommand/plugin.json b/plugins/ExampleCommand/plugin.json new file mode 100644 index 0000000000..24cc1735d1 --- /dev/null +++ b/plugins/ExampleCommand/plugin.json @@ -0,0 +1,6 @@ +{ + "name": "ExampleCommand", + "version": "0.1.0", + "description": "Example for console commands", + "theme": false +}
\ No newline at end of file |