Skip to content

Commit

Permalink
call model method by -m prop
Browse files Browse the repository at this point in the history
  • Loading branch information
parsgit committed Dec 6, 2023
1 parent 2fece56 commit 1e99768
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/CallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ protected function configure()
Directory::initDefaultStructure();
$this->addArgument('name', InputArgument::REQUIRED, 'Controller->method Name');
$this->addOption('params', 'p', InputArgument::OPTIONAL);
$this->addOption('model', 'm', InputOption::VALUE_NEGATABLE);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$params = $input->getOption('params')??"'[]'";
$model = $input->getOption('model');


$params = str_replace("'", '', $params);
Expand All @@ -38,7 +40,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$controller = $array[0];
$method = $array[1];

$dir = Directory::get('controllers');
if($model){
$dir = Directory::get('models');
}
else{
$dir = Directory::get('controllers');
}

$class = "$dir\\$controller";

Expand All @@ -47,11 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$controller = new $class;


if (method_exists($controller, '__init')) {
$controller->__init();
}


if (method_exists($controller, $method)) {

$data = $controller->{$method}(...$params);
Expand All @@ -67,11 +69,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("<error>Method $method not found in $class.php</error>");
}


if (method_exists($controller, '__end')) {
$controller->__end();
}

return Command::SUCCESS;
}

Expand Down

0 comments on commit 1e99768

Please sign in to comment.