Download .zip |
Info | Documentation | View files (4) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2018-10-21 (19 days ago) | Not yet rated by the users | Total: 52 This week: 1 | All time: 9,319 This week: 371 |
Version | License | PHP version | Categories | |||
prop-preprocessor 1.0.1 | MIT/X Consortium ... | 5 | PHP 5, Data types, Language, Traits |
Description | Author | |||
This package can preprocess class variables when they are accessed. Innovation Award
|
This is a simple yet powerful trait which allows one to easily pre-process the properties before they are returned from the objects of classes which use it.
The preferred way to install this extension is to click here which will download the package as a zip file. Instructions on how to use it is explained below.
From the downloaded zip, place the file PreProcessorTrait.php in your project's 'traits' folder(please create one if it does not exist). In your classes, you can use the trait as below:
class ClassName{
use \traits\PreProcessorTrait.php
...
...
...
}
Suppose you have an object $store
and it has a property $products
which is an array of all the Product
objects in that Store
.
The Product
objects are too large and it contains lot of data and you currently need only some minimal data.
Use PreProcessorTrait
in the $store
object's class as explained above and insert the following method in traits\PreProcessorTrait.php
public function getMinified($objects){
foreach($objects as &$object){
$object->minify();
}
return $objects;
}
public function minify(){
//your logic to minify and return the object
}
You can get the minified data by calling like this: $store->productsMinified
. Similarly you can use like this for any property of the $store object. Eg:- $store->invoicesMinified
, $store->customersMinified
etc.
From this point on, any class using the PreProcessorTrait
will have the ability to minify it's properties before returning them.
For example:
$customer->ordersMinified
$brand->productsMinified
$product->categoriesMinified
Like this, you can add whatever methods in PreProcessorTrait and it can be used in any object in which this trait is used in the very same way explained above. For more use cases and examples, click here
Files |
File | Role | Description |
---|---|---|
EXAMPLES.md | Doc. | Examples code |
LICENSE | Lic. | License text |
PreProcessorTrait.php | Class | Class source |
README.md | Doc. | Documentation |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.