2014-04-17 15:00:14 +02:00
< ? php
/**
*
* @ package phpBB3
* @ copyright ( c ) 2014 phpBB Group
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
*
*/
2014-04-18 11:13:02 +02:00
namespace phpbb\event ;
2014-04-18 12:50:23 +02:00
/**
* Class php_exporter
* Crawls through a list of files and grabs all php - events
*
* @ package phpbb\event
*/
class php_exporter
2014-04-17 15:00:14 +02:00
{
/** @var string */
protected $root_path ;
2014-04-18 02:08:23 +02:00
/** @var string */
protected $current_file ;
/** @var string */
protected $current_event ;
/** @var int */
protected $current_event_line ;
/** @var array */
protected $events ;
/** @var array */
protected $file_lines ;
2014-04-17 15:00:14 +02:00
/**
* @ param string $phpbb_root_path
*/
public function __construct ( $phpbb_root_path )
{
$this -> root_path = $phpbb_root_path ;
2014-04-18 02:08:23 +02:00
$this -> events = $this -> file_lines = array ();
$this -> current_file = $this -> current_event = '' ;
$this -> current_event_line = 0 ;
2014-04-17 15:00:14 +02:00
}
2014-04-18 02:08:23 +02:00
public function get_events ()
{
return $this -> events ;
}
public function set_current_event ( $name , $line )
{
$this -> current_event = $name ;
$this -> current_event_line = $line ;
}
public function set_content ( $content )
{
$this -> file_lines = $content ;
}
2014-04-18 11:06:04 +02:00
/**
* Crawl the phpBB / directory for php events
* @ return int The number of events found
*/
public function crawl_phpbb_directory_php ()
{
$files = $this -> get_recursive_file_list ( $this -> root_path );
2014-04-18 12:50:23 +02:00
$this -> events = array ();
2014-04-18 11:06:04 +02:00
foreach ( $files as $file )
{
$this -> crawl_php_file ( $file );
}
2014-04-18 12:50:23 +02:00
ksort ( $this -> events );
2014-04-18 11:06:04 +02:00
2014-04-18 12:50:23 +02:00
return sizeof ( $this -> events );
2014-04-18 11:06:04 +02:00
}
/**
* Returns a list of files in $dir
*
* Works recursive with any depth
*
* @ param string $dir Directory to go through
* @ param string $path Path from root to $dir
* @ return array List of files ( including directories )
*/
public function get_recursive_file_list ( $dir , $path = '' )
{
try
{
$iterator = new \DirectoryIterator ( $dir );
}
2014-04-18 11:13:02 +02:00
catch ( \Exception $e )
2014-04-18 11:06:04 +02:00
{
return array ();
}
$files = array ();
foreach ( $iterator as $file_info )
{
/** @var \DirectoryIterator $file_info */
if ( $file_info -> isDot ())
{
continue ;
}
// Do not scan some directories
if ( $file_info -> isDir () && (
( $path == '' && in_array ( $file_info -> getFilename (), array (
'cache' ,
'develop' ,
'ext' ,
'files' ,
'language' ,
'store' ,
'vendor' ,
)))
|| ( $path == '/includes' && in_array ( $file_info -> getFilename (), array ( 'utf' )))
|| ( $path == '/phpbb/db/migration' && in_array ( $file_info -> getFilename (), array ( 'data' )))
|| ( $path == '/phpbb' && in_array ( $file_info -> getFilename (), array ( 'event' )))
))
{
continue ;
}
else if ( $file_info -> isDir ())
{
$sub_dir = $this -> get_recursive_file_list ( $file_info -> getPath () . '/' . $file_info -> getFilename (), $path . '/' . $file_info -> getFilename ());
foreach ( $sub_dir as $file )
{
$files [] = $file_info -> getFilename () . '/' . $file ;
}
}
2014-04-18 13:06:13 +02:00
else if ( substr ( $file_info -> getFilename (), - 4 ) == '.php' )
2014-04-18 11:06:04 +02:00
{
$files [] = $file_info -> getFilename ();
}
}
return $files ;
}
/**
* Format the php events as a wiki table
* @ return string
*/
2014-04-18 12:50:23 +02:00
public function export_events_for_wiki ()
2014-04-18 11:06:04 +02:00
{
2014-04-18 12:50:23 +02:00
$wiki_page = '= PHP Events (Hook Locations) =' . " \n " ;
$wiki_page .= '{| class="sortable zebra" cellspacing="0" cellpadding="5"' . " \n " ;
$wiki_page .= '! Identifier !! Placement !! Arguments !! Added in Release !! Explanation' . " \n " ;
foreach ( $this -> events as $event )
2014-04-18 11:06:04 +02:00
{
$wiki_page .= '|- id="' . $event [ 'event' ] . '"' . " \n " ;
$wiki_page .= '| [[#' . $event [ 'event' ] . '|' . $event [ 'event' ] . ']] || ' . $event [ 'file' ] . ' || ' . implode ( ', ' , $event [ 'arguments' ]) . ' || ' . $event [ 'since' ] . ' || ' . $event [ 'description' ] . " \n " ;
}
2014-04-18 12:50:23 +02:00
$wiki_page .= '|}' . " \n " ;
2014-04-18 11:06:04 +02:00
return $wiki_page ;
}
2014-04-18 02:08:23 +02:00
/**
2014-04-20 14:28:09 +02:00
* @ param string $file
* @ return int Number of events found in this file
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-18 02:08:23 +02:00
*/
2014-04-18 11:06:04 +02:00
public function crawl_php_file ( $file )
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
$this -> current_file = $file ;
$this -> file_lines = array ();
$content = file_get_contents ( $this -> root_path . $this -> current_file );
2014-04-20 14:28:09 +02:00
$num_events_found = 0 ;
2014-04-17 15:00:14 +02:00
2014-04-17 16:55:36 +02:00
if ( strpos ( $content , " dispatcher->trigger_event(' " ) || strpos ( $content , " dispatcher->dispatch(' " ))
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
$this -> set_content ( explode ( " \n " , $content ));
for ( $i = 0 , $num_lines = sizeof ( $this -> file_lines ); $i < $num_lines ; $i ++ )
2014-04-17 15:00:14 +02:00
{
2014-04-17 18:21:18 +02:00
$event_line = false ;
2014-04-18 02:08:23 +02:00
$found_trigger_event = strpos ( $this -> file_lines [ $i ], " dispatcher->trigger_event(' " );
2014-04-18 11:13:02 +02:00
$arguments = array ();
2014-04-17 15:00:14 +02:00
if ( $found_trigger_event !== false )
{
$event_line = $i ;
2014-04-20 14:58:24 +02:00
$this -> set_current_event ( $this -> get_event_name ( $event_line , false ), $event_line );
2014-04-17 15:00:14 +02:00
2014-04-18 00:31:06 +02:00
// Find variables of the event
2014-04-18 02:08:23 +02:00
$arguments = $this -> get_vars_from_array ();
$doc_vars = $this -> get_vars_from_docblock ();
$this -> validate_vars_docblock_array ( $arguments , $doc_vars );
2014-04-17 15:00:14 +02:00
}
2014-04-17 18:21:18 +02:00
else
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
$found_dispatch = strpos ( $this -> file_lines [ $i ], " dispatcher->dispatch(' " );
2014-04-17 16:55:36 +02:00
if ( $found_dispatch !== false )
{
$event_line = $i ;
2014-04-20 14:58:24 +02:00
$this -> set_current_event ( $this -> get_event_name ( $event_line , true ), $event_line );
2014-04-17 16:55:36 +02:00
}
2014-04-17 15:00:14 +02:00
}
if ( $event_line )
{
// Validate @event
2014-04-18 02:08:23 +02:00
$event_line_num = $this -> find_event ();
$this -> validate_event ( $this -> current_event , $this -> file_lines [ $event_line_num ]);
2014-04-17 15:00:14 +02:00
// Validate @since
2014-04-18 02:08:23 +02:00
$since_line_num = $this -> find_since ();
$since = $this -> validate_since ( $this -> file_lines [ $since_line_num ]);
2014-04-17 15:00:14 +02:00
// Find event description line
2014-04-18 02:08:23 +02:00
$description_line_num = $this -> find_description ();
$description = substr ( trim ( $this -> file_lines [ $description_line_num ]), strlen ( '* ' ));
2014-04-17 15:00:14 +02:00
2014-04-18 12:50:23 +02:00
if ( isset ( $this -> events [ $this -> current_event ]))
2014-04-18 02:08:23 +02:00
{
2014-04-20 15:11:23 +02:00
throw new \LogicException ( " The event ' { $this -> current_event } ' from file "
. " ' { $this -> current_file } : { $event_line_num } ' already exists in file "
. " ' { $this -> events [ $this -> current_event ][ 'file' ] } ' " , 10 );
2014-04-18 02:08:23 +02:00
}
2014-04-18 12:50:23 +02:00
$this -> events [ $this -> current_event ] = array (
2014-04-18 02:08:23 +02:00
'event' => $this -> current_event ,
'file' => $this -> current_file ,
2014-04-17 15:00:14 +02:00
'arguments' => $arguments ,
'since' => $since ,
'description' => $description ,
);
2014-04-20 14:28:09 +02:00
$num_events_found ++ ;
2014-04-17 15:00:14 +02:00
}
}
}
2014-04-20 14:28:09 +02:00
return $num_events_found ;
2014-04-17 15:00:14 +02:00
}
2014-04-17 16:55:36 +02:00
/**
* Find the name of the event inside the dispatch () line
*
2014-04-20 14:57:18 +02:00
* @ param int $event_line
2014-04-20 14:58:24 +02:00
* @ param bool $is_dispatch Do we look for dispatch () or trigger_event () ?
2014-04-17 16:55:36 +02:00
* @ return int Absolute line number
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 16:55:36 +02:00
*/
2014-04-20 14:58:24 +02:00
public function get_event_name ( $event_line , $is_dispatch )
2014-04-17 16:55:36 +02:00
{
2014-04-20 14:57:18 +02:00
$event_text_line = $this -> file_lines [ $event_line ];
$event_text_line = ltrim ( $event_text_line , " \t " );
2014-04-17 16:55:36 +02:00
2014-04-20 14:58:24 +02:00
if ( $is_dispatch )
2014-04-17 16:55:36 +02:00
{
2014-04-20 14:58:24 +02:00
$regex = '#\$([a-z](?:[a-z0-9_]|->)*)' ;
$regex .= '->dispatch\(' ;
$regex .= '\'' . $this -> preg_match_event_name () . '\'' ;
$regex .= '\);#' ;
}
else
{
$regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)' ;
$regex .= '->trigger_event\(' ;
$regex .= '\'' . $this -> preg_match_event_name () . '\'' ;
$regex .= ', compact\(\$vars\)\)\);#' ;
2014-04-17 16:55:36 +02:00
}
$match = array ();
2014-04-20 14:57:18 +02:00
preg_match ( $regex , $event_text_line , $match );
2014-04-17 16:55:36 +02:00
if ( ! isset ( $match [ 2 ]))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find event name in line ' { $event_text_line } ' "
. " in file ' { $this -> current_file } : { $event_line } ' " , 1 );
2014-04-17 16:55:36 +02:00
}
return $match [ 2 ];
}
/**
2014-04-18 12:50:23 +02:00
* Returns a regex match for the event name
2014-04-17 16:55:36 +02:00
*
2014-04-18 12:50:23 +02:00
* @ return string
2014-04-17 16:55:36 +02:00
*/
protected function preg_match_event_name ()
{
return '([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+)' ;
}
2014-04-17 18:21:18 +02:00
/**
* Find the $vars array
*
* @ return array List of variables
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 18:21:18 +02:00
*/
2014-04-18 02:08:23 +02:00
public function get_vars_from_array ()
2014-04-17 18:21:18 +02:00
{
2014-04-20 14:15:54 +02:00
$vars_array_line = 1 ;
$found_vars_array = false ;
$vars_array = array ();
while ( ltrim ( $this -> file_lines [ $this -> current_event_line - $vars_array_line ], " \t " ) !== '*/' )
2014-04-17 18:21:18 +02:00
{
2014-04-20 14:15:54 +02:00
$line = ltrim ( $this -> file_lines [ $this -> current_event_line - $vars_array_line ], " \t " );
$match = array ();
2014-04-24 17:14:12 +02:00
preg_match ( '#^\$vars = (array_merge\(\$vars, )?array\(\'([a-zA-Z0-9_\' ,]+)\'\)(?(1)\));$#' , $line , $match );
2014-04-20 14:15:54 +02:00
2014-04-24 17:14:12 +02:00
if ( isset ( $match [ 2 ]))
2014-04-20 14:15:54 +02:00
{
$found_vars_array = true ;
2014-04-24 17:14:12 +02:00
if ( strlen ( $match [ 2 ]) > 90 )
2014-04-20 14:15:54 +02:00
{
2014-04-20 15:11:23 +02:00
throw new \LogicException ( 'Should use multiple lines for $vars definition '
2014-04-20 14:57:18 +02:00
. " for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 3 );
2014-04-20 14:15:54 +02:00
}
2014-04-24 17:14:12 +02:00
$vars_array = array_merge ( $vars_array , explode ( " ', ' " , $match [ 2 ]));
2014-04-20 14:15:54 +02:00
}
$vars_array_line ++ ;
if ( $this -> current_event_line - $vars_array_line === 0 )
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find ' \$ vars = array();'-line for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-20 14:15:54 +02:00
}
2014-04-17 18:21:18 +02:00
}
2014-04-20 14:15:54 +02:00
if ( ! $found_vars_array )
2014-04-17 18:21:18 +02:00
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find ' \$ vars = array();'-line for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 3 );
2014-04-17 18:21:18 +02:00
}
foreach ( $vars_array as $var )
{
if ( ! preg_match ( '#^([a-zA-Z_][a-zA-Z0-9_]*)$#' , $var ))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Found invalid var ' { $var } ' in array for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 4 );
2014-04-17 18:21:18 +02:00
}
}
2014-04-18 00:31:06 +02:00
sort ( $vars_array );
2014-04-17 18:21:18 +02:00
return $vars_array ;
}
2014-04-18 00:31:06 +02:00
/**
* Find the $vars array
*
* @ return array List of variables
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-18 00:31:06 +02:00
*/
2014-04-18 02:08:23 +02:00
public function get_vars_from_docblock ()
2014-04-18 00:31:06 +02:00
{
$doc_vars = array ();
$current_doc_line = 1 ;
$found_comment_end = false ;
2014-04-18 02:08:23 +02:00
while ( ltrim ( $this -> file_lines [ $this -> current_event_line - $current_doc_line ], " \t " ) !== '/**' )
2014-04-18 00:31:06 +02:00
{
2014-04-18 02:08:23 +02:00
if ( ltrim ( $this -> file_lines [ $this -> current_event_line - $current_doc_line ], " \t " ) === '*/' )
2014-04-18 00:31:06 +02:00
{
$found_comment_end = true ;
}
if ( $found_comment_end )
{
2014-04-18 02:08:23 +02:00
$var_line = trim ( $this -> file_lines [ $this -> current_event_line - $current_doc_line ]);
2014-04-18 00:31:06 +02:00
$var_line = preg_replace ( '!\s+!' , ' ' , $var_line );
if ( strpos ( $var_line , '* @var ' ) === 0 )
{
$doc_line = explode ( ' ' , $var_line , 5 );
if ( sizeof ( $doc_line ) !== 5 )
{
2014-04-20 15:11:23 +02:00
throw new \LogicException ( " Found invalid line ' { $this -> file_lines [ $this -> current_event_line - $current_doc_line ] } ' "
2014-04-20 14:57:18 +02:00
. " for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 1 );
2014-04-18 00:31:06 +02:00
}
$doc_vars [] = $doc_line [ 3 ];
}
}
$current_doc_line ++ ;
2014-04-18 02:08:23 +02:00
if ( $current_doc_line > $this -> current_event_line )
2014-04-18 00:31:06 +02:00
{
// Reached the start of the file
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find end of docblock for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-18 00:31:06 +02:00
}
}
if ( empty ( $doc_vars ))
{
// Reached the start of the file
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find @var lines for event ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 3 );
2014-04-18 00:31:06 +02:00
}
foreach ( $doc_vars as $var )
{
if ( ! preg_match ( '#^([a-zA-Z_][a-zA-Z0-9_]*)$#' , $var ))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Found invalid @var ' { $var } ' in docblock for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 4 );
2014-04-18 00:31:06 +02:00
}
}
sort ( $doc_vars );
return $doc_vars ;
}
2014-04-17 15:00:14 +02:00
/**
* Find the " @since " Information line
*
* @ return int Absolute line number
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 15:00:14 +02:00
*/
2014-04-18 02:08:23 +02:00
public function find_since ()
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
return $this -> find_tag ( 'since' , array ( 'event' , 'var' ));
2014-04-17 15:00:14 +02:00
}
/**
* Find the " @event " Information line
*
* @ return int Absolute line number
*/
2014-04-18 02:08:23 +02:00
public function find_event ()
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
return $this -> find_tag ( 'event' , array ());
2014-04-17 15:00:14 +02:00
}
/**
* Find a " @* " Information line
*
* @ param string $find_tag Name of the tag we are trying to find
* @ param array $disallowed_tags List of tags that must not appear between
* the tag and the actual event
* @ return int Absolute line number
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 15:00:14 +02:00
*/
2014-04-18 02:08:23 +02:00
public function find_tag ( $find_tag , $disallowed_tags )
2014-04-17 15:00:14 +02:00
{
$find_tag_line = 0 ;
$found_comment_end = false ;
2014-04-18 02:08:23 +02:00
while ( strpos ( ltrim ( $this -> file_lines [ $this -> current_event_line - $find_tag_line ], " \t " ), '* @' . $find_tag . ' ' ) !== 0 )
2014-04-17 15:00:14 +02:00
{
2014-04-18 02:08:23 +02:00
if ( $found_comment_end && ltrim ( $this -> file_lines [ $this -> current_event_line - $find_tag_line ], " \t " ) === '/**' )
2014-04-17 15:00:14 +02:00
{
// Reached the start of this doc block
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find '@ { $find_tag } ' information for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 1 );
2014-04-17 15:00:14 +02:00
}
foreach ( $disallowed_tags as $disallowed_tag )
{
2014-04-18 02:08:23 +02:00
if ( $found_comment_end && strpos ( ltrim ( $this -> file_lines [ $this -> current_event_line - $find_tag_line ], " \t " ), '* @' . $disallowed_tag ) === 0 )
2014-04-17 15:00:14 +02:00
{
// Found @var after the @since
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Found '@ { $disallowed_tag } ' information after '@ { $find_tag } ' for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 3 );
2014-04-17 15:00:14 +02:00
}
}
2014-04-18 02:08:23 +02:00
if ( ltrim ( $this -> file_lines [ $this -> current_event_line - $find_tag_line ], " \t " ) === '*/' )
2014-04-17 15:00:14 +02:00
{
$found_comment_end = true ;
}
$find_tag_line ++ ;
2014-04-18 02:08:23 +02:00
if ( $find_tag_line >= $this -> current_event_line )
2014-04-17 15:00:14 +02:00
{
// Reached the start of the file
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find '@ { $find_tag } ' information for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-17 15:00:14 +02:00
}
}
2014-04-18 02:08:23 +02:00
return $this -> current_event_line - $find_tag_line ;
2014-04-17 15:00:14 +02:00
}
/**
* Find a " @* " Information line
*
* @ return int Absolute line number
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 15:00:14 +02:00
*/
2014-04-18 02:08:23 +02:00
public function find_description ()
2014-04-17 15:00:14 +02:00
{
$find_desc_line = 0 ;
2014-04-18 02:08:23 +02:00
while ( ltrim ( $this -> file_lines [ $this -> current_event_line - $find_desc_line ], " \t " ) !== '/**' )
2014-04-17 15:00:14 +02:00
{
$find_desc_line ++ ;
2014-04-18 02:08:23 +02:00
if ( $find_desc_line > $this -> current_event_line )
2014-04-17 15:00:14 +02:00
{
// Reached the start of the file
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find a description for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 1 );
2014-04-17 15:00:14 +02:00
}
}
2014-04-18 02:08:23 +02:00
$find_desc_line = $this -> current_event_line - $find_desc_line + 1 ;
2014-04-17 15:00:14 +02:00
2014-04-18 02:08:23 +02:00
$desc = trim ( $this -> file_lines [ $find_desc_line ]);
2014-04-17 15:00:14 +02:00
if ( strpos ( $desc , '* @' ) === 0 || $desc [ 0 ] !== '*' || substr ( $desc , 1 ) == '' )
{
// First line of the doc block is a @-line, empty or only contains "*"
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Can not find a description for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-17 15:00:14 +02:00
}
return $find_desc_line ;
}
/**
* Validate " @since " Information
*
* @ param string $line
* @ return string
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 15:00:14 +02:00
*/
2014-04-18 02:08:23 +02:00
public function validate_since ( $line )
2014-04-17 15:00:14 +02:00
{
$since = substr ( ltrim ( $line , " \t " ), strlen ( '* @since ' ));
if ( $since !== trim ( $since ))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Invalid '@since' information for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 1 );
2014-04-17 15:00:14 +02:00
}
$since = ( $since === '3.1-A1' ) ? '3.1.0-a1' : $since ;
if ( ! preg_match ( '#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#' , $since ))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Invalid '@since' information for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-17 15:00:14 +02:00
}
return $since ;
}
/**
* Validate " @event " Information
*
* @ param string $event_name
* @ param string $line
* @ return string
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-17 15:00:14 +02:00
*/
2014-04-18 02:08:23 +02:00
public function validate_event ( $event_name , $line )
2014-04-17 15:00:14 +02:00
{
$event = substr ( ltrim ( $line , " \t " ), strlen ( '* @event ' ));
if ( $event !== trim ( $event ))
{
2014-04-20 14:57:18 +02:00
throw new \LogicException ( " Invalid '@event' information for event "
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 1 );
2014-04-17 15:00:14 +02:00
}
if ( $event !== $event_name )
{
2014-04-20 15:11:23 +02:00
throw new \LogicException ( " Event name does not match '@event' tag for event "
2014-04-20 14:57:18 +02:00
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " , 2 );
2014-04-17 15:00:14 +02:00
}
return $event ;
}
2014-04-18 00:31:06 +02:00
/**
* Validates that two arrays contain the same strings
*
* @ param array $vars_array Variables found in the array line
* @ param array $vars_docblock Variables found in the doc block
* @ return null
2014-04-18 11:13:02 +02:00
* @ throws \LogicException
2014-04-18 00:31:06 +02:00
*/
2014-04-18 02:08:23 +02:00
public function validate_vars_docblock_array ( $vars_array , $vars_docblock )
2014-04-18 00:31:06 +02:00
{
$vars_array = array_unique ( $vars_array );
$vars_docblock = array_unique ( $vars_docblock );
$sizeof_vars_array = sizeof ( $vars_array );
if ( $sizeof_vars_array !== sizeof ( $vars_docblock ) || $sizeof_vars_array !== sizeof ( array_intersect ( $vars_array , $vars_docblock )))
{
2014-04-20 15:11:23 +02:00
throw new \LogicException ( " \$ vars array does not match the list of '@var' tags for event "
2014-04-20 14:57:18 +02:00
. " ' { $this -> current_event } ' in file ' { $this -> current_file } : { $this -> current_event_line } ' " );
2014-04-18 00:31:06 +02:00
}
}
2014-04-17 15:00:14 +02:00
}