Piwik\Plugins\CoreConsole\Commands\GenerateWidget::getWidgetName PHP Method

getWidgetName() protected method

protected getWidgetName ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : array
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return array
    protected function getWidgetName(InputInterface $input, OutputInterface $output)
    {
        $validate = function ($widgetName) {
            if (empty($widgetName)) {
                throw new \InvalidArgumentException('Please enter the name of your widget');
            }
            if (preg_match("/[^A-Za-z0-9 ]/", $widgetName)) {
                throw new \InvalidArgumentException('Only alpha numerical characters and whitespaces are allowed');
            }
            return $widgetName;
        };
        $widgetName = $input->getOption('widgetname');
        if (empty($widgetName)) {
            $dialog = $this->getHelperSet()->get('dialog');
            $widgetName = $dialog->askAndValidate($output, 'Enter the name of your Widget, for instance "Browser Families": ', $validate);
        } else {
            $validate($widgetName);
        }
        $widgetName = ucfirst($widgetName);
        return $widgetName;
    }