Jump to content

PHP Docs help


Darghon

Recommended Posts

Hello all,

 

My question isn't about php, but the php docs.

 

I have several php classes that extend a base class.

This class has a static method that returns a object based on the extending class that calls this method

 

How can I add php docs that my editor knows that when I call this function on 1 class, that I get a object of a specific class in return?

 

Right now I'm passing the "super" class of that object, but it would to great to be more accurate.

 

If the above explenation isn't clear, this is a example of what I want to do

 

php class User extends BusinessClass

php class FUser extends FinderClass

 

when I call User::Find() => autocomplete shows info of FinderClass

I want it to show info of FUser.

 

current code:

/**
* Static function that creates a "Find" static function to each business object, which in turn is basicly a shortkey to get The Findertype, or when an ID is passed, to get the object by that ID
* @return BusinessClass|FinderClass
*/
final public static function & Find($id = null) {

 

Adding the following line above my User class result in the correct object types, but the function is no longer detected as available in autocomplete

/**
* @method User|FUser Find(Integer $id) Find a object by ID, or return the object finder.
*/

Autocomplete on "User::" no longer shows Find as a available function

 

Thx for any help

Link to comment
Share on other sites

Firstly, these comments are *annotations* not php docs.

 

Secondly, a User should not be extending a Business or some *finder* utility. This design smells bad.

 

Thirdly, we would need to know what editor your using and how this editor implements it's reading of annotations to be able to help. There is no *standard* in regards to these things.

Link to comment
Share on other sites

I'm using netbeans,

 

And a little insight on my class structure

 

A object/model has 3 layers (mapped to a database record)

a business layer with all functions to work with this object

a datalayer with all raw variables mapped to the record in the database (with input validation etc)

a finderlayer with statements that retrieve records from the database, and return initialised business objects to the requester.

 

so the user table for instance has:

a User class which extends globale business function from the businesslayer

a DUser class which extends globale data functions from the datalayer, and is added as a protected variable in the business model

a FUser class which extends globale finder functions from the finderlayer

 

so lets say I add a method to find a user by email address (byEmail($email)) to the FUser

I'll be able to retrieve all users with that email address by the following statement:

$users = User::Find()->byEmail($email);

Edited by Darghon
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.