+ }
+
+ /**
+ * Get hooks from a PHP file
+ * @param string $filePath Full file path to the PHP file.
+ * @return array Array: key => hook name; value => array of arguments or string 'unknown'
+ */
+ private function getHooksFromFile( $filePath ) {
+ $content = file_get_contents( $filePath );
+ $m = [];
+ preg_match_all(
+ // All functions which runs hooks
+ '/(?:wfRunHooks|Hooks\:\:run)\s*\(\s*' .
+ // First argument is the hook name as string
+ '([\'"])(.*?)\1' .
+ // Comma for second argument
+ '(?:\s*(,))?' .
+ // Second argument must start with array to be processed
+ '(?:\s*(?:array\s*\(|\[)' .
+ // Matching inside array - allows one deep of brackets
+ '((?:[^\(\)\[\]]|\((?-1)\)|\[(?-1)\])*)' .
+ // End
+ '[\)\]])?/',
+ $content,
+ $m,
+ PREG_SET_ORDER
+ );
+
+ // Extract parameter
+ $hooks = [];
+ foreach ( $m as $match ) {
+ $args = [];
+ if ( isset( $match[4] ) ) {
+ $n = [];
+ if ( preg_match_all( '/((?:[^,\(\)]|\([^\(\)]*\))+)/', $match[4], $n ) ) {
+ $args = array_map( 'trim', $n[1] );
+ // remove empty entries from trailing spaces
+ $args = array_filter( $args );
+ }
+ } elseif ( isset( $match[3] ) ) {
+ // Found a parameter for Hooks::run,
+ // but could not extract the hooks argument,
+ // because there are given by a variable
+ $args = 'unknown';
+ }
+ $hooks[$match[2]] = $args;
+ }
+