From 50320417d79c62279ee1f480b62bae72322d64f8 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Mon, 15 Jul 2024 00:41:18 +0200 Subject: [PATCH] Removing Adapter and AdapterInstance classes --- libraries/src/Adapter/Adapter.php | 226 ------------------ libraries/src/Adapter/AdapterInstance.php | 81 ------- .../compat/src/classmap/classmap.php | 3 - 3 files changed, 310 deletions(-) delete mode 100644 libraries/src/Adapter/Adapter.php delete mode 100644 libraries/src/Adapter/AdapterInstance.php diff --git a/libraries/src/Adapter/Adapter.php b/libraries/src/Adapter/Adapter.php deleted file mode 100644 index e415206781180..0000000000000 --- a/libraries/src/Adapter/Adapter.php +++ /dev/null @@ -1,226 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\CMS\Adapter; - -use Joomla\CMS\Factory; -use Joomla\CMS\Object\LegacyErrorHandlingTrait; -use Joomla\CMS\Object\LegacyPropertyManagementTrait; -use Joomla\Database\DatabaseAwareInterface; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Adapter Class - * Retains common adapter pattern functions - * Class harvested from joomla.installer.installer - * - * @since 1.6 - * @deprecated 4.3 will be removed in 6.0 - * Will be removed without replacement - */ -class Adapter -{ - use LegacyErrorHandlingTrait; - use LegacyPropertyManagementTrait; - - /** - * Associative array of adapters - * - * @var static[] - * @since 1.6 - */ - protected $_adapters = []; - - /** - * Adapter Folder - * - * @var string - * @since 1.6 - */ - protected $_adapterfolder = 'adapters'; - - /** - * Adapter Class Prefix - * - * @var string - * @since 1.6 - */ - protected $_classprefix = 'J'; - - /** - * Base Path for the adapter instance - * - * @var string - * @since 1.6 - */ - protected $_basepath = null; - - /** - * Database Connector Object - * - * @var \Joomla\Database\DatabaseDriver - * @since 1.6 - */ - protected $_db; - - /** - * Constructor - * - * @param string $basepath Base Path of the adapters - * @param string $classprefix Class prefix of adapters - * @param string $adapterfolder Name of folder to append to base path - * - * @since 1.6 - */ - public function __construct($basepath, $classprefix = null, $adapterfolder = null) - { - $this->_basepath = $basepath; - $this->_classprefix = $classprefix ?: 'J'; - $this->_adapterfolder = $adapterfolder ?: 'adapters'; - - $this->_db = Factory::getDbo(); - - // Ensure BC, when removed in 5, then the db must be set with setDatabase explicitly - if ($this instanceof DatabaseAwareInterface) { - $this->setDatabase($this->_db); - } - } - - /** - * Get the database connector object - * - * @return \Joomla\Database\DatabaseDriver Database connector object - * - * @since 1.6 - */ - public function getDbo() - { - return $this->_db; - } - - /** - * Return an adapter. - * - * @param string $name Name of adapter to return - * @param array $options Adapter options - * - * @return static|boolean Adapter of type 'name' or false - * - * @since 1.6 - */ - public function getAdapter($name, $options = []) - { - if (\array_key_exists($name, $this->_adapters)) { - return $this->_adapters[$name]; - } - - if ($this->setAdapter($name, $options)) { - return $this->_adapters[$name]; - } - - return false; - } - - /** - * Set an adapter by name - * - * @param string $name Adapter name - * @param object $adapter Adapter object - * @param array $options Adapter options - * - * @return boolean True if successful - * - * @since 1.6 - */ - public function setAdapter($name, &$adapter = null, $options = []) - { - if (\is_object($adapter)) { - $this->_adapters[$name] = &$adapter; - - return true; - } - - $class = rtrim($this->_classprefix, '\\') . '\\' . ucfirst($name); - - if (class_exists($class)) { - $this->_adapters[$name] = new $class($this, $this->_db, $options); - - return true; - } - - $class = rtrim($this->_classprefix, '\\') . '\\' . ucfirst($name) . 'Adapter'; - - if (class_exists($class)) { - $this->_adapters[$name] = new $class($this, $this->_db, $options); - - return true; - } - - $fullpath = $this->_basepath . '/' . $this->_adapterfolder . '/' . strtolower($name) . '.php'; - - if (!is_file($fullpath)) { - return false; - } - - // Try to load the adapter object - $class = $this->_classprefix . ucfirst($name); - - \JLoader::register($class, $fullpath); - - if (!class_exists($class)) { - return false; - } - - $this->_adapters[$name] = new $class($this, $this->_db, $options); - - return true; - } - - /** - * Loads all adapters. - * - * @param array $options Adapter options - * - * @return void - * - * @since 1.6 - */ - public function loadAllAdapters($options = []) - { - $files = new \DirectoryIterator($this->_basepath . '/' . $this->_adapterfolder); - - /** @type $file \DirectoryIterator */ - foreach ($files as $file) { - $fileName = $file->getFilename(); - - // Only load for php files. - if (!$file->isFile() || $file->getExtension() != 'php') { - continue; - } - - // Try to load the adapter object - require_once $this->_basepath . '/' . $this->_adapterfolder . '/' . $fileName; - - // Derive the class name from the filename. - $name = str_ireplace('.php', '', ucfirst(trim($fileName))); - $class = $this->_classprefix . ucfirst($name); - - if (!class_exists($class)) { - // Skip to next one - continue; - } - - $adapter = new $class($this, $this->_db, $options); - $this->_adapters[$name] = clone $adapter; - } - } -} diff --git a/libraries/src/Adapter/AdapterInstance.php b/libraries/src/Adapter/AdapterInstance.php deleted file mode 100644 index 49023952b8ed0..0000000000000 --- a/libraries/src/Adapter/AdapterInstance.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\CMS\Adapter; - -use Joomla\CMS\Factory; -use Joomla\CMS\Object\LegacyErrorHandlingTrait; -use Joomla\CMS\Object\LegacyPropertyManagementTrait; -use Joomla\Database\DatabaseDriver; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Adapter Instance Class - * - * @since 1.6 - * @deprecated 4.3 will be removed in 6.0 - * Will be removed without replacement - */ -class AdapterInstance -{ - use LegacyErrorHandlingTrait; - use LegacyPropertyManagementTrait; - - /** - * Parent - * - * @var Adapter - * @since 1.6 - */ - protected $parent = null; - - /** - * Database - * - * @var DatabaseDriver - * @since 1.6 - */ - protected $db = null; - - /** - * Constructor - * - * @param Adapter $parent Parent object - * @param DatabaseDriver $db Database object - * @param array $options Configuration Options - * - * @since 1.6 - */ - public function __construct(Adapter $parent, DatabaseDriver $db, array $options = []) - { - // Set the properties from the options array that is passed in - $this->setProperties($options); - - // Set the parent and db in case $options for some reason overrides it. - $this->parent = $parent; - - // Pull in the global dbo in case something happened to it. - $this->db = $db ?: Factory::getDbo(); - } - - /** - * Retrieves the parent object - * - * @return Adapter - * - * @since 1.6 - */ - public function getParent() - { - return $this->parent; - } -} diff --git a/plugins/behaviour/compat/src/classmap/classmap.php b/plugins/behaviour/compat/src/classmap/classmap.php index f46d916d1a727..4dbbddb18700f 100644 --- a/plugins/behaviour/compat/src/classmap/classmap.php +++ b/plugins/behaviour/compat/src/classmap/classmap.php @@ -480,9 +480,6 @@ JLoader::registerAlias('JFormFilterInt_Array', '\\Joomla\\CMS\\Form\\Filter\\IntarrayFilter', '6.0'); -JLoader::registerAlias('JAdapter', '\\Joomla\\CMS\\Adapter\\Adapter', '6.0'); -JLoader::registerAlias('JAdapterInstance', '\\Joomla\\CMS\\Adapter\\AdapterInstance', '6.0'); - JLoader::registerAlias('JHtmlAccess', '\\Joomla\\CMS\\HTML\\Helpers\\Access', '6.0'); JLoader::registerAlias('JHtmlActionsDropdown', '\\Joomla\\CMS\\HTML\\Helpers\\ActionsDropdown', '6.0'); JLoader::registerAlias('JHtmlAdminLanguage', '\\Joomla\\CMS\\HTML\\Helpers\\AdminLanguage', '6.0');