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

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

Instance Method Summary

Instance methods inherited from class Analyzer

analyze analyze, base_path : String base_path, base_paths : Array(String) base_paths, callees_needed? : Bool callees_needed?, 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

Instance methods inherited from module FileHelper

all_files : Array(String) all_files, 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_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

Instance Method Detail

def analyze #

[View source]