Skip to content
Extraits de code Groupes Projets
Valider 205db2e8 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

removed some duplicated code, fixed some erros in tests command and visualization command

parent 0c2e947c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -50,31 +50,12 @@ class GenerateApi extends GeneratePluginBase
* @return array
* @throws \RunTimeException
*/
private function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('API.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have an API';
$validate = function ($pluginName) use ($pluginNames) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException('You have to enter the name of an existing plugin which does not already have an API');
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
return parent::getPluginName($input, $output, $pluginNames, $invalidName);
}
}
\ No newline at end of file
......@@ -84,35 +84,11 @@ class GenerateCommand extends GeneratePluginBase
return $testname;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RunTimeException
*/
private function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';
$validate = function ($pluginName) use ($pluginNames) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException('You have to enter the name of an existing plugin');
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
return parent::getPluginName($input, $output, $pluginNames, $invalidName);
}
}
\ No newline at end of file
......@@ -50,30 +50,12 @@ class GenerateController extends GeneratePluginBase
* @return array
* @throws \RunTimeException
*/
private function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Controller.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have a Controller';
$validate = function ($pluginName) use ($pluginNames) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException('You have to enter the name of an existing plugin which does not already have a Controller');
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
return parent::getPluginName($input, $output, $pluginNames, $invalidName);
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@ namespace Piwik\Plugins\CoreConsole\Commands;
use Piwik\Filesystem;
use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @package CoreConsole
......@@ -111,4 +113,34 @@ class GeneratePluginBase extends ConsoleCommand
return $pluginNames;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RunTimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output, $pluginNames, $invalidArgumentException)
{
$validate = function ($pluginName) use ($pluginNames, $invalidArgumentException) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException($invalidArgumentException);
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
}
}
\ No newline at end of file
......@@ -50,31 +50,12 @@ class GenerateSettings extends GeneratePluginBase
* @return array
* @throws \RunTimeException
*/
private function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Settings.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have settings';
$validate = function ($pluginName) use ($pluginNames) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException('You have to enter the name of an existing plugin which does not already have settings');
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
return parent::getPluginName($input, $output, $pluginNames, $invalidName);
}
}
\ No newline at end of file
......@@ -105,33 +105,15 @@ class GenerateTest extends GeneratePluginBase
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @return array
* @throws \RunTimeException
*/
private function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';
$validate = function ($pluginName) use ($pluginNames) {
if (!in_array($pluginName, $pluginNames)) {
throw new \InvalidArgumentException('You have to enter the name of an existing plugin');
}
return $pluginName;
};
$pluginName = $input->getOption('pluginname');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter the name of your plugin: ', $validate, false, null, $pluginNames);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
return parent::getPluginName($input, $output, $pluginNames, $invalidName);
}
/**
......@@ -149,7 +131,7 @@ class GenerateTest extends GeneratePluginBase
return false;
}
function getValidTypes()
public function getValidTypes()
{
return array('unit', 'integration', 'database');
}
......@@ -163,11 +145,11 @@ class GenerateTest extends GeneratePluginBase
{
$testtype = $input->getOption('testtype');
$validate = function ($testtype) {
$self = $this;
if (empty($testtype) || !in_array($testtype, $this->getValidTypes())) {
throw new \InvalidArgumentException('You have to enter a valid test type: ' . implode(" or ", $this->getValidTypes()));
$validate = function ($testtype) use ($self) {
if (empty($testtype) || !in_array($testtype, $self->getValidTypes())) {
throw new \InvalidArgumentException('You have to enter a valid test type: ' . implode(" or ", $self->getValidTypes()));
}
return $testtype;
};
......
......@@ -35,24 +35,23 @@ class GenerateVisualizationPlugin extends GeneratePlugin
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
$visualizationName = $this->getVisualizationName($input, $output);
$pluginName = $this->getPluginName($input, $output);
$description = $this->getPluginDescription($input, $output);
$version = $this->getPluginVersion($input, $output);
$version = $this->getPluginVersion($input, $output);
$visualizationName = $this->getVisualizationName($input, $output);
$this->generatePluginFolder($pluginName);
$this->generatePluginJson($pluginName, $version, $description, false);
$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExampleVisualization';
$replace = array(
'ExampleVisualization' => $pluginName,
'SimpleTable' => $visualizationName,
'simpleTable' => lcfirst($visualizationName),
'Simple Table' => $visualizationName
'SimpleTable' => $visualizationName,
'simpleTable' => lcfirst($visualizationName),
'Simple Table' => $visualizationName,
'ExampleVisualization' => $pluginName,
'ExampleVisualizationDescription' => $description
);
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace);
$this->generatePluginFile($pluginName);
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles = array());
$this->writeSuccessMessage($output, array(
sprintf('Visualization plugin %s %s generated.', $pluginName, $version),
......
{
"name": "ExampleVisualization",
"version": "0.1.0",
"description": "Example for generating a simple visualization",
"description": "ExampleVisualizationDescription",
"theme": false,
"license": "GPL-3.0+",
"keywords": ["SimpleTable"],
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter