Symbols final class
Minn\Runtime\Symbols · public/minn/src/Minn/Runtime/Symbols.php · 524 lines
A static read of what a plugin's PHP calls: global functions and classes it uses but does not itself declare, minus the ones it guards with function_exists() or class_exists(). Checked against what the runtime provides, this decides whether a plugin loads at all.
The read is cached in the minn_runtime_symbols option, keeping only the reference's own names (all a verdict reads). An entry is trusted while the folder's fingerprint (its own time and its top-level files' newest) holds, for up to FULL_CHECK_EVERY seconds; then the whole folder is walked again, as an update replaces it. Installing, updating or activating a plugin walks its folder at once (recheck()). Walking every folder on every request cost hundreds of milliseconds on a site with many plugins.
Constants and properties
| private | MAX_FILES = 10000 | The most PHP files a folder's walk reads; a folder past it is not loaded, as its needs are not all known. WPML is 7,080 (64 MB at its peak, once, on activation); the next of the 215 most-run plugins is under 4,800. |
| private | SKIP_DIRS = array ( 0 => 'node_modules', 1 => 'tests', 2 => 'test', 3 => '.git', ) | |
| private | READER = 4 | Bumped whenever the token reader changes, so every cached scan is made again. |
| private | FULL_CHECK_EVERY = 300 | How long a cached entry is trusted on its fingerprint alone before the folder is walked again. |
| private | GIVE_UP_AFTER = 120 | A walk begun this long ago that never finished ran out of time or memory: its folder is held back instead of walked again on every request. |
| private | static ?array $pending |
Public
| static | missing(string $dir, Minn\Runtime\Options $options): array# | What a plugin folder needs that the runtime lacks, cached by mtime. @return array{functions: list<string>, classes: list<string>, redeclares: list<string>, files: int, truncated: bool} | |||
| static | recheck(string $dir, Minn\Runtime\Options $options): void# | The folder is walked again at its next check instead of trusted on its fingerprint: an install, an update or an activation never waits out the window. The walk still keeps the cached read when nothing changed. | |||
| static | redeclaresIn(string $file): array# | The functions one file declares in the global scope, unguarded, that the loaded runtime already defines: including that file would not compile. @return list<string> | |||
| static | missingAgainst(string $dir, Minn\Runtime\SymbolGap $gap): array# | The same read against an exported gap instead of the running engine, so a folder can be judged with no database, no options, and no facade loaded. @return array{functions: list<string>, classes: list<string>, redeclares: list<string>, files: int, truncated: bool} | |||
| static | survey(string $dir, Minn\Runtime\SymbolGap $gap, array $deadEnds): array# | What a folder needs and what it reaches that Minn answers with nothing, in one read, for a machine judging a site before the engine runs it (preflight): the gate's verdict against the gap given, and the dead ends it calls (the wp-admin screens, the editors, the Customizer, XML-RPC, what was left out), by area. A call the folder guards or answers itself is not counted, as the gate counts it.
@return array{functions: list<string>, classes: list<string>, redeclares: list<string>, files: int, truncated: bool, deadEnds: array<string, list<string>>} |
Internals 14
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | key(string $dir): string# | A folder's place in the cache: its parent's name and its own (plugins/kubio, themes/kubio, mu-plugins/x.php), so a plugin and a theme of one name keep entries of their own. | ||||||
| private | keep(array $cache, Minn\Runtime\Options $options): void# | The cache changed this request: written once, when the request ends; entries an older engine kept by name alone go. | ||||||
| private | fingerprint(string $dir): string# | A folder's cheap fingerprint: its own time and its top-level PHP files' newest (an update replaces the folder; a version bumps the main file). | ||||||
| private | namesStamp(): string# | The reference names a reduced scan was kept against: a new interface (a WordPress update) makes every scan again. | ||||||
| private | reduced(array $scan): array# | A scan cut to the reference's own names, the only ones a verdict asks about.
@return array<string, mixed> | ||||||
| private | verdict(array $scan, int $files, Minn\Runtime\SymbolGap $gap): array# | Only the reference's own interface counts: a function or class the plugin needs from WordPress. Its own integrations with other plugins and PHP extensions are its business.
@return array{functions: list<string>, classes: list<string>, redeclares: list<string>, files: int, truncated: bool} | ||||||
| private | phpFiles(string $dir): array# | @return list<string> | ||||||
| private | scan(array $files): array# | Every file's tokens into one table: the functions called, the classes referenced, both minus what the folder declares itself or guards with an existence check.
@return array{calls: list<string>, classes: list<string>, declared: array<string, true>, declaredClasses: array<string, true>, guarded: array<string, true>, truncated: bool} | ||||||
| private | scanTokens(array $tokens, Minn\Runtime\SymbolTable $table): void# | One file's tokens. A class name is resolved as PHP resolves it: through the file's use imports, else inside its namespace, so a plugin that imports a WordPress class (a provider built on the AI client's abstract provider) is judged on the class it really names.
| ||||||
| private | inGuardedNamespace(string $lower, array $guarded): bool# | Whether a class sits in the namespace of a class the folder checks for: a plugin that asks class_exists( 'Vendor\\Lib\\Client' ) before using the library treats the library as optional, its other classes with it (Ninja Forms checks WordPress's AI client so, then builds its requirements).
| ||||||
| private | noteName(array $tokens, int $i, string $namespace, array $imports, Minn\Runtime\SymbolTable $table): void# | A name token: a class reference when it follows new / extends / implements / instanceof or precedes ::, a call when it precedes "(", and a guard when the call is an existence check on a literal.
| ||||||
| private | resolve(string $name, string $namespace, array $imports): string# | A class name as PHP resolves it in the file: its first part an imported alias, else inside the file's namespace.
| ||||||
| private | readImports(array $tokens, int $i, array $imports): int# | Reads one use statement's class imports (use A\B; use A\B as C; use A\{B, C as D};), leaving out function and constant imports, and returns the index of its semicolon.
| ||||||
| private | significant(array $tokens, int $from, int $step): ?array# | The nearest token in either direction that is not whitespace or a comment, as [id, text]. @param list<array|string> $tokens @return array{0: ?int, 1: string}|null
|
Nothing matches.