Author: wim niemans
Last month viewers: 4
Package: Armory PHP Closure Trait
Read this short tutorial to learn about several ways to use the PHP Armory Trait.
What is the Armory PHP Closure Trait Useful for?
The Armory PHP Closure Trait provides means to handle events that may happen inside a class by invoking callback functions that we call closures using code that can defined outside that class.
How to Gather Multiple Callback Functions in Single Object?
This trait is ideal to gather API function calls that usually need multitude of object instances.
Instead of creating an API environment and pass it around, you can gather the important calls in a separate object of a class and pass that object around.
Since the origin object is bound to the closure object using the $this operator, there is no need to get the object again, as the $this operator can be called from the closure function code.
How to Encapsulate Many Global Functions in a Single Object?
Another way of using the Armory PHP Closure Trait is to gather global functions and have them renamed within this trait.
This way code can be developed without knowing the exact spelling of those global function names.
When testing your system it is a simple task to adjust functions, replace them by mockups, or rename or duplicate them.
This package can be downloaded from download page or be installed using the PHP Composer tool following instructions in the Composer install instructions page.
If you liked this article, please share it with your PHP colleague developers, so they appreciate you more for being nice and they also share nice articles with you too.
You need to be a registered user or login to post a comment
Login Immediately with your account on:
No comments were submitted yet.