J4 Issue ? ?
avatar mbabker
mbabker
5 Sep 2017

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.

avatar mbabker mbabker - open - 5 Sep 2017
avatar joomla-cms-bot joomla-cms-bot - change - 5 Sep 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Sep 2017
avatar mbabker mbabker - change - 5 Sep 2017
Labels Added: ?
avatar mbabker mbabker - labeled - 5 Sep 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Sep 2017
Category CLI
avatar wilsonge
wilsonge - comment - 7 Sep 2017

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 :)

avatar roland-d
roland-d - comment - 9 Sep 2017

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?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17879.

avatar mbabker
mbabker - comment - 10 Sep 2017

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.

avatar roland-d
roland-d - comment - 17 Sep 2017

@mbabker Thank you for explaining. Sounds like the way to go.

avatar franz-wohlkoenig franz-wohlkoenig - change - 18 Sep 2017
Status New Discussion
avatar mbabker
mbabker - comment - 28 Sep 2017

#18141 is the PR setting up the core infrastructure for the console.

avatar mbabker
mbabker - comment - 18 Nov 2017

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.

avatar brianteeman brianteeman - change - 25 Mar 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar mbabker
mbabker - comment - 23 Jul 2018

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.

avatar mbabker mbabker - close - 23 Jul 2018
avatar mbabker mbabker - change - 23 Jul 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-07-23 19:06:12
Closed_By mbabker

Add a Comment

Login with GitHub to post a comment