Last active
May 5, 2021 12:22
-
-
Save bennadel/afdce739f2bc6960da24410b9eab89b0 to your computer and use it in GitHub Desktop.
Validating And Documenting Complex Object Structures With CFParam In Lucee CFML 5.3.7.47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// For safety and DOCUMENTATION (regarding which values are needed within this | |
// template), validate the general structure of the attributes. | |
param name="attributes.project" type="struct"; | |
param name="attributes.project.id" type="numeric"; | |
param name="attributes.project.name" type="string"; | |
param name="attributes.project.createdAt" type="date"; | |
param name="attributes.project.owner" type="struct"; | |
param name="attributes.project.owner.id" type="numeric"; | |
param name="attributes.project.owner.name" type="string"; | |
param name="attributes.project.screens" type="array"; | |
// We can't validate screen structures unless we have at least one screen. | |
if ( attributes.project.screens.len() ) { | |
param name="attributes.project.screens[ 1 ].id" type="numeric"; | |
param name="attributes.project.screens[ 1 ].name" type="string"; | |
param name="attributes.project.screens[ 1 ].clientFilename" type="string"; | |
} | |
// .... consume attribute values .... | |
dump( attributes.project ); | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
project = { | |
id: 1, | |
name: "Public Site Redesign", | |
createdAt: createDate( 2021, 1, 15 ), | |
owner: { | |
id: 4, | |
name: "Ben Nadel" | |
}, | |
screens: [ | |
{ | |
id: 101, | |
name: "Home Page", | |
clientFilename: "home@2x.png" | |
} | |
] | |
}; | |
module | |
template = "./MyTag.cfm" | |
project = project | |
; | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment