class Analyzer::Cfml::Coldbox

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:

Defined in:

analyzer/analyzers/cfml/coldbox.cr

Constant Summary

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 Method Summary

Instance Method Summary

Instance methods inherited from class Analyzer

analyze analyze, base_path : String base_path, base_paths : Array(String) base_paths, base_relative_path(path : String) : String base_relative_path, callees_needed? : Bool callees_needed?, content_matches?(content : String, markers : Regex) : Bool content_matches?, http_header_name(name : String) : String | Nil http_header_name, line_number_for_index(content : String, char_index : Int32) : Int32 line_number_for_index, logger : NoirLogger logger, parallel_analyze(files : Array(String), &block : String -> Nil) parallel_analyze, read_file_content(path : String) : String read_file_content, result : Array(Endpoint) result, unique_params(params : Array(Param)) : Array(Param) unique_params, url : String url, web_root_path(path : String, markers : Array(String)) : String web_root_path

Constructor methods inherited from class Analyzer

new(options : Hash(String, YAML::Any)) new

Macros inherited from class Analyzer

analyzer_for(tech) analyzer_for

Instance methods inherited from module FileHelper

all_files : Array(String) all_files, get_files_by_basename(basename : String) : Array(String) get_files_by_basename, get_files_by_extension(extension : String) : Array(String) get_files_by_extension, get_files_by_extensions(extensions : Array(String)) : Array(String) get_files_by_extensions, get_files_by_prefix(prefix : String) : Array(String) get_files_by_prefix, get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String) get_files_by_prefix_and_extension, get_files_by_relative_path(relative_path : String, root : String = "") : Array(String) get_files_by_relative_path, get_public_dir_files(base_path : String, folder : String) : Array(String) get_public_dir_files, get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String) get_public_files, walked_path(expanded : String) : String walked_path

Class Method Detail

def self.tech_name : String #

[View source]

Instance Method Detail

def analyze #

[View source]