Skip to content
Snippets Groups Projects
Commit c9c945f8 authored by Demian Katz's avatar Demian Katz
Browse files

Added command line dynamic route generator.

parent e7a7af3e
No related merge requests found
...@@ -79,6 +79,7 @@ class Module implements \Zend\ModuleManager\Feature\ConsoleUsageProviderInterfac ...@@ -79,6 +79,7 @@ class Module implements \Zend\ModuleManager\Feature\ConsoleUsageProviderInterfac
return [ return [
'generate extendservice' => 'Override a service with a new child class', 'generate extendservice' => 'Override a service with a new child class',
'generate nontabrecordaction' => 'Add routes for non-tab record action', 'generate nontabrecordaction' => 'Add routes for non-tab record action',
'generate dynamicroute' => 'Add a dynamic route',
'generate recordroute' => 'Add a record route', 'generate recordroute' => 'Add a record route',
'generate staticroute' => 'Add a static route', 'generate staticroute' => 'Add a static route',
'harvest harvest_oai' => 'OAI-PMH harvester', 'harvest harvest_oai' => 'OAI-PMH harvester',
......
...@@ -43,6 +43,53 @@ use Zend\Console\Console; ...@@ -43,6 +43,53 @@ use Zend\Console\Console;
*/ */
class GenerateController extends AbstractBase class GenerateController extends AbstractBase
{ {
/**
* Add a new dynamic route definition
*
* @return \Zend\Console\Response
*/
public function dynamicrouteAction()
{
$argv = $this->consoleOpts->getRemainingArgs();
if (!isset($argv[3])) {
Console::writeLine(
"Usage: {$_SERVER['argv'][0]} [route] [controller] [action]"
. " [target_module]"
);
Console::writeLine(
"\troute - the route name (used by router), e.g. customList"
);
Console::writeLine(
"\tcontroller - the controller name (used in URL), e.g. MyResearch"
);
Console::writeLine(
"\taction - the action and segment params, e.g. CustomList/[:id]"
);
Console::writeLine(
"\ttarget_module - the module where the new route will be generated"
);
return $this->getFailureResponse();
}
$route = $argv[0];
$controller = $argv[1];
$action = $argv[2];
$module = $argv[3];
// Create backup of configuration
$configPath = $this->getModuleConfigPath($module);
$this->backUpFile($configPath);
// Append the route
$config = include $configPath;
$routeGenerator = new \VuFind\Route\RouteGenerator();
$routeGenerator->addDynamicRoute($config, $route, $controller, $action);
// Write updated configuration
$this->writeModuleConfig($configPath, $config);
return $this->getSuccessResponse();
}
/** /**
* Extend an existing service * Extend an existing service
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment