Back to Document class

Method getInstance

public static static
getInstance
(mixed $type = 'html', mixed $attributes = array())
Returns the global Document object, only creating it if it doesn't already exist.
Parameters
  • string $type The document type to instantiate
  • array $attributes Array of attributes
Returns
  • static The document object.
Since
  • 1.7.0
Deprecated
  • 5.0
Class: Document
Project: Joomla

Method getInstance - Source code

/**
 * Returns the global Document object, only creating it
 * if it doesn't already exist.
 *
 * @param   string  $type        The document type to instantiate
 * @param   array   $attributes  Array of attributes
 *
 * @return  static  The document object.
 *
 * @since       1.7.0
 * @deprecated  5.0 Use the \Joomla\CMS\Document\FactoryInterface instead
 */
public static function getInstance($type = 'html', $attributes = array())
{
    $signature = serialize(array($type, $attributes));
    if (empty(self::$instances[$signature])) {
        self::$instances[$signature] = CmsFactory::getContainer()->get(FactoryInterface::class)->createDocument($type, $attributes);
    }
    return self::$instances[$signature];
}