<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace com_eorisis_pixels\framework\install_package\lib\core\cms;
\defined('_JEXEC') or die;

use version_compare, class_exists;
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use EorisisFactory, JLoader;

if (!class_exists('EorisisFactory', false))
{
	if (version_compare(JVERSION, '3.8', '>='))
	{
		JLoader::registerAlias('EorisisFactory', '\\Joomla\\CMS\\Factory');
	}
	else
	{
		JLoader::registerAlias('EorisisFactory', 'JFactory');
	}
}

class application
{
	public function __construct() {}

	// --------------------------------------------------

	public static function get()
	{
		return EorisisFactory::getApplication();
	}

	// --------------------------------------------------

	public static function register_class(string $class, string $path, bool $force = true)
	{
		JLoader::register($class, $path, $force);
	}

	// --------------------------------------------------

	public static function cache(string $group = '', string $handler = 'callback', $storage = null)
	{
		// @param   string  $group    The cache group name
		// @param   string  $handler  The handler to use
		// @param   string  $storage  The storage method

		if (version_compare(JVERSION, '4.3', '>='))
		{
			$options = ['defaultgroup' => $group];

			if ($storage)
			{
				$options['storage'] = $storage;
			}

			$class = CacheControllerFactoryInterface::class;
			return EorisisFactory::getContainer()->get($class)->createCacheController($handler, $options);
		}

		return EorisisFactory::getCache($group, $handler, $storage);
	}

	// --------------------------------------------------

	public static function dbo()
	{
		static $dbo = null;
		if ($dbo === null)
		{
			if (version_compare(JVERSION, 4, '>='))
			{
				$dbo = EorisisFactory::getContainer()->get('DatabaseDriver');
			}
			else
			{
				$dbo = EorisisFactory::getDbo();
			}
		}

		return $dbo;
	}

	// --------------------------------------------------

	public static function set_message(string $txt, string $type = 'notice')
	{
		// message, notice, warning, error
		self::get()->enqueueMessage($txt, $type);
	}
}
