NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Script for code-insight for Factory created objects?


Joined: 08 Jul 2009
Posts: 1
Reply with quote
Hi,

I use an object factory to instantiate many of the objects in my script - unfortunately PHPEd can't provide insight into what methods/properties are available in the objects like it can when they are instantiated via the "new" keyword. Are there any scripts available that can achieve this with factory objects?

Code:

$Obj = new className; // provides code insight on public methods/properties

class objectFactory
{
   public static function Create($className)
   {
        return new $className;
   }
}

$Obj = objectFactory::Create("className"); // no code insight


Thanks
View user's profileFind all posts by tomp_glSend private message


Joined: 11 Apr 2010
Posts: 90
Location: Prague, Czech Republic
Reply with quote
Hi!

I am afraid that this behaviour is common for all IDEs, because in general there is no way to know, what class name is in the variable at the time of class creation.

If possible, I suggest to create extra methods together with phpDoc and use them as creation mediators like:

Code:
/**
 * @return MyClass
 */
function newMyClass() {
    return new objectFactory::Create("MyClass");
}

$obj = newMyClass(); // code insight works now


You can possibly make these extra methods part of your objectFactory class, so you could call comething like "$obj = objectFactory::createMyClass();".

It is not a perfect solution, but still I hope this helps you a little.
View user's profileFind all posts by fibizaSend private message
Script for code-insight for Factory created objects?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic