Back to LibraryHelper class

Method loadLibrary

protected static bool
loadLibrary
(mixed $element)
Load the installed library into the libraries property.
Parameters
  • string $element The element value for the extension
Returns
  • bool True on success
Since
  • 3.7.0
Class: LibraryHelper
Project: Joomla

Method loadLibrary - Source code

/**
 * Load the installed library into the libraries property.
 *
 * @param   string  $element  The element value for the extension
 *
 * @return  boolean  True on success
 *
 * @since   3.7.0
 */
protected static function loadLibrary($element)
{
    $loader = function ($element) {
        $db = Factory::getDbo();
        $query = $db->getQuery(true)->select($db->quoteName(['extension_id', 'element', 'params', 'enabled'], ['id', 'option', null, null]))->from($db->quoteName('#__extensions'))->where($db->quoteName('type') . ' = ' . $db->quote('library'))->where($db->quoteName('element') . ' = :element')->bind(':element', $element);
        $db->setQuery($query);
        return $db->loadObject();
    };
    /** @var CallbackController $cache */
    $cache = Factory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController('callback', ['defaultgroup' => '_system']);
    try {
        static::$libraries[$element] = $cache->get($loader, array($element), __METHOD__ . $element);
    } catch (CacheExceptionInterface $e) {
        static::$libraries[$element] = $loader($element);
    }
    if (empty(static::$libraries[$element])) {
        // Fatal error.
        $error = Text::_('JLIB_APPLICATION_ERROR_LIBRARY_NOT_FOUND');
        Log::add(Text::sprintf('JLIB_APPLICATION_ERROR_LIBRARY_NOT_LOADING', $element, $error), Log::WARNING, 'jerror');
        return false;
    }
    return true;
}