Back to WebApplication class

Method getInstance

public static \Joomla\CMS\Application\WebApplication
getInstance
(mixed $name = null)
Returns a reference to the global WebApplication object, only creating it if it doesn't already exist.
Parameters
  • string $name The name (optional) of the WebApplication class to instantiate.
Returns
  • \Joomla\CMS\Application\WebApplication
Since
  • 1.7.3
Deprecated
  • 5.0
-
  • \RuntimeException

Method getInstance - Source code

/**
 * Returns a reference to the global WebApplication object, only creating it if it doesn't already exist.
 *
 * This method must be invoked as: $web = WebApplication::getInstance();
 *
 * @param   string  $name  The name (optional) of the WebApplication class to instantiate.
 *
 * @return  WebApplication
 *
 * @since       1.7.3
 * @throws      \RuntimeException
 * @deprecated  5.0 Use \Joomla\CMS\Factory::getContainer()->get($name) instead
 */
public static function getInstance($name = null)
{
    // Only create the object if it doesn't exist.
    if (empty(static::$instance)) {
        if (!is_subclass_of($name, '\\Joomla\\CMS\\Application\\WebApplication')) {
            throw new \RuntimeException(sprintf('Unable to load application: %s', $name), 500);
        }
        static::$instance = new $name();
    }
    return static::$instance;
}