| View previous topic :: View next topic |
| Author |
Message |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Sat Jun 20, 2009 6:12 pm Post subject: force autocomplete |
|
|
Hi,
I have a DAO registry class to get hold of DAOs in an easy way and to limit to one instance of the DAOs. To get a DAO you do this:
| Code: | $agentDAO = DAOReg::get('AgentDAO');
$agent = $agentDAO->findByName($name); |
or usually I'll just access the methods directly like this:
| Code: | | $agent = DAOReg::get('AgentDAO')->findByName($name); |
The problem is that because NB doesn't know what is being returned in the DAOReg::get method, I can't use autocomplete.
What would be the best way to get NB to do autocomplete on this? Is there a way to 'teach' NB which DAO will come back on the DAOReg::get call and hence do autocomplete?
If I used the first method of getting a DAO first explicitly, is there a way to force the class of the $agentDAO?
Thanks
Ziad |
|
| Back to top |
|
 |
christianachatz
Joined: 21 May 2009 Posts: 12 Location: Germany
|
Posted: Sat Jun 20, 2009 10:27 pm Post subject: |
|
|
Hi Zaid,
the way to teach is to add code comment to your method. If you have something like this
| Code: | /**
* @return MyType The type that is returned.
*/
public function get($param){
return ...;
} |
NB knows about the return type.
Cheers,
Christian |
|
| Back to top |
|
 |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Sat Jun 20, 2009 11:29 pm Post subject: |
|
|
Thanks for your response Christian. I guess I could use your suggestion for 'regular' functions but my DAOReg::get function actually returns different types. I guess I didn't make myself clear in the question.
| Code: |
// returns AgentDAO type
$agentDAO = DAOReg::get('AgentDAO');
// returns MemberDAO type
$memberDAO = DAOReg::get('MemberDAO');
|
So is there anyway to teach NB that the type of the object returned is what was passed in as the parameter to the DAOReg::get method? I'm guessing this is probably not possible.
But is it possible to tell NB the type of my variable on the client end (i.e. where DAOReg::get is called) instead of in the function itself? So is there a way to tell NB that the $agentDAO is of type AgentDAO in the following code?
| Code: |
$agentDAO = DAOReg::get('AgentDAO');
|
Thanks
Ziad |
|
| Back to top |
|
 |
christianachatz
Joined: 21 May 2009 Posts: 12 Location: Germany
|
Posted: Sun Jun 21, 2009 11:33 am Post subject: |
|
|
Hello Ziad,
| Quote: | | So is there anyway to teach NB that the type of the object returned is what was passed in as the parameter to the DAOReg::get method? I'm guessing this is probably not possible. |
I don't think so, PHP does not support generics. Perheps you can try to annotate your code like in JAVA using generic. Have never done that, but give it a try.
| Quote: | | But is it possible to tell NB the type of my variable on the client end (i.e. where DAOReg::get is called) instead of in the function itself? So is there a way to tell NB that the $agentDAO is of type AgentDAO in the following code? |
AFAIK you can add
| Code: | /**
* @var AgentDAO $agentDAO
*/
$agentDAO = DAOReg::get('AgentDAO'); |
Cheers,
Christian |
|
| Back to top |
|
 |
Eugene Morgan Posted via mailing list.
|
Posted: Mon Jun 22, 2009 2:06 pm Post subject: force autocomplete |
|
|
| Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the |
|
| Back to top |
|
 |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Tue Jun 23, 2009 4:37 am Post subject: Re: force autocomplete |
|
|
| Eugene Morgan wrote: | | Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the |
Yes all my DAOs do extend a base DAO. It looks like your message got cut off. Please complete the rest of your post.
Thanks |
|
| Back to top |
|
 |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Tue Jun 23, 2009 4:41 am Post subject: |
|
|
| christianachatz wrote: |
I don't think so, PHP does not support generics. Perheps you can try to annotate your code like in JAVA using generic. Have never done that, but give it a try.
|
How would I do that? Thanks. |
|
| Back to top |
|
 |
Tomas Mysik Posted via mailing list.
|
|
| Back to top |
|
 |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Tue Jun 23, 2009 1:36 pm Post subject: Re: force autocomplete |
|
|
Hi Tomas,
Yeah I got how to force the type to a particular type using the @var comment but I was wondering about generics and what christian mentioned. How/where do I comment/annotate generics?
|
|
| Back to top |
|
 |
Tomas Mysik Posted via mailing list.
|
Posted: Tue Jun 23, 2009 2:01 pm Post subject: force autocomplete |
|
|
Hi,
Dne úterý 23 června 2009 15:36:58 ziad napsal(a):
| Quote: | Yeah I got how to force the type to a particular type using the @var
comment but I was wondering about generics and what christian mentioned.
How/where do I comment/annotate generics?
|
IMHO there's no such possibility for PHP.
Tomas
--
Tomas Mysik
address-removed |
|
| Back to top |
|
 |
Eugene Morgan Posted via mailing list.
|
Posted: Tue Jun 23, 2009 4:18 pm Post subject: force autocomplete |
|
|
Not sure how much it will help, but the rest of my post was ...
... you can specify that class [the base class] in the documentation
for the DAOReg::get function -- at least that will give you some
autocompletion for any methods that are inherited by all DAOs.
On Mon, Jun 22, 2009 at 11:38 PM, ziad<address-removed> wrote:
| Quote: |
Eugene Morgan wrote:
| Quote: | Another thing you can try is if all your DAOs extend a base DAO class, you can specify that class in the documentation for the
|
Yes all my DAOs do extend a base DAO. It looks like your message got cut off. Please complete the rest of your post.
Thanks
|
|
|
| Back to top |
|
 |
ziad
Joined: 10 Mar 2009 Posts: 19
|
Posted: Tue Jun 23, 2009 5:20 pm Post subject: |
|
|
Hi Eugene,
Yeah that definitely does help but it would be nice to be able to get it to work properly. I saw how you can get auto-complete to work for CakePHP helpers by adding them onto an include fine and giving them types so I might try that. |
|
| Back to top |
|
 |
|