Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion administrator/includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@
// Set profiler start time and memory usage and mark afterLoad in the profiler.
JDEBUG ? JProfiler::getInstance('Application')->setStart($startTime, $startMem)->mark('afterLoad') : null;

// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();

/*
* Alias the session service keys to the web session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for alised class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session.web', 'session.web.administrator')
->alias('session', 'session.web.administrator')
->alias('JSession', 'session.web.administrator')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.administrator')
->alias(\Joomla\Session\Session::class, 'session.web.administrator')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.administrator');

// Instantiate the application.
$app = \Joomla\CMS\Factory::getContainer()->get(\Joomla\CMS\Application\AdministratorApplication::class);
$app = $container->get(\Joomla\CMS\Application\AdministratorApplication::class);

// Set the application as global app
\Joomla\CMS\Factory::$application = $app;
Expand Down
16 changes: 16 additions & 0 deletions cli/joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
// Get the framework.
require_once JPATH_BASE . '/includes/framework.php';

// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();

/*
* Alias the session service keys to the CLI session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for alised class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session', 'session.cli')
->alias('JSession', 'session.cli')
->alias(\Joomla\CMS\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\SessionInterface::class, 'session.cli');

$app = \Joomla\CMS\Factory::getContainer()->get(\Joomla\Console\Application::class);
\Joomla\CMS\Factory::$application = $app;
$app->execute();
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"symfony/console": "3.4.*",
"symfony/debug": "3.4.*",
"symfony/ldap": "3.4.*",
"symfony/options-resolver": "3.4.*",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference this was already a transient dependency, but since I am now explicitly using it it's now listed explicitly here.

"symfony/web-link": "3.4.*",
"symfony/yaml": "3.4.*",
"wamania/php-stemmer": "^1.2"
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@
// Set profiler start time and memory usage and mark afterLoad in the profiler.
JDEBUG ? JProfiler::getInstance('Application')->setStart($startTime, $startMem)->mark('afterLoad') : null;

// Get the application.
$app = \Joomla\CMS\Factory::getContainer()->get(\Joomla\CMS\Application\SiteApplication::class);
// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();

/*
* Alias the session service keys to the web session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for alised class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session.web', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');

// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);

// Set the application as global app
\Joomla\CMS\Factory::$application = $app;
Expand Down
14 changes: 14 additions & 0 deletions installation/includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,19 @@
$container = \Joomla\CMS\Factory::getContainer();
$container->registerServiceProvider(new \Joomla\CMS\Installation\Service\Provider\Application);

/*
* Alias the session service keys to the web session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for alised class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session.web', 'session.web.installation')
->alias('session', 'session.web.installation')
->alias('JSession', 'session.web.installation')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.installation')
->alias(\Joomla\Session\Session::class, 'session.web.installation')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.installation');

// Instantiate and execute the application
$container->get(\Joomla\CMS\Installation\Application\InstallationApplication::class)->execute();
66 changes: 43 additions & 23 deletions libraries/src/Console/SessionGcCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,19 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Console\AbstractCommand;
use Joomla\DI\ContainerAwareInterface;
use Joomla\DI\ContainerAwareTrait;
use Joomla\Session\SessionInterface;
use Symfony\Component\Console\Input\InputOption;

/**
* Console command for performing session garbage collection
*
* @since 4.0.0
*/
class SessionGcCommand extends AbstractCommand
class SessionGcCommand extends AbstractCommand implements ContainerAwareInterface
{
/**
* The session object.
*
* @var SessionInterface
* @since 4.0.0
*/
private $session;

/**
* Instantiate the command.
*
* @param SessionInterface $session The session object.
*
* @since 4.0.0
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;

parent::__construct();
}
use ContainerAwareTrait;

/**
* Execute the command.
Expand All @@ -55,7 +38,14 @@ public function execute(): int

$symfonyStyle->title('Running Session Garbage Collection');

if ($this->session->gc() === false)
$session = $this->getSessionService($this->getApplication()->getConsoleInput()->getOption('application'));

$gcResult = $session->gc();

// Destroy the session started for this process
$session->destroy();

if ($gcResult === false)
{
$symfonyStyle->error('Garbage collection was not completed. Either the operation failed or is not supported on your platform.');

Expand All @@ -78,12 +68,42 @@ protected function initialise()
{
$this->setName('session:gc');
$this->setDescription('Performs session garbage collection');
$this->addOption('application', 'app', InputOption::VALUE_OPTIONAL, 'The application to perform garbage collection for.', 'site');
$this->setHelp(
<<<EOF
The <info>%command.name%</info> command runs PHP's garbage collection operation for session data

<info>php %command.full_name%</info>

This command defaults to performing garbage collection for the frontend (site) application. To run garbage collection
for another application, you can specify it with the <info>--application</info> option.

<info>php %command.full_name% --application=[APPLICATION]</info>
EOF
);
}

/**
* Get the session service for the requested application.
*
* @param string $application The application session service to retrieve
*
* @return SessionInterface
*
* @since 4.0.0
*/
private function getSessionService(string $application): SessionInterface
{
if (!$this->getContainer()->has("session.web.$application"))
{
throw new \InvalidArgumentException(
sprintf(
'The `%s` application is not a valid option.',
$application
)
);
}

return $this->getContainer()->get("session.web.$application");
}
}
9 changes: 8 additions & 1 deletion libraries/src/Service/Provider/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ public function register(Container $container)
SessionGcCommand::class,
function (Container $container)
{
return new SessionGcCommand($container->get('session'));
/*
* The command will need the same session handler that web apps use to run correctly,
* since this is based on an option we need to inject the container
*/
$command = new SessionGcCommand;
$command->setContainer($container);

return $command;
},
true
);
Expand Down
Loading