class

Analyzer::Cfml::Coldbox

Inherits Analyzer::Cfml::CfmlEngine < Analyzer < FileHelper < Reference < Object

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.cfc entryPoint, so ContentBox's API routes are /cbapi/v1/login rather than /login;
  • a bare route() accepts any verb, but the handler constrains it via this.allowedMethods, so that map decides the verbs instead of fanning out to all seven.

Constants

ACTION_VERB_RE = /["']?(\w+)["']?\s*[:=]/
ADD_NAMESPACE_RE = /(?<![\w.])addNamespace\s*\(/i
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_ACTIONS_RE = /\.\s*withAction\s*\(\s*\{([^}]*)\}/i

route( "/x" ).withAction( { get : "show", post : "save" } ) binds one action per verb, so the struct's keys are the verbs the route answers. Without this a route() carrying only a withAction map fell back to GET — ColdBox's own harness registers /invalid-restful and /invalid-main-method as POST that way.

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"{

GROUP_CALL_RE = /(?<![\w.])group\s*\(/i

group( { pattern : "/api" }, function( options ){ ... } ) prefixes every route declared inside the closure, and groups nest. Ignoring them is both a false positive and a false negative at once: ColdBox's own test harness declares route( "/:user_id" ) inside group( { pattern : "/runAWNsync" ... } ), which was reported as /:user_id — a URL that answers nothing — while the real /runAWNsync/:user_id went unreported.

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.

NAMESPACE_MOUNT_RE = /\.\s*toNamespaceRouting\s*\(\s*["']([^"']+)["']/i

A group may name a namespace instead of a path. Namespaces are not paths in themselves: they become reachable only where a route mounts them, so the mount pattern is what supplies the prefix.

NAMESPACE_ROUTE_RE = /(?<![\w.])route\s*\(\s*["']([^"']+)["']\s*\)\s*\.\s*toNamespaceRouting\s*\(\s*["']([^"']+)["']\s*\)/i

route( "/luis" ).toNamespaceRouting( "luis" ) — the mount pattern and the namespace it carries, in one statement.

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 is id / 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"}

Class methods

tech_name
Source

Instance methods

analyze
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source