API15

API15:JRegistryFormat/getInstance

From Joomla! Documentation

Revision as of 22:24, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Returns a reference to a Format object, only creating it if it doesn't already exist. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Descripti...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Returns a reference to a Format object, only creating it if it doesn't already exist.

[Edit Descripton]

Template:Description:JRegistryFormat/getInstance

Syntax

& getInstance($format)
Parameter Name Default Value Description
$format $format The format to load

Returns

object Registry format handler

Defined in

libraries/joomla/registry/format.php

Importing

jimport( 'joomla.registry.format' );

Source Body

function &getInstance($format)
{
        static $instances;

        if (!isset ($instances)) {
                $instances = array ();
        }

        $format = strtolower(JFilterInput::clean($format, 'word'));
        if (empty ($instances[$format]))
        {
                $class = 'JRegistryFormat'.$format;
                if(!class_exists($class))
                {
                        $path    = dirname(__FILE__).DS.'format'.DS.$format.'.php';
                        if (file_exists($path)) {
                                require_once($path);
                        } else {
                                JError::raiseError(500,JText::_('Unable to load format class'));
                        }
                }

                $instances[$format] = new $class ();
        }
        return $instances[$format];
}

[Edit See Also] Template:SeeAlso:JRegistryFormat/getInstance

Examples

<CodeExamplesForm />