Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Sources/Actions/Admin/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2300,13 +2300,21 @@ protected static function parseIntegrationHook(string $hook, string $rawData): a
protected static function getDefinedFunctionsInFile(string $file): array
{
$source = file_get_contents($file);
// token_get_all() is too slow so use a nice little regex instead.
preg_match_all('/\bnamespace\s++((?P>label)(?:\\\(?P>label))*+)\s*+;|\bclass\s++((?P>label))[\w\s]*+{|\bfunction\s++((?P>label))\s*+\(.*?\)[:\|\w\s]*+{(?(DEFINE)(?<label>[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*+))/is', $source, $matches, PREG_SET_ORDER);

if (!str_contains($source, 'function')) {
return [];
}

// Remove multiline comments so regex does not
// match fake functions/classes inside them.
$source = preg_replace('~//[^\h]+|/\*.*?\*/~s', '', $source);
$functions = [];
$namespace = '';
$class = '';

// token_get_all() is too slow so use a nice little regex instead.
preg_match_all('/\b(?:namespace\s+((?P>label)(?:\\\(?P>label))*+)\s*;|(?:class\s+((?P>label))(?:[\s,]|\\\\|(?P>label))*+|function\s+((?P>label))\s*\([^)]*\)\s*(?::[^{]+)?){)(?(DEFINE)(?<label>[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*+))/i', $source, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
if (!empty($match[1])) {
$namespace = $match[1] . '\\';
Expand Down
Loading