/**
* @param InputInterface $input
* @param OutputInterface $output
* @param string $pluginName
* @return array
* @throws \RuntimeException
*/
protected function getDimension(InputInterface $input, OutputInterface $output, $pluginName)
{
$dimensions = array();
$dimensionNames = array();
$reports = new ReportsProvider();
foreach ($reports->getAllReports() as $report) {
$dimension = $report->getDimension();
if (is_object($dimension)) {
$name = $dimension->getName();
if (!empty($name)) {
$dimensions[$name] = get_class($dimension);
$dimensionNames[] = $name;
}
}
}
$plugin = Manager::getInstance()->loadPlugin($pluginName);
$dimensions = Dimension::getAllDimensions();
$dimensions = array_merge($dimensions, Dimension::getDimensions($plugin));
foreach ($dimensions as $dimension) {
$name = $dimension->getName();
if (!empty($name)) {
$dimensions[$name] = get_class($dimension);
$dimensionNames[] = $name;
}
}
$dimensionNames = array_values(array_unique($dimensionNames));
$validate = function ($dimension) use($dimensions) {
if (empty($dimension)) {
return '';
}
if (!empty($dimension) && !array_key_exists($dimension, $dimensions)) {
throw new \InvalidArgumentException('Leave dimension either empty or use an existing one. You can also create a new dimension by calling .console generate:dimension before generating this report.');
}
return $dimension;
};
$actualDimension = $input->getOption('dimension');
if (null === $actualDimension) {
$dialog = $this->getHelperSet()->get('dialog');
$actualDimension = $dialog->askAndValidate($output, 'Enter the report dimension, for instance "Browser" (you can leave it either empty or use an existing one): ', $validate, false, null, $dimensionNames);
} else {
$validate($actualDimension);
}
if (empty($actualDimension)) {
return array('null', '');
}
$className = $dimensions[$actualDimension];
$parts = explode('\\', $className);
$name = end($parts);
return array('new ' . $name . '()', 'use ' . $className . ';');
}