note 69423 deleted from language.oop5.reflection by danbrown

From: Date: Wed, 16 Sep 2009 16:18:02 +0000
Subject: note 69423 deleted from language.oop5.reflection by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160721@lists.php.net to get a copy of this message
Note Submitter: thiago_mata at yahoo dot com dot br ---- If you need to try to do something with the phpdoc or like the java notations in php4, you can create your own 'reflection functions'. This is a litle example of that. <?php /** * Comment used to start a phpdoc * @author Thiago Mata * @package notations */ define( 'START_DOC' , '/**' ); /** * Comment used to end a phpdoc * @author Thiago Mata * @package notations */ define( 'END_DOC' , '*/' ); /** * Comment used to indicate a tag of phpdoc * @author Thiago Mata * @package notations */ define( 'TAG_DOC' , '@' ); /** * This is a function maded in PHP4 to get the notations from some php file. * Can use comments with many lines * * @author Thiago Mata * @date 05/09/2006 * @package notations * @param string $strFile * @copyright open source * @example <code> $arrNotations = getFileNotations( 'somefile.php' ); </code> */ function getFileNotations( $strFile ) { $strText = file_get_contents( $strFile ); $arrText = explode( "\n" , $strText ); $arrNotations = array(); for ( $intCount = 0 ; $intCount < count( $arrText ) ; ++$intCount ) { $strLine = $arrText[ $intCount ]; // inside the phpdoc // if ( strpos( trim( $strLine ) , START_DOC ) === 0 ) { ++$intCount; $strLine = $arrText[ $intCount ]; $arrNotation = array(); // while the phpdoc is not finished // while ( ( strpos( trim( $strLine ) , END_DOC ) !== 0 ) and ( $intCount < count( $arrText ) ) ) { // removing the tag doc from the line // $strLine = substr( $strLine , strpos( $strLine , TAG_DOC ) ); // get the name of the tag // $strName = substr( $strLine , 0 , strpos( $strLine , ' ' ) ); // get the value of the tag // $strLine = substr( $strLine , strpos( $strLine , ' ' ) + 1 ); if ( strpos( trim( $strLine ) , '*' ) === 0 ) { $strLine = substr( $strLine , strpos( $strLine , '*' ) + 1 ); } $strLine = trim( $strLine ); if ( ! isset( $arrNotation[ $strName ] ) ) { $arrNotation[ $strName ] = ''; } else { if ( $strLine != '' ) { $arrNotation[ $strName ] .= "\n"; } } $arrNotation[ $strName ] .= trim( $strLine ); ++$intCount; $strLine = $arrText[ $intCount ]; } if ( $intCount < count( $arrText ) ) { do { ++$intCount; $strLine = $arrText[ $intCount ]; } while ( $strLine == '' ); // adding the notation to the next command line // $arrNotations[ trim( $arrText[ $intCount ] ) ] = $arrNotation; $intCount--; } } } return( $arrNotations ); } print( '<pre>' . "\n" ); var_export( getFileNotations( __FILE__ ) ); print( '</pre>' . "\n" ); ?> <!-- OUTPUT array ( 'define( \'START_DOC\' , \'/**\' );' => array ( '' => 'Comment used to start a phpdoc', '@author' => 'Thiago Mata', '@package' => 'notations', ), 'define( \'END_DOC\' , \'*/\' );' => array ( '' => 'Comment used to end a phpdoc', '@author' => 'Thiago Mata', '@package' => 'notations', ), 'define( \'TAG_DOC\' , \'@\' );' => array ( '' => 'Comment used to indicate a tag of phpdoc', '@author' => 'Thiago Mata', '@package' => 'notations', ), 'function getFileNotations( $strFile )' => array ( '' => 'This is a function maded in PHP4 to get the notations from some php file. Can use comments with many lines', '@author' => 'Thiago Mata', '@date' => '05/09/2006', '@package' => 'notations', '@param' => 'string $strFile', '@copyright' => 'open source', '@example' => '<code> $arrNotations = getFileNotations( \'somefile.php\' ); </code>', ), ) -->

« previous php.notes (#160721) next »