I have a bunch of symfony tasks to send different kind of emails. For example, I have a sendMailConfirmationTask, sendMailAlertContactTask, sendMailBlogTask etc...
My goal is to have one "master" class : sendMailBaseTask, that will, based on the correct parameter, execute the right task.
So as an example, when I execute "php symfony sendMail:base --object=confirmation", it creates an instance of sendMailBaseTask, and then, the following line makes the call to the right task :
$this->runTask($prefix . $task_name, array(), $options); // $prefix . $task_name = "sendMail:confirmation" for example
Through the CLI, both methods works fine, I can trigger my confirmation email these ways :
php symfony sendMail:base --object=confirmation --to=some@email.com
php symfony sendMailConfirmation --to=some@email.com
Where it becomes tricky is when I want to run my task within an sfAction. I'd like to run my task whenever someone registers onto my application for example. So here's the piece of code I've tried without luck :
chdir(sfConfig::get('sf_root_dir'));
$task = new sendMailBaseTask($configuration->getEventDispatcher(), new sfFormatter());
$rc = $task->run(array(), array('object' => 'confirmation', 'to' => $email, 'hash' => $hash));
chdir($current_dir);
This gives the following error : "Unable to create a task as no command application is associated with this task yet."
But, if instead of creating a sendMailBaseTask instance I create a sendMailConfirmationTask, it works fine.
I could do it that way, but that's not the way I want it working, so if anyone has a clue... Thanks!