Object Mapper Class
You can include this library to your code file by typing the below code;
use Ness\Tool\ObjectMapper
Required Namespace
- Ness
- Tool
- ObjectMapper
- Tool
You can include this library to your code file by typing the below code;
use Ness\Tool\ObjectMapper
About Object Mapper Class #top
Object Mappers are used to define a value globally. You can pass any type of variable between Controllers & Views, System & Application, Configuration & Project. In simple words you can pass variable from any layer of your project to another excepts models. Object Mapper class (shortly; omap) is very useful for data transfer and very easy to get adapt. You can transfer variables just writing a single line of code.
Map New Value #top
ObjectMapper::MapNew(string $name, mixed $data);
Map new variable for use it globally | ||
Return | Void | |
Parameters | $name String; id for the object $data Anything; your daat definition. |
Get Mapped Value #top
ObjectMapper::getValue(string $name);
Get a variable's data | ||
Return | Data Type | |
Parameters | $name String; id for the object |
Example #top
Define An Array
/**
* Define an Array
*/
Ness\Tool\ObjectMapper::MapNew("db_connection_string",
array("username"=>"uname",
"password"=>"pw",
"hostname"=>"localhost"));
/**
* Get array value from ObjectMapper
*/
$data = Ness\Tool\ObjectMapper::GetValue("db_connection_string");
Define A String/Integer/Bool/etc
/**
* Define Variables
*/
Ness\Tool\ObjectMapper::MapNew("my_int", 28);
Ness\Tool\ObjectMapper::MapNew("my_str", "Twenty Eight");
Ness\Tool\ObjectMapper::MapNew("my_bool", true);
/**
* Get value from ObjectMapper
*/
$data_1 = Ness\Tool\ObjectMapper::GetValue("my_int");
$data_2 = Ness\Tool\ObjectMapper::GetValue("my_str");
$data_3 = Ness\Tool\ObjectMapper::GetValue("my_bool");
Define An Object
class test_class{ public $data = 'Message'; function __construct() { //Codes } };
/** * Define */ $class = new test_class(); Ness\Tool\ObjectMapper::MapNew("my_class", $class); /** * Get */ $data_1 = Ness\Tool\ObjectMapper::GetValue("my_class");