[BUG]: Register CLI application throwing warning
Describe the bug Throwing deprecated warning
To Reproduce Based on documentation, to register CLI application code like this is required:
//cli.php
$console = new Console($container);
$arguments = [];
foreach ($argv as $k => $arg) {
if ($k === 1) {
$arguments['task'] = $arg;
} elseif ($k === 2) {
$arguments['action'] = $arg;
} elseif ($k >= 3) {
$arguments['params'][] = $arg;
}
}
$console->handle($arguments);
Which cause this kind of warning
Deprecated: Phalcon\Dispatcher\AbstractDispatcher::setActionName(): Passing null to parameter #1 ($actionName) of type string is deprecated in /var/www/application/apps/crontabs/cli.php on line 283
Details
- Phalcon version: 5.0.4
- PHP Version: PHP 8.1.7
- Operating System:
- Installation type: Ubuntu + Docker
- Server: Nginx
Could please specify what is on line 283 in cli.php file?
Could please specify what is on line 283 in cli.php file?
I've edited my previous post.
//line 283
$console->handle($arguments);
Thanks!
@dz3n If possible can you also post the task you are trying to run? (the task class) as well as the command you are invoking in the CLI?
I have the same problem. I solved it by always passing the second parameter, even though it's mainAction
@dz3n If possible can you also post the task you are trying to run? (the task class) as well as the command you are invoking in the CLI?
@niden
The task class doesn't matter really
the command is as follow:
/usr/local/bin/php /var/www/application/apps/crontabs/cli.php taskclass
without any action and params arguments
If I change it with second param like this
/usr/local/bin/php /var/www/application/apps/crontabs/cli.php taskclass main
I don't get warnings, so @Alistar84 is right, I need to pass second argument in order to get rid of this error
@dz3n I am having some trouble recreating this.
First of all in your code you can make a small change so that you don't have to run each command with main. Look at this:
//cli.php
$console = new Console($container);
$arguments = [
'action' => 'main',
];
foreach ($argv as $k => $arg) {
if ($k === 1) {
$arguments['task'] = $arg;
} elseif ($k === 2) {
$arguments['action'] = $arg;
} elseif ($k >= 3) {
$arguments['params'][] = $arg;
}
}
$console->handle($arguments);
Now for my test I am using the tasks in our testing suite. My cli.php is as follows:
<?php
declare(strict_types=1);
error_reporting(E_ALL);
ini_set("display_errors", 'On');
use Phalcon\Cli\Console;
use Phalcon\Cli\Dispatcher;
use Phalcon\Di\FactoryDefault\Cli as CliDI;
require_once 'vendor/autoload.php';
$container = new CliDI();
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Phalcon\Tests\Fixtures\Tasks');
$container->setShared('dispatcher', $dispatcher);
$console = new Console($container);
$arguments = [];
foreach ($argv as $k => $arg) {
if ($k === 1) {
$arguments['task'] = $arg;
} elseif ($k === 2) {
$arguments['action'] = $arg;
} elseif ($k >= 3) {
$arguments['params'][] = $arg;
}
}
try {
$console->handle($arguments);
} catch (\Exception $e) {
fwrite(STDERR, $e->getMessage() . PHP_EOL);
exit(1);
} catch (Throwable $throwable) {
fwrite(STDERR, $throwable->getMessage() . PHP_EOL);
exit(1);
}
Then I run (in a localr docker environment)
php -d extension=ext/modules/phalcon.so aa.php params
This executes the ParamsTask (tests/_data/fixtures/Tasks/ParamsTask.php) which does not have a mainAction in it. The result I get back is as expected:
Action 'main' was not found in handler 'params'
If I run it for the EchoTask (tests/_data/fixtures/Tasks/EchoTask.php) and modify that task slightly to echo 'Hello' in the main action I get
php -d extension=ext/modules/phalcon.so aa.php echo
Hello
I am not sure why this happens and I cannot get this to replicate. Feel free to email me directly ([email protected]) so that we can arrange some sort of screen sharing to figure this out. Alternatively, if this is not feasible, have a look above for any changes between my code and yours and let me know.
@dz3n never mind I managed to reproduce it
Resolved in https://github.com/phalcon/cphalcon/pull/16189
Thank you @dz3n