Hello, I have the same Problem as described here: https://forum.phalcon.io/discussion/4295/namespaced-tasks-in-cli-why-not-working
Unfortunately that thread was marked as solved by accident, but is not solved. Therefore I want to "reopen" that thread here. Here's my code:
<?php
(...)
$di = new CliDI();
// Define path to application directory
defined('CLI_PATH') || define('CLI_PATH', realpath(dirname(__FILE__)));
// Load the configuration file (if any)
if (is_readable(__DIR__ . '/../app/config/config.php')) {
$config = include __DIR__ . '/../app/config/config.php';
} else {
throw new \Exception('Can not read config');
}
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
array('SomeName\Task' => $config->application->classesDir . 'Task')
)->register();
//Create a console application
$console = new ConsoleApp();
$console->setDI($di);
var_dump(get_class(new \SomeName\Task\MainTask())); //outputs
(...)
try {
// handle incoming arguments
var_dump($arguments);
$console->handle($arguments);
} catch (\Phalcon\Exception $e) {
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
exit(255);
}
The console output is is as follows:
string(23) "SomeName\Task\MainTask"
array(0) {
}
string(39) "MainTask handler class cannot be loaded"
string(253) "#0 [internal function]: Phalcon\CLI\Dispatcher->_throwDispatchException('MainTask handle...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /home/dompie/workspace/project/app/cli.php(56): Phalcon\CLI\Console->handle(Array)
#3 {main}"
Any suggestions how I can convince phalcon to load namespaced classes from CLI?