Historically Joomla has been a predominantly web focused application with minimal CLI support. Developers writing CLI tools generally are having to write everything they need since Joomla doesn't provide a high level API for this, yet.
At the Framework level, we are adding a new Console package integrating Symfony's Console component and creating a proper infrastructure for the creation of CLI focused scripts using the core Joomla API.
With 4.0, we should look into how this package can be integrated into the CMS distro, how to migrate the existing suite of CLI tools to use the package, and how we can enable extensions to hook into this system to easily provide CLI tools.
Labels |
Added:
?
|
Labels |
Added:
?
|
Category | ⇒ | CLI |
This looks like something cool to have in 4.0.
Does this mean we no longer have to copy-paste the includes to load the Joomla framework?
It means there would be exactly one command line "front controller" in the package (think an index.php
but for CLI, possibly cli/joomla.php
). It would look something like this at a bare minimum:
<?php
// Set flag that this is a parent file.
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_BASE . '/includes/framework.php';
// Set up the container
\Joomla\CMS\Factory::getContainer()->share(
\Joomla\Console\Application::class,
function (\Joomla\DI\Container $container)
{
return new \Joomla\Console\Application;
},
true
);
$app = \Joomla\CMS\Factory::getContainer()->get(\Joomla\Console\Application::class);
\Joomla\CMS\Factory::$application = $app;
$app->execute();
Instead of writing separate application classes and having to bootstrap the entire architecture on your own, that single file would do the work. You would simply write a class defining your command's actions and that would be executed when running the CLI script.
Status | New | ⇒ | Discussion |
With #18141 merged we're in a state now that core supports the console package and most of the core scripts are migrated.
Right now the only way for extensions to add commands is a plugin in either the system or new console groups subscribing to Joomla\Application\ApplicationEvents::BEFORE_EXECUTE
(which uses a different internal event name than the web app's onBeforeExecute
, and because this internal identifier isn't a compatible PHP method name your plugins will have to use the "new approach" added in 4.0 and follow the event subscriber pattern as done in the Joomla update quickicon plugin). It would be nice if we can improve things a bit so that commands can be picked up by some kind of convention as well.
Labels |
Added:
J4 Issue
|
I don't see this going any further at the core architecture level than where it already is. So, closing. The base API's there, if someone wants to find a way to solve the DX issues that remain please do so.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-07-23 19:06:12 |
Closed_By | ⇒ | mbabker |
Agreed. This new console package is excellent - and combining this app with CMSApplicationInterface in J4 is going to allow us to do some really cool things :)