Back to Session class

Method getHandlers

public static array
getHandlers
()
Get the available session handlers
Returns
  • array An array of available session handlers
Since
  • 4.0.0
Class: Session
Project: Joomla

Method getHandlers - Source code

/**
 * Get the available session handlers
 *
 * @return  array  An array of available session handlers
 *
 * @since   4.0.0
 */
public static function getHandlers() : array
{
    $connectors = [];
    // Get an iterator and loop trough the handler classes.
    $iterator = new \DirectoryIterator(JPATH_LIBRARIES . '/vendor/joomla/session/src/Handler');
    foreach ($iterator as $file) {
        $fileName = $file->getFilename();
        // Only load for PHP files.
        if (!$file->isFile() || $file->getExtension() !== 'php') {
            continue;
        }
        // Derive the class name from the type.
        $class = str_ireplace('.php', '', '\\Joomla\\Session\\Handler\\' . $fileName);
        // 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;
        }
        // Sweet!  Our class exists, so now we just need to know if it passes its test method.
        if ($class::isSupported()) {
            // Connector names should not have file the handler suffix or the file extension.
            $connectors[] = str_ireplace('Handler.php', '', $fileName);
        }
    }
    return $connectors;
}