Generate prototype classes from orginal class files in PHP -


is there way in php read php source file contains 1 or more classes , create prototype class (similar interface)

original class looks this:

class math {      private $a;     private $b;      public function set_a($a) {         $this -> = $a;     }      public function set_b($b) {         $this -> b = $b;     }      public function sum() {         return $a + $b;     }  } 

the prototype file must this:

class math {      public function set_a($a) { }      public function set_b($b) { }      public function sum() { }  } 

i want dynamically reading class files @ runtime , generating prototype classes. there library in php through can read class meta information file without including.

edit: need create php file listing prototype classes. reason have created phar file library. , whenever need use code within phar file include using following syntax.

require_once("phar://mylibrary.phar/math.php"); 

but problem code hints , intelli-sense not work. using zend studio. thought, if create single file prototype classes , include new project code hinting work.

if coding style guarantees you'll never break arguments of function declaration on multiple lines, can hack prototype generator pretty selecting lines match following patterns (and correcting braces needed):

/^class / /^}/ /^\s*(\w+)?\s*function\b/   # must append closing } each line matching 

you rig php script this, if you've got unix tools in environment, above few characters away being complete sed script.

here embedded in php script, requested (not tested):

$fp = fopen("source.php"); while (($line = fgets($fp)) !== false) {     if (preg_match("/^class |^}/", $line))         print $line;     elif (preg_match('/^\s*(\w+)?\s*function\b/', $line))         print rtrim($line) . " }\n"; } 

adapt/extend needed coding style.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -