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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.