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
31 changes: 30 additions & 1 deletion libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\CMS\Menu\MenuFactoryInterface;
use Joomla\CMS\Pathway\Pathway;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Profiler\Profiler;
Expand Down Expand Up @@ -128,6 +129,15 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
*/
protected $authenticationPluginType = 'authentication';

/**
* The menu factory
*
* @var MenuFactoryInterface
*
* @since __DEPLOY_VERSION__
*/
private $menuFactory;

/**
* Class constructor.
*
Expand Down Expand Up @@ -515,7 +525,12 @@ public function getMenu($name = null, $options = array())
$options['app'] = $this;
}

return AbstractMenu::getInstance($name, $options);
if ($this->menuFactory === null)
{
$this->menuFactory = $this->getContainer()->get(MenuFactoryInterface::class);
}

return $this->menuFactory->createMenu($name, $options);
}

/**
Expand Down Expand Up @@ -1450,4 +1465,18 @@ private function setupLogging(): void
Log::addLogger(['text_file' => 'custom-logging.php'], $priority, $categories, $mode);
}
}

/**
* Sets the internal menu factory.
*
* @param MenuFactoryInterface $menuFactory The menu factory
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function setMenuFactory(MenuFactoryInterface $menuFactory): void
{
$this->menuFactory = $menuFactory;
}
}
8 changes: 8 additions & 0 deletions libraries/src/Menu/MenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
\defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseAwareTrait;

/**
* Default factory for creating Menu objects
Expand All @@ -19,6 +20,8 @@
*/
class MenuFactory implements MenuFactoryInterface
{
use DatabaseAwareTrait;

/**
* Creates a new Menu object for the requested format.
*
Expand All @@ -40,6 +43,11 @@ public function createMenu(string $client, array $options = []): AbstractMenu
throw new \InvalidArgumentException(Text::sprintf('JLIB_APPLICATION_ERROR_MENU_LOAD', $client), 500);
}

if (!array_key_exists('db', $options))
{
$options['db'] = $this->getDatabase();
}

return new $classname($options);
}
}
9 changes: 8 additions & 1 deletion libraries/src/Menu/SiteMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public function __construct($options = array())
{
// Extract the internal dependencies before calling the parent constructor since it calls $this->load()
$this->app = isset($options['app']) && $options['app'] instanceof CMSApplication ? $options['app'] : Factory::getApplication();
$this->db = isset($options['db']) && $options['db'] instanceof DatabaseDriver ? $options['db'] : Factory::getDbo();
$this->language = isset($options['language']) && $options['language'] instanceof Language ? $options['language'] : Factory::getLanguage();

if (!isset($options['db']) || !($options['db'] instanceof DatabaseDriver))
{
@trigger_error(sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
$options['db'] = Factory::getContainer()->get(DatabaseDriver::class);
}

$this->db = $options['db'];

parent::__construct($options);
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/src/Service/Provider/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Joomla\CMS\Console\UpdateCoreCommand;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Menu\MenuFactoryInterface;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Console\Application as BaseConsoleApplication;
use Joomla\Console\Loader\LoaderInterface;
Expand Down Expand Up @@ -82,6 +83,7 @@ function (Container $container)
$app->setLogger($container->get(LoggerInterface::class));
$app->setSession($container->get(SessionInterface::class));
$app->setUserFactory($container->get(UserFactoryInterface::class));
$app->setMenuFactory($container->get(MenuFactoryInterface::class));

return $app;
},
Expand All @@ -105,6 +107,7 @@ function (Container $container)
$app->setLogger($container->get(LoggerInterface::class));
$app->setSession($container->get(SessionInterface::class));
$app->setUserFactory($container->get(UserFactoryInterface::class));
$app->setMenuFactory($container->get(MenuFactoryInterface::class));

return $app;
},
Expand Down Expand Up @@ -192,6 +195,7 @@ function (Container $container) {
$app->setDispatcher($container->get('Joomla\Event\DispatcherInterface'));
$app->setLogger($container->get(LoggerInterface::class));
$app->setSession($container->get('Joomla\Session\SessionInterface'));
$app->setMenuFactory($container->get(MenuFactoryInterface::class));

return $app;
},
Expand Down
6 changes: 5 additions & 1 deletion libraries/src/Service/Provider/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Menu\MenuFactory;
use Joomla\CMS\Menu\MenuFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand Down Expand Up @@ -39,7 +40,10 @@ public function register(Container $container)
MenuFactoryInterface::class,
function (Container $container)
{
return new MenuFactory;
$factory = new MenuFactory;
$factory->setDatabase($container->get(DatabaseInterface::class));

return $factory;
},
true
);
Expand Down