0

I was going through codes of application, what document is and it has method getInstance method

public static function getInstance($client, $config = array(), $prefix = 'J')
{
    return JApplicationCms::getInstance($client);
}

Then went to JapplicationCms class that wasn't there i managed to find class CMSApplication it has definition

public static function getInstance($name = null)
{
    if (empty(static::$instances[$name]))
    {
        // Create a CMSApplication object.
        $classname = '\JApplication' . ucfirst($name);

        if (!class_exists($classname))
        {
            throw new \RuntimeException(\JText::sprintf('JLIB_APPLICATION_ERROR_APPLICATION_LOAD', $name), 500);
        }

        static::$instances[$name] = new $classname;
    }

    return static::$instances[$name];
}

Here in this function they are creating a classname. why they would create a class name, couldn't they have find class name by calling class creating a class name. they said always ask yourself how and why and i am stuck with loosing job no documentation any help appreciated. thank you

  • I believe the $name argument is used to determine the type of the application you want to get an instance of, such as site, administrator, cli, etc.: github.com/joomla/joomla-cms/blob/staging/libraries/… – Lodder Apr 11 at 9:16
  • Thanyou for replying but why class name – bikashamit Apr 11 at 9:18
  • What do you mean by "why class name"? – Lodder Apr 11 at 9:23
  • in document code they have tried accessing class JApplicationCms and there no no class called JApplicationCms. in JapplicationCms class they tried to create a class name and tried instantiating them. thank you for replying. – bikashamit Apr 11 at 9:27
  • So if its alias class name. But they want cms application object then they could have simply done new class . Why creating a variable classname which doesn't even exist and instantiating them. – bikashamit Apr 11 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.