Back to Installer class

Method getAdapters

public string[]
getAdapters
(mixed $options = array(), array $custom = array())
Gets a list of available install adapters.
Parameters
  • array $options An array of options to inject into the adapter
  • array $custom Array of custom install adapters
Returns
  • string[] An array of the class names of available install adapters.
Since
  • 3.4
Class: Installer
Project: Joomla

Method getAdapters - Source code

/**
 * Gets a list of available install adapters.
 *
 * @param   array  $options  An array of options to inject into the adapter
 * @param   array  $custom   Array of custom install adapters
 *
 * @return  string[]  An array of the class names of available install adapters.
 *
 * @since   3.4
 */
public function getAdapters($options = array(), array $custom = array())
{
    $files = new \DirectoryIterator($this->_basepath . '/' . $this->_adapterfolder);
    // Process the core adapters
    foreach ($files as $file) {
        $fileName = $file->getFilename();
        // Only load for php files.
        if (!$file->isFile() || $file->getExtension() !== 'php') {
            continue;
        }
        // Derive the class name from the filename.
        $name = str_ireplace('.php', '', trim($fileName));
        $name = str_ireplace('adapter', '', trim($name));
        $class = rtrim($this->_classprefix, '\\') . '\\' . ucfirst($name) . 'Adapter';
        if (!class_exists($class)) {
            // Not namespaced
            $class = $this->_classprefix . ucfirst($name);
        }
        // Core adapters should autoload based on classname, keep this fallback just in case
        if (!class_exists($class)) {
            // Try to load the adapter object
            \JLoader::register($class, $this->_basepath . '/' . $this->_adapterfolder . '/' . $fileName);
            if (!class_exists($class)) {
                // Skip to next one
                continue;
            }
        }
        $adapters[] = $name;
    }
    // Add any custom adapters if specified
    if (\count($custom) >= 1) {
        foreach ($custom as $adapter) {
            // Setup the class name
            // @todo - Can we abstract this to not depend on the Joomla class namespace without PHP namespaces?
            $class = $this->_classprefix . ucfirst(trim($adapter));
            // If the class doesn't exist we have nothing left to do but look at the next type. We did our best.
            if (!class_exists($class)) {
                continue;
            }
            $adapters[] = str_ireplace('.php', '', $fileName);
        }
    }
    return $adapters;
}