class
Analyzer::Php::Slim
- Analyzer::Php::Slim
- Analyzer::Php::PhpEngine
- Analyzer
- Reference
- Object
Defined in:
analyzer/analyzers/php/slim.crConstant Summary
-
FOREIGN_ROUTE_COLLECTORS =
Set {"routes", "router", "route", "builder"} -
Cheap pre-filter: avoid heavy regex work on files that clearly aren't Slim. Any file that reaches this analyzer via detection is usually in a Slim project, but project-wide scans still feed unrelated PHP here. Route-collector handles that belong to a different PHP framework by convention:
$routesis CodeIgniter 4 and CakePHP,$builderis CakePHP'sRouteBuilder,$routeris Lumen. Slim's own docs and skeleton use$appand$groupthroughout.This only gates the marker-less fallback below. Every PHP analyzer is fed every
.phpfile in the scan, so in a repo holding more than one PHP framework that fallback read$routes->get('users/(:num)', …)out of CodeIgniter'sapp/Config/Routes.phpand$builder->get('/status', …)out of CakePHP'sconfig/routes.php, and emitted both as Slim routes. A genuine Slim file namingSlim\keeps working regardless of what it calls its variables. -
MEZZIO_MARKER_RE =
/Mezzio\\/ -
Mezzio registers its programmatic routes on
$app->get('/x', Handler::class)— the same expression Slim uses — so Slim read Mezzio's route table as its own.Mezzio\is the one unambiguous marker: a Mezzio application names it, and Slim never does.Laminas\deliberately isn't on this list. Slim apps pull inLaminas\Diactorosfor PSR-7 all the time, so excluding on it would drop their routes. -
PARAM_PATTERNS =
[{/\$args\s*\[\s*['"]([^'"]+)['"]\s*\]/, "path"}, {/->getQueryParams\s*\(\s*\)\s*\[\s*['"]([^'"]+)['"]\s*\]/, "query"}, {/->getParsedBody\s*\(\s*\)\s*\[\s*['"]([^'"]+)['"]\s*\]/, "form"}, {/->getHeaderLine\s*\(\s*['"]([^'"]+)['"]\s*\)/, "header"}, {/->getHeader\s*\(\s*['"]([^'"]+)['"]\s*\)/, "header"}, {/->getCookieParams\s*\(\s*\)\s*\[\s*['"]([^'"]+)['"]\s*\]/, "cookie"}] -
RELEVANCE_MARKER_RE =
/Slim\\|SlimFramework|AppFactory|RouteCollectorProxy/ -
Precompiled once at load: these four markers used to be four separate
String#includes?scans of the whole file ORed together. Crystal'sString#includes?is measurably slower than a single precompiledRegex#matches?call, and this runs on every .php file fed into the analyzer during a project-wide scan. -
VERB_CALL_RECEIVER_RE =
/\$(\w+)->(?:get|post|put|patch|delete|options|head|map|group)\s*\(/i