Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Add the controllers/invokables key when creating controllers #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/ZFTool/Controller/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ public function controllerAction()
$phtml = true;
}

// Add the new controller key to the invokables
$moduleConfig = require "$path/module/$module/config/module.config.php";
$invokableKey = ucfirst($module) . '\Controller\\' . $ucName;

if (!in_array($invokableKey, $moduleConfig['controllers']['invokables'])) {
$moduleConfig['controllers']['invokables'][$invokableKey] = ucfirst($module) . '\Controller\\' . $controller;
copy("$path/module/$module/config/module.config.php", "$path/module/$module/config/module.config.old");

$content = <<<EOD
<?php
/**
* Configuration file generated by ZFTool
* The previous configuration file is stored in module.config.old
*
* @see https://github.com/zendframework/ZFTool
*/

EOD;

$content .= 'return ' . Skeleton::exportConfig($moduleConfig) . ";\n";
file_put_contents("$path/module/$module/config/module.config.php", $content);
}

if (file_put_contents($ctrlPath, $file->generate()) && $phtml == true) {
$console->writeLine("The controller $name has been created in module $module.", Color::GREEN);
} else {
Expand Down