mementifier
module. This module will transform your business objects into native ColdFusion (CFML) data structures with 🚀 speed. It will inject itself into ORM objects and/or business objects alike and give them a nice getMemento()
function to transform their properties and relationships (state) into a consumable structure or array of structures. It can even detect ORM entities and you don't even have to write the default includes manually, it will auto-detect all properties. No more building transformations by hand! No more inconsistencies! No more repeating yourself!Memento pattern is used to restore state of an object to a previous state or to produce the state of the object.
cffractal
(https://forgebox.io/view/cffractal) and build consistent and fast 🚀 object graph transformations.config/Coldbox.cfc
and add the following settings into the moduleSettings
struct under the mementifier
key:this.memento
structure in order for the mementifier
to inject a getMemento()
method into the target. This method will allow you to transform the entity and its relationships into native struct/array/native formats.this.memento
Markerthis.memento
struct with the following (optional) available keys:mementifier
will call the public getter
method for the property to retrieve its value. If the returning value is null
then the value will be an empty
string. If you are using CF ORM and the ormAutoIncludes
setting is true (by default), then this array can be auto-populated for you, no need to list all the properties.[ "*" ]
which will tell the mementifier to introspect the object for all properties
and use those instead for the default includes.Also note theormAutoIncludes
setting, which if you are using a ColdFusion ORM object, we will automatically add all properties to the default includes.
User
object needs to have an avatarLink
in it's memento. Then you can add a avatarLink
to the array and create the appropriate getAvatarLink()
method. Then the mementifier
will call your getter and add it to the resulting memento.DefaultIncldues
array can also include nested relationships. So if a User
has a Role
relationship and you want to include only the roleName
property, you can do role.roleName
. Every nesting is demarcated with a period (.
) and you will navigate to the relationship.DefaultExcludes
array can also declare nested relationships. So if a User
has a Role
relationship and you want to exclude the roleID
property, you can do role.roleId
. Every nesting is demarcated with a period (.
) and you will navigate to the relationship and define what portions of the nested relationship can be excluded out.getMemento()
call receives an include that is listed in this array, it will still not add it to the resulting memento. This is great if you are using dynamic include and exclude lists. You can also use nested relationships here as well.null
value. The key
of the structure is the name of the property and/or relationship. Please note that if you have a collection of relationships (array), the default value is an empty array by default. This mostly applies if you want complete control of the default value.key
of the structure is the name of the property and/or relationship. The value
is a closure that receives the item and it must return back the item mapped according to your function.getMemento()
MethodYou can find the API Docs Here: https://apidocs.ortussolutions.com/coldbox-modules/mementifier/1.0.0/index.html​
includes, excludes, mappers and defaults
. This will allow you to add upon the defaults dynamically.ignoreDefaults
flag. If you turn that flag to true
then ONLY the passed in includes and excludes
will be used in the memento. However, please note that the neverInclude
array will always be used.getMemento()
method. No problem! If you create your own getMemento()
method, then the mementifier
will inject the method as $getMemento()
so you can do your overrides:results
- An array containing all the unique identifiers from the array of objects processedresultsMap
- A struct keyed by the unique identifier containing the memento of each of those objects.[email protected]
and call the process()
method with your collection, the unique identifier key name (defaults to id
) and the other arguments that getMemento()
can use. Here is the signature of the method: