Skip to content

Instantly share code, notes, and snippets.

@renekreijveld
Created May 28, 2024 10:36
Show Gist options
  • Save renekreijveld/03cb8ef52907a7c1827c318e4f0a6683 to your computer and use it in GitHub Desktop.
Save renekreijveld/03cb8ef52907a7c1827c318e4f0a6683 to your computer and use it in GitHub Desktop.
Joomla 5 CLI
<?php
use \Joomla\CMS\Factory;
const _JEXEC = 1;
define( 'JDEBUG', false );
define( 'JPATH_BASE', dirname( dirname( __FILE__ ) ) );
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// Boot the DI container
$container = Factory::getContainer();
$session_alias = 'session.web';
$session_suffix = 'web.site';
// Alias the session service key to the web session service.
$container->alias( $session_alias, 'session.' . $session_suffix )
->alias( 'JSession', 'session.' . $session_suffix )
->alias( \Joomla\CMS\Session\Session::class, 'session.' . $session_suffix )
->alias( \Joomla\Session\Session::class, 'session.' . $session_suffix )
->alias( \Joomla\Session\SessionInterface::class, 'session.' . $session_suffix );
// Instantiate the application.
$app = $container->get( \Joomla\CMS\Application\SiteApplication::class);
// Set the application as global app
Factory::$application = $app;
// Setup database
$db = Factory::getContainer()->get( 'DatabaseDriver' );
/* your code comes here */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment