Reputation: 5
class Gdn {
const AliasDispatcher = 'Dispatcher';
protected static $_Factory = NULL;
public static function Dispatcher() {
$Result = self::Factory(self::AliasDispatcher);
return $Result;
}
public static function Factory($Alias = FALSE) {
if ($Alias === FALSE)
return self::$_Factory;
// Get the arguments to pass to the factory.
//$Args = array($Arg1, $Arg2, $Arg3, $Arg4, $Arg5);
$Args = func_get_args();
array_shift($Args);
return self::$_Factory->Factory($Alias, $Args);
}
}
If I call the Dispatcher() like $Dispatcher = Gdn::Dispatcher();
, what does return self::$_Factory->Factory($Alias, $Args);
mean?
Upvotes: 0
Views: 99
Reputation: 4812
self:: means you are refering to the class of the current object since factory is a recursive function it will keep calling itself until it runs out of arguments and then returns the factory that is set in the current factory class.
if you would do: "blah->Factory('test1','test2',test3','test4')" it would run like:
blah->factory('test1','test2','test3','test4')
blah->$_Factory->Factory('test1',array('test2','test3','test4'))
blah->$_Factory->Factory(array('test2','test3','test4'));
blah->$_Factory->Factory();
// oh hey, i dont have any arguments, replace it with my default argument 'false' and thus return the factory
return self::$_Factory;
i dont know WHY you would want it, but this is what it does
Upvotes: 0
Reputation: 29208
It means Dispatcher() is returning an object, and that object is a copy of something created by Factory().
Upvotes: 1