PDA

View Full Version : API codegenerator (php)



makcs
19 Dec 2009, 5:03 PM
<?php
$API = array();
foreach ( glob( "classes/*.php" ) as $class )
{
$content = file_get_contents( $class );
preg_match( "/class ([\S^{]+)/", $content, $m );
preg_match_all( "/function ([^ (]+) *\(\s*(.*)\s*\)/", $content, $f );
for ( $i = 0; $i < count( $f[ 0 ] ); $i++ )
$API[ $m[ 1 ] ][ 'methods'][ $f[ 1 ][ $i ] ][ 'len' ] = empty( $f[ 2 ][ $i ] ) ? 0 : count( preg_split( "/,/", $f[ 2 ][ $i ] ) );
}
/*
$API = array(
'TestAction'=>array(
'methods'=>array(
'doEcho'=>array(
'len'=>1
),
'multiply'=>array(
'len'=>1
),
'getTree'=>array(
'len'=>1
)
)
),

'Profile'=>array(
'methods'=>array(
'getBasicInfo'=>array(
'len'=>2
),
'getPhoneInfo'=>array(
'len'=>1
),
'getLocationInfo'=>array(
'len'=>1
),
'updateBasicInfo'=>array(
'len'=>2,
'formHandler'=>true
)
)
)
);

*/

?>