note 69423 added to language.oop5.reflection

From: Date: Tue, 05 Sep 2006 21:19:33 +0000
Subject: note 69423 added to language.oop5.reflection
Groups: php.notes 
Request: Send a blank email to php-notes+get-116724@lists.php.net to get a copy of this message
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>', ), ) --> ---- Server IP: 200.185.109.13 Probable Submitter: 200.190.159.67 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.reflection.php Edit -- https://master.php.net/note/edit/69423 Del: integrated -- https://master.php.net/note/delete/69423/integrated Del: useless -- https://master.php.net/note/delete/69423/useless Del: bad code -- https://master.php.net/note/delete/69423/bad+code Del: spam -- https://master.php.net/note/delete/69423/spam Del: non-english -- https://master.php.net/note/delete/69423/non-english Del: in docs -- https://master.php.net/note/delete/69423/in+docs Del: other reasons-- https://master.php.net/note/delete/69423 Reject -- https://master.php.net/note/reject/69423 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116724) next »