SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 230 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

As with the previous
example in the declaration of the getInstance() method, we make the method
return a reference and we define it as static in the doctags.
An extension of this mechanism is to allow instantiation of subclasses. A good
example of this is the core JDocument class that can instantiate JDocumentError,
JDocumentFeed, JDocumentHTML, JDocumentPDF, or JDocumentRAW (located at
libraries/joomla/document).
In this example, we will attempt something similar; assume that the subclasses are
located in the root of a component and named with the prefix SomeClass:
/**
* Returns a reference to the global SomeClass object
*
* @access public
* @static
* param string A string
* @return mixed A SomeClass object, false on failure
*/
function &getInstance($foo)
{
static $instances;
// prepare static array
if (!$instances)
{
$instances = array();
}
$foo = (string)$foo;
$class = 'SomeClass'.$foo;
$file = strtolower($foo).'.php';
if (empty($instances[$foo]))
{
if (!class_exists($class))
{
// class does not exists, so we need to find it
jimport('joomla.


Pages:
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6