Back to CliApplication class

Method getInstance

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

Method getInstance - Source code

/**
 * Returns a reference to the global CliApplication object, only creating it if it doesn't already exist.
 *
 * This method must be invoked as: $cli = CliApplication::getInstance();
 *
 * @param   string  $name  The name (optional) of the Application Cli class to instantiate.
 *
 * @return  CliApplication
 *
 * @since       1.7.0
 * @deprecated  5.0 Load the app through the container
 * @throws  \RuntimeException
 */
public static function getInstance($name = null)
{
    // Only create the object if it doesn't exist.
    if (empty(static::$instance)) {
        if (!class_exists($name)) {
            throw new \RuntimeException(sprintf('Unable to load application: %s', $name), 500);
        }
        static::$instance = new $name();
    }
    return static::$instance;
}