Skip to content

Commit

Permalink
COLDBOX-904 #resolve
Browse files Browse the repository at this point in the history
Interceptor Buffer Methods Removed
  • Loading branch information
lmajano committed Jul 10, 2020
1 parent d125297 commit 61fa3fb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 101 deletions.
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"scripts":{
"format": "cfformat run system/**/*.cfc,tests/specs/**/*.cfc --overwrite",
"format:watch": "cfformat watch system/**/*.cfc,tests/specs/**/*.cfc ./cfformat.json",
"format:watch": "cfformat watch system/**/*.cfc,tests/specs/**/*.cfc ./.cfformat.json",
"format:check": "cfformat check system/**/*.cfc,tests/specs/**/*.cfc",
"start:lucee" : "server start serverConfigFile='server-lucee@5.json' --force",
"start:2016" : "server start serverConfigFile='server-adobe@2016.json' --force",
Expand Down
138 changes: 50 additions & 88 deletions system/Interceptor.cfc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* Base class for all interceptors
* @author Luis Majano <lmajano@ortussolutions.com>
*/
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* Base class for all interceptors
*/
component extends="coldbox.system.FrameworkSupertype" serializable="false" accessors="true"{

// Controller Reference
Expand All @@ -20,137 +19,100 @@ component extends="coldbox.system.FrameworkSupertype" serializable="false" acces
// WireBox Reference
property name="wirebox";
// The interceptor properties structure
property name="properties" type="struct";
property name="properties" type="struct";
// The interceptor service
property name="interceptorService" type="coldbox.system.services.InterceptorService";
property name="interceptorService" type="coldbox.system.services.InterceptorService";

/**
* Constructor
* @controller The ColdBox controller
* @properties The properties to init the Interceptor with
*
* @result Interceptor
*/
* Constructor
*
* @controller The ColdBox controller
* @properties The properties to init the Interceptor with
*
* @return Interceptor
*/
function init( required controller, struct properties={} ){
// Register Controller
variables.controller = arguments.controller;
// Register LogBox
variables.logBox = arguments.controller.getLogBox();
variables.logBox = arguments.controller.getLogBox();
// Register Log object
variables.log = variables.logBox.getLogger( this );
variables.log = variables.logBox.getLogger( this );
// Register Flash RAM
variables.flash = arguments.controller.getRequestService().getFlashScope();
variables.flash = arguments.controller.getRequestService().getFlashScope();
// Register CacheBox
variables.cacheBox = arguments.controller.getCacheBox();
variables.cacheBox = arguments.controller.getCacheBox();
// Register WireBox
variables.wireBox = arguments.controller.getWireBox();
variables.wireBox = arguments.controller.getWireBox();
// Load global UDF Libraries into target
loadApplicationHelpers();
// store properties
variables.properties = arguments.properties;
variables.properties = arguments.properties;
// setup interceptor service
variables.interceptorService = arguments.controller.getInterceptorService();

return this;
}

/**
* Configuration method for the interceptor
*/
* Configuration method for the interceptor
*/
void function configure(){}

/**
* Get an interceptor property
* @property The property to retrieve
* @defaultValue The default value to return if property does not exist
*/
* Get an interceptor property
*
* @property The property to retrieve
* @defaultValue The default value to return if property does not exist
*
* @return The property value requested or the default value if not found
*/
any function getProperty( required property, defaultValue ){
return ( structKeyExists( variables.properties, arguments.property ) ? variables.properties[ arguments.property ] : arguments.defaultValue );
}

/**
* Get struct of properties
*/
any function getProperties(){
* Get the struct of properties defined in this interceptor
*/
struct function getProperties(){
return variables.properties;
}

/**
* Store an interceptor property
* @property The property to store
* @value The value to store
*
* @return Interceptor instance
*/
* Store an interceptor property
*
* @property The property to store
* @value The value to store
*
* @return Interceptor instance
*/
any function setProperty( required property, required value ){
variables.properties[ arguments.property ] = arguments.value;
return this;
}

/**
* Verify an interceptor property
* @property The property to check
*/
* Verify an interceptor property exists
*
* @property The property to check
*/
boolean function propertyExists( required property ){
return structKeyExists( variables.properties, arguments.property );
}

/**
* Unregister the interceptor
* @state The named state to unregister this interceptor from
*
* @return Interceptor
*/
function unregister( required state ){
var interceptorClass = listLast( getMetadata( this ).name, "." );
variables.controller.getInterceptorService().unregister( interceptorClass, arguments.state );
return this;
}

/**************************************** BUFFER METHODS ****************************************/

/**
* Clear the interceptor buffer: Deprecated, please use incoming buffer arguements instead, this is not thread safe
* @deprecated
* @return Interceptor
*/
function clearBuffer(){
getBufferObject().clear();
return this;
}

/**
* Append to the interceptor buffer: Deprecated, please use incoming buffer arguments instead, this is not thread safe
* @deprecated Please use the incoming `buffer` argument instead
* Unregister the interceptor from the state passed
*
* @str The string to append to the buffer
* @state The named state to unregister this interceptor from
*
* @return Interceptor
*/
function appendToBuffer( required str ){
getBufferObject().append( arguments.str );
function unregister( required state ){
var interceptorClass = listLast( getMetadata( this ).name, "." );
variables.controller
.getInterceptorService()
.unregister( interceptorClass, arguments.state );
return this;
}

/**
* Get the string representation of the buffer: Deprecated, please use incoming buffer arguements instead, this is not thread safe
* @deprecated Please use the incoming `buffer` argument instead
*/
string function getBufferString(){
return getBufferObject().getString();
}

/**
* Get the request buffer object from scope.: Deprecated, please use incoming buffer arguements instead, this is not thread safe
* @deprecated Please use the incoming `buffer` argument instead
* @return struct
*/
function getBufferObject(){
if( !request.keyExists( "__cbox_buffer" ) ){
request[ "__cbox_buffer" ] = variables.interceptorService.getLazyBuffer();
}
return request[ "__cbox_buffer" ];
}

}
1 change: 1 addition & 0 deletions tests/specs/EventHandlerTest.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
component extends = "coldbox.system.testing.BaseModelTest"{

function setup(){
handler = createMock( "coldbox.system.EventHandler" );
mockController = createMock( "coldbox.system.web.Controller" );
Expand Down
26 changes: 14 additions & 12 deletions tests/specs/InterceptorTest.cfc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<cfcomponent extends="coldbox.system.testing.BaseModelTest" output="false">
<cfscript>
component extends="coldbox.system.testing.BaseModelTest"{

function setup(){
interceptor = createMock( className = "coldbox.system.Interceptor" );
mockIService = createMock( className = "coldbox.system.web.services.InterceptorService", clearMethods = true );
mockController = createMock( className = "coldbox.system.web.Controller" );
mockRS = createMock( className = "coldbox.system.web.services.RequestService" );
flashScope = createMock( className = "coldbox.system.web.flash.MockFlash" );
mockLogBox = createMock( className = "coldbox.system.logging.LogBox" );
mockLogger = createMock( className = "coldbox.system.logging.Logger" );
interceptor = createMock( "coldbox.system.Interceptor" );
mockIService = createMock( "coldbox.system.web.services.InterceptorService", clearMethods = true );
mockController = createMock( "coldbox.system.web.Controller" );
mockRS = createMock( "coldbox.system.web.services.RequestService" );
flashScope = createMock( "coldbox.system.web.flash.MockFlash" );
mockLogBox = createMock( "coldbox.system.logging.LogBox" );
mockLogger = createMock( "coldbox.system.logging.Logger" );
mockCacheBox = createEmptyMock( "coldbox.system.cache.CacheFactory" );
mockWireBox = createEmptyMock( "coldbox.system.ioc.Injector" );

Expand All @@ -29,7 +29,9 @@
debugmode : true,
configFile : "config/routes.cfm"
};
interceptor.init( mockController, properties ).$( "getInterceptorService", mockIService );
interceptor
.init( mockController, properties )
.$( "getInterceptorService", mockIService );
}

function testProperties(){
Expand All @@ -47,5 +49,5 @@
interceptor.unregister( "preProcess" );
assertEquals( mockIService.$count( "unregister" ), 1 );
}
</cfscript>
</cfcomponent>

}

0 comments on commit 61fa3fb

Please sign in to comment.