Skip to content

Commit

Permalink
Apply required changes for vendor proxies (#623)
Browse files Browse the repository at this point in the history
* use new vendor proxies

* use logging proxy classes

* use proxy methods for console helpers

* adjust console commands

* use proxy methods for adding command options

* use correct container class
  • Loading branch information
sgiehl committed May 2, 2023
1 parent 69f3fc8 commit 938eb81
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 130 deletions.
33 changes: 12 additions & 21 deletions Commands/GenerateDataLayerVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@
namespace Piwik\Plugins\TagManager\Commands;

use Piwik\Plugins\CoreConsole\Commands\GeneratePluginBase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateDataLayerVariable extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:tagmanager-datalayer-variable');
$this->setDescription('Generate a preconfigured data layer variable');
$this->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin');
$this->addOption('variablename', null, InputOption::VALUE_REQUIRED, 'The name of the variable you want to create');
$this->addRequiredValueOption('pluginname', null, 'The name of an existing plugin');
$this->addRequiredValueOption('variablename', null, 'The name of the variable you want to create');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
protected function doExecute(): int
{
$pluginName = $this->getPluginName($input, $output);
$this->checkAndUpdateRequiredPiwikVersion($pluginName, $output);
$pluginName = $this->getPluginName();
$this->checkAndUpdateRequiredPiwikVersion($pluginName);

$variableName = $this->getVariableName($input, $output);
$variableName = $this->getVariableName();
$variableId = str_replace(array('-', ' '), '', $variableName);
$variableClass = $variableId . 'Variable';

Expand All @@ -57,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->makeTranslationIfPossible($pluginName, "This is the description for " . $variableName, $variableClass . 'Description');
$this->makeTranslationIfPossible($pluginName, "", $variableClass . 'Help');

$this->writeSuccessMessage($output, array(
$this->writeSuccessMessage(array(
sprintf('Variable for %s in folder "plugins/%s/Template/Variable/Preconfigured" generated.', $pluginName, $pluginName),
'You can now start implementing the preconfigured data layer variable',
'Enjoy!'
Expand All @@ -67,14 +61,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RuntimeException
*/
private function getVariableName(InputInterface $input, OutputInterface $output)
private function getVariableName()
{
$variableName = $input->getOption('variablename');
$variableName = $this->getInput()->getOption('variablename');

$validate = function ($testname) {
if (empty($testname)) {
Expand All @@ -89,8 +81,7 @@ private function getVariableName(InputInterface $input, OutputInterface $output)
};

if (empty($variableName)) {
$dialog = $this->getHelperSet()->get('dialog');
$variableName = $dialog->askAndValidate($output, 'Enter the name of the variable (CamelCase): ', $validate);
$variableName = $this->askAndValidate('Enter the name of the variable (CamelCase): ', $validate);
} else {
$validate($variableName);
}
Expand All @@ -100,12 +91,12 @@ private function getVariableName(InputInterface $input, OutputInterface $output)
return $variableName;
}

protected function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName()
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';

return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
return $this->askPluginNameAndValidate($pluginNames, $invalidName);
}

}
34 changes: 12 additions & 22 deletions Commands/GeneratePreconfiguredVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@
namespace Piwik\Plugins\TagManager\Commands;

use Piwik\Plugins\CoreConsole\Commands\GeneratePluginBase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GeneratePreconfiguredVariable extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:tagmanager-preconfigured-variable');
$this->setDescription('Generate Preconfigured Variable');
$this->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin');
$this->addOption('variablename', null, InputOption::VALUE_REQUIRED, 'The name of the variable you want to create');
$this->addRequiredValueOption('pluginname', null, 'The name of an existing plugin');
$this->addRequiredValueOption('variablename', null, 'The name of the variable you want to create');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
protected function doExecute(): int
{
$pluginName = $this->getPluginName($input, $output);
$this->checkAndUpdateRequiredPiwikVersion($pluginName, $output);
$pluginName = $this->getPluginName();
$this->checkAndUpdateRequiredPiwikVersion($pluginName);

$variableName = $this->getVariableName($input, $output);
$variableName = $this->getVariableName();
$variableId = str_replace(array('-', ' '), '', $variableName);
$variableClass = $variableId . 'Variable';

Expand All @@ -57,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->makeTranslationIfPossible($pluginName, "This is the description for " . $variableName, $variableClass . 'Description');
$this->makeTranslationIfPossible($pluginName, "", $variableClass . 'Help');

$this->writeSuccessMessage($output, array(
$this->writeSuccessMessage(array(
sprintf('Variable for %s in folder "plugins/%s/Template/Variable/Preconfigured" generated.', $pluginName, $pluginName),
'You can now start implementing the preconfigured variable',
'Enjoy!'
Expand All @@ -67,14 +61,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RuntimeException
*/
private function getVariableName(InputInterface $input, OutputInterface $output)
private function getVariableName()
{
$variableName = $input->getOption('variablename');
$variableName = $this->getInput()->getOption('variablename');

$validate = function ($testname) {
if (empty($testname)) {
Expand All @@ -93,8 +85,7 @@ private function getVariableName(InputInterface $input, OutputInterface $output)
};

if (empty($variableName)) {
$dialog = $this->getHelperSet()->get('dialog');
$variableName = $dialog->askAndValidate($output, 'Enter the name of the variable (CamelCase): ', $validate);
$variableName = $this->askAndValidate('Enter the name of the variable (CamelCase): ', $validate);
} else {
$validate($variableName);
}
Expand All @@ -104,12 +95,11 @@ private function getVariableName(InputInterface $input, OutputInterface $output)
return $variableName;
}

protected function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName()
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';

return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
return $this->askPluginNameAndValidate($pluginNames, $invalidName);
}

}
33 changes: 12 additions & 21 deletions Commands/GenerateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,26 @@
namespace Piwik\Plugins\TagManager\Commands;

use Piwik\Plugins\CoreConsole\Commands\GeneratePluginBase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateTag extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:tagmanager-tag');
$this->setDescription('Generate Tag');
$this->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin');
$this->addOption('tagname', null, InputOption::VALUE_REQUIRED, 'The name of the tag you want to create');
$this->addRequiredValueOption('pluginname', null, 'The name of an existing plugin');
$this->addRequiredValueOption('tagname', null, 'The name of the tag you want to create');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
protected function doExecute(): int
{
$pluginName = $this->getPluginName($input, $output);
$this->checkAndUpdateRequiredPiwikVersion($pluginName, $output);
$pluginName = $this->getPluginName();
$this->checkAndUpdateRequiredPiwikVersion($pluginName);

$tagName = $this->getTagName($input, $output);
$tagName = $this->getTagName();
$tagId = str_replace(array('-', ' '), '', $tagName);
$tagClass = $tagId . 'Tag';

Expand All @@ -59,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->makeTranslationIfPossible($pluginName, "This is the description for " . $tagName, $tagClass . 'Description');
$this->makeTranslationIfPossible($pluginName, "", $tagClass . 'Help');

$this->writeSuccessMessage($output, array(
$this->writeSuccessMessage(array(
sprintf('Tag for %s in folder "plugins/%s/Template/Tag" generated.', $pluginName, $pluginName),
'You can now start implementing the tag',
'Enjoy!'
Expand All @@ -69,14 +63,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RuntimeException
*/
private function getTagName(InputInterface $input, OutputInterface $output)
private function getTagName()
{
$tagName = $input->getOption('tagname');
$tagName = $this->getInput()->getOption('tagname');

$validate = function ($testname) {
if (empty($testname)) {
Expand All @@ -95,8 +87,7 @@ private function getTagName(InputInterface $input, OutputInterface $output)
};

if (empty($tagName)) {
$dialog = $this->getHelperSet()->get('dialog');
$tagName = $dialog->askAndValidate($output, 'Enter the name of the tag (CamelCase): ', $validate);
$tagName = $this->askAndValidate('Enter the name of the tag (CamelCase): ', $validate);
} else {
$validate($tagName);
}
Expand All @@ -106,11 +97,11 @@ private function getTagName(InputInterface $input, OutputInterface $output)
return $tagName;
}

protected function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName()
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';

return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
return $this->askPluginNameAndValidate($pluginNames, $invalidName);
}
}
35 changes: 12 additions & 23 deletions Commands/GenerateTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,27 @@
*/
namespace Piwik\Plugins\TagManager\Commands;


use Piwik\Plugins\CoreConsole\Commands\GeneratePluginBase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


class GenerateTrigger extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:tagmanager-trigger');
$this->setDescription('Generate Trigger');
$this->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin');
$this->addOption('triggername', null, InputOption::VALUE_REQUIRED, 'The name of the trigger you want to create');
$this->addRequiredValueOption('pluginname', null, 'The name of an existing plugin');
$this->addRequiredValueOption('triggername', null, 'The name of the trigger you want to create');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
protected function doExecute(): int
{
$pluginName = $this->getPluginName($input, $output);
$this->checkAndUpdateRequiredPiwikVersion($pluginName, $output);
$pluginName = $this->getPluginName();
$this->checkAndUpdateRequiredPiwikVersion($pluginName);

$triggerName = $this->getTriggerName($input, $output);
$triggerName = $this->getTriggerName();
$triggerId = str_replace(array('-', ' '), '', $triggerName);
$triggerClass = $triggerId . 'Trigger';

Expand All @@ -59,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->makeTranslationIfPossible($pluginName, "This is the description for " . $triggerName, $triggerClass . 'Description');
$this->makeTranslationIfPossible($pluginName, "", $triggerClass . 'Help');

$this->writeSuccessMessage($output, array(
$this->writeSuccessMessage(array(
sprintf('Trigger for %s in folder "plugins/%s/Template/Trigger" generated.', $pluginName, $pluginName),
'You can now start implementing the trigger',
'Enjoy!'
Expand All @@ -69,14 +61,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RuntimeException
*/
private function getTriggerName(InputInterface $input, OutputInterface $output)
private function getTriggerName()
{
$triggerName = $input->getOption('triggername');
$triggerName = $this->getInput()->getOption('triggername');

$validate = function ($testname) {
if (empty($testname)) {
Expand All @@ -95,8 +85,7 @@ private function getTriggerName(InputInterface $input, OutputInterface $output)
};

if (empty($triggerName)) {
$dialog = $this->getHelperSet()->get('dialog');
$triggerName = $dialog->askAndValidate($output, 'Enter the name of the trigger (CamelCase): ', $validate);
$triggerName = $this->askAndValidate('Enter the name of the trigger (CamelCase): ', $validate);
} else {
$validate($triggerName);
}
Expand All @@ -106,11 +95,11 @@ private function getTriggerName(InputInterface $input, OutputInterface $output)
return $triggerName;
}

protected function getPluginName(InputInterface $input, OutputInterface $output)
protected function getPluginName()
{
$pluginNames = $this->getPluginNames();
$invalidName = 'You have to enter the name of an existing plugin';

return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
return $this->askPluginNameAndValidate($pluginNames, $invalidName);
}
}

0 comments on commit 938eb81

Please sign in to comment.