0

i write an api generator, and need to read all methods with ist parameters by a defined class. read all Methods is done!

Example Class:

class Foo {

    function tester($test)
    {
     return "bar";
    }

    function test(Article $article)
    {
     return "bar";
    } 

}

get_class_methods = array('tester', 'test');

ok, now i have to know the parameters of each function, how can i solve this problem?

Important is TypeHinting.

Thanks

Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
OskarStark
  • 384
  • 1
  • 11

3 Answers3

1

I don't know if there is any method to do this, but you can use php lexical analyzer.

You may read the file using token_get_all (see http://us.php.net/manual/en/function.token-get-all.php). Then parse it by yourself to get all classes, methods, parameters, and even parse comments if you want!

Jaffa
  • 12,442
  • 4
  • 49
  • 101
1

ok, now i have to know the parameters of each function, how can i solve this problem?

Using the reflection API. Build a new ReflectionClass( 'Foo' ), get the method test and you can get its parameters by getParameters( ). Good luck!

Berry Langerak
  • 18,561
  • 4
  • 45
  • 58
0

You can do this with Zend_Reflection which is an extension to the PHP reflection classes.

http://framework.zend.com/manual/en/zend.reflection.html

When you have a Zend_Reflection_Parameter object you can get your type hinting value thru getType I expect.

Kees Schepers
  • 2,248
  • 1
  • 20
  • 31