Last active
April 13, 2016 09:44
-
-
Save roryl/5fbeecc3f9dde7289f519b7963db6a72 to your computer and use it in GitHub Desktop.
Lucee Properties Examples
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
component { | |
public function init(){ | |
} | |
} |
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> | |
writeDump(new basicComponent()); | |
writeDump(new componentWithProperties()); | |
writeDump(new componentWithPropertiesAccessor()); | |
</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
component { | |
property name='myValue'; | |
public function init(){ | |
return this; | |
} | |
} |
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
component accessors='true' { | |
property name='myValue'; | |
public function init(){ | |
return this; | |
} | |
} |
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
component accessors='true' { | |
property name='myValue' default='test this is a default!'; | |
public function init(){ | |
return this; | |
} | |
public function getValue(){ | |
return variables.myValue; | |
} | |
} |
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
component accessors='true' { | |
property name='myValue' required='true'; | |
} |
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
component accessors='true' { | |
property name='myValue' setter='false'; | |
public function init(){ | |
variables.myValue = 'Hello!'; | |
return this; | |
} | |
} |
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
component accessors='true' { | |
property name='myValue' required='true'; //Required has no effect | |
public function init(){ | |
return this; | |
} | |
} |
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
component accessors='true' { | |
property name='myValue' type='struct'; | |
public function init(){ | |
return this; | |
} | |
} |
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
component accessors='true' { | |
property name='myEmail' validate='email'; | |
property name='myString' validate='string' validateparams="{minLength=0, maxLength=5}"; | |
} |
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> | |
myComponent = new componentWithPropertiesNoConstructor(myValue:"Hello there!"); | |
echo(myComponent.getMyValue()); | |
myComponent = new componentWithPropertiesNoConstructor({myValue:"Hello there!"}); //Equivalent to the above | |
echo(myComponent.getMyValue()); | |
myComponent = new componentWithPropertiesNoConstructor(argumentCollection={myValue:"Hello there!"}); //Equivalent to the above | |
echo(myComponent.getMyValue()); | |
writeDump(now()); | |
</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
/** | |
* My xUnit Test | |
*/ | |
component extends="testbox.system.BaseSpec"{ | |
/*********************************** LIFE CYCLE Methods ***********************************/ | |
// executes before all test cases | |
function beforeTests(){ | |
} | |
// executes after all test cases | |
function afterTests(){ | |
} | |
// executes before every test case | |
function setup( currentMethod ){ | |
} | |
// executes after every test case | |
function teardown( currentMethod ){ | |
} | |
/*********************************** TEST CASES BELOW ***********************************/ | |
// Remember that test cases MUST start or end with the keyword 'test' | |
function checkAllSyntaxTest(){ | |
var files = directoryList(""); | |
for(file IN files){ | |
if(file CONTAINS ".cfm" AND !file CONTAINS "use_validations"){ | |
include template="#getFileFromPath(file)#"; | |
} | |
} | |
} | |
function getDefaultValueTest(){ | |
var myObj = new componentWithPropertiesDefault(); | |
expect(myObj.getValue()).toBe("test this is a default!"); | |
} | |
function validateParamsTest(){ | |
var myObj = new componentWithPropertyValidations(myEmail:"test@domain.com", myString:"hellothere"); | |
// myObj.setMyString("hellothere"); | |
writeDump(myObj); | |
} | |
function useValidationsTest(){ | |
expect(function(){include template="use_validations.cfm"}).toThrow(); | |
} | |
} |
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> | |
writeDump(getComponentMetaData("componentWithProperties")); | |
</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> | |
myComponent = new componentWithPropertiesAccessor(); | |
myComponent.setMyValue("Hello!"); | |
echo(myComponent.getMyValue()); | |
</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> | |
myComponent = new componentWithPropertiesDefault(); | |
writeDump(myComponent); | |
echo(myComponent.getMyValue()); | |
writeDump(myComponent.getValue()); | |
</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> | |
myComponent = new componentWithPropertiesOverride(); | |
writeDump(myComponent); | |
echo(myComponent.getMyValue()); | |
//myComponent.setMyValue("Hello!"); //errors that function does not exist | |
</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> | |
myComponent = new componentWithPropertiesRequired({}); | |
myComponent.setMyValue("Hello!"); | |
echo(myComponent.getMyValue()); | |
</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> | |
myComponent = new componentWithPropertiesType(); | |
writeDump(myComponent); | |
// myComponent.setMyValue('test'); //Will throw an error for invalid type | |
echo(myComponent.getMyValue()); | |
</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> | |
myObj = new componentWithPropertyValidations(); | |
myObj.setMyEmail("test@domain.com"); //works | |
myObj.setMyString("hello"); //works | |
myObj.setMyEmail("test"); //throws error for invalid email | |
myObj.setMyString("hello there!"); //Throws error for invalid string | |
//Validation of auto poplated members is currently broken see https://luceeserver.atlassian.net/browse/LDEV-816 | |
myObj = new componentWithPropertyValidations(myEmail:"test", myString:"hello there!"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment