Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Model
- {
- public $data = [];
- public $index = 5;
- public $accesors = [];
- function __construct($db = NULL){
- $this->accesorRegister([
- 'password' => function($pass){ return password_hash($pass, PASSWORD_DEFAULT); }
- ]);
- //parent::__construct($db);
- }
- function accesorRegister(array $arr){
- $this->accesors = $arr;
- }
- function apply($data){
- $accesor_keys = array_keys($this->accesors);
- foreach ($data as $k => $dato){
- if (in_array($k, $accesor_keys))
- $data[$k] = $this->accesors[$k]($dato);
- }
- return $data;
- }
- function create($data){
- $this->data[++$this->index] = $this->apply($data);
- return $this->index;
- }
- function get($index){
- return $this->data[$index];
- }
- }
- $obj = new Model;
- $id = $obj->create(['nombre' => 'Pablo', 'pais' => 'Argentina', 'password' => '123']);
- var_dump(['id' =>$id]);
- var_dump($obj->get(6));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement