1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121:
<?php
namespace NetBazzlineZfLocatorGenerator\Controller\Console;
use Exception;
use InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\PipeInterface;
use Zend\Console\ColorInterface;
use ZfConsoleHelper\Controller\Console\AbstractConsoleController;
class IndexController extends AbstractConsoleController
{
private $configuration;
private $processPipe;
public function setConfiguration(array $configuration)
{
$this->configuration = $configuration;
}
public function setProcessPipe(PipeInterface $processPipe)
{
$this->processPipe = $processPipe;
}
public function generateAction()
{
$beVerbose = $this->beVerbose();
$configuration = $this->configuration;
$console = $this->getConsole();
$processPipe = $this->processPipe;
try {
$this->throwExceptionIfNotCalledInsideAnCliEnvironment();
$configuration = $configuration['name_to_configuration_path'];
if ($this->hasParameter('locator_name')) {
$locatorName = $this->getParameter('locator_name');
if (!isset($configuration[$locatorName])) {
throw new InvalidArgumentException(
'invalid locator name provided'
);
}
$namesToPath = array($locatorName => $configuration[$locatorName]);
} else {
$namesToPath = $configuration;
}
foreach ($namesToPath as $name => $path) {
if ($beVerbose) {
$console->writeLine(
'generating "' . $name . '" by using configuration file "' . $path . '"'
);
} else {
$console->write('.');
}
$arguments = array(
__FILE__,
$path
);
try {
$processPipe->execute($arguments);
} catch (Exception $exception) {
$console->setColor(ColorInterface::LIGHT_RED);
$console->writeLine('could not generate locator for "' . $name . '"');
$console->writeLine('error: ' . $exception->getMessage());
$console->resetColor();
}
}
} catch (Exception $exception) {
$this->handleException($exception);
}
}
public function listAction()
{
$configuration = $this->configuration;
$console = $this->getConsole();
try {
$this->throwExceptionIfNotCalledInsideAnCliEnvironment();
$configuration = $configuration['name_to_configuration_path'];
foreach ($configuration as $name => $path) {
$console->writeLine('locator: ' . $name . ' with configuration file "' . $path . '"');
}
} catch (Exception $exception) {
$this->handleException($exception);
}
}
protected function beVerbose()
{
return $this->hasBooleanParameter('v', 'verbose');
}
}