class
Analyzer::Cfml::Coldbox
- Analyzer::Cfml::Coldbox
- Analyzer::Cfml::CfmlEngine
- Analyzer
- Reference
- Object
Overview
ColdBox routing.
Routes are declared in a dedicated config/Router.cfc (or the legacy
config/routes.cfm), which makes them the closest CFML analogue of a
Rails or Laravel route file:
route( "/", "echo.index" );
post( "/login", "auth.login" );
get( "/sites/:slug/settings", "siteSettings.index" );
resources( resource = "authors", except = "new,edit" );
route( "/render/:format" ).to( "actionRendering.index" );
Two pieces of context live outside the router and are resolved here, because without them the emitted URLs and verbs are wrong:
- a module's routes are mounted under its
ModuleConfig.cfcentryPoint, so ContentBox's API routes are/cbapi/v1/loginrather than/login; - a bare
route()accepts any verb, but the handler constrains it viathis.allowedMethods, so that map decides the verbs instead of fanning out to all seven.
Defined in:
analyzer/analyzers/cfml/coldbox.crConstant Summary
-
ADD_ROUTE_RE =
/(?<![\w.])addRoute\s*\(/i -
Legacy tag-syntax registration, still present in older configs.
-
ALLOWED_METHODS_BLOCK_RE =
/this\s*\.\s*allowedMethods\s*=\s*\{([^}]*)\}/i -
this.allowedMethods = { index : "GET", create : "POST,PUT" } -
ALLOWED_METHODS_ENTRY_RE =
/["']?(\w+)["']?\s*:\s*["']([^"']*)["']/ -
CHAIN_LIMIT =
400 -
CHAINED_VERBS_RE =
/\.\s*withVerbs\s*\(\s*["']([^"']+)["']/i -
Chained builders that follow
route( ... )up to the statement end. -
FUNCTION_ALLOWED_RE =
/(?<![\w.])function\s+(\w+)\s*\([^)]*\)[^{;]*?allowedMethods\s*=\s*["']([^"']+)["']/i -
function show( event, rc, prc ) allowedMethods="GET"{ -
INTERPOLATION_RE =
/#\s*([A-Za-z_]\w*)\s*#/ -
LOCAL_STRING_RE =
/(?:var\s+)?([A-Za-z_]\w*)\s*=\s*["']([^"'#]*)["']\s*;/ -
var sitePrefix = "/sites/:site"— referenced as#siteprefix#, case-insensitively. -
PLACEHOLDER_RE =
/:([A-Za-z_]\w*)(?:[-{(][^\/]*)?/ -
Placeholders carry inline constraints in three shapes, and all of them must be stripped or the quantifier leaks into the URL:
:id-numeric{2}:name-regex(luis):name{4}The parameter isid/name; everything from the first-,{or(to the end of the segment is the constraint. -
RESOURCE_ROUTES =
[{"index", "GET", ""}, {"new", "GET", "/new"}, {"create", "POST", ""}, {"show", "GET", "/:id"}, {"edit", "GET", "/:id/edit"}, {"update", "PUT", "/:id"}, {"delete", "DELETE", "/:id"}] -
ColdBox's standard resource expansion.
-
RESOURCES_RE =
/(?<![\w.])resources\s*\(/i -
ROUTE_CALL_RE =
/(?<![\w.])(route|get|post|put|patch|delete|head|options)\s*\(/i -
route()is verb-agnostic; the rest name their verb. -
ROUTER_FILES =
Set {"router.cfc", "routes.cfm"}