views:

46

answers:

2
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?

+1  A: 

It means Dispatcher() is returning an object, and that object is a copy of something created by Factory().

editor
I dont understand the arrow after the static vars,so Gdn::$_Factory is a object?
nzh
A: 

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

DoXicK