pvlg / tarantool-php-datamapper
This package's canonical repository appears to be gone and the package has been frozen as a result.
dev-master
2018-02-23 13:33 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2019-05-05 21:34:34 UTC
README
Usage
/** * @property integer $id * @property string $name * @property float $price */ class Product extends DataMapper { protected $map = [ 0 => 'id', 1 => 'name', 2 => 'price', ]; }
// Tarantool data $data = [ 1, 'Name', 999.99, ]; // Associative array $data = [ 'id' => 1, 'name' => 'Name', 'price' => 999.99, ]; $product = new Product($data); // Getter print_r($product->id); // 1 print_r($product->name); // Name print_r($product->price); // 999.99 // Setter $product->id = 3; $product->name = 'New name'; $product->price = 100; print_r($product->getAsIndex()); // Array // ( // [0] => 3 // [1] => New name // [2] => 100 // ) print_r($product->getAsAttribute()); // Array // ( // [id] => 3 // [name] => New name // [price] => 100 // ) print_r($product->getIndexByAttribute('name')); // 3 print_r($product->getAttributeByIndex(2)); // price print_r($product->getValueByIndex(1)); // New name print_r($product->getValueByAttribute('price')); // 100