Advertisement
Guest User

Model

a guest
Nov 26th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. class UserRepository
  2. {
  3.     private $mapper;
  4.  
  5.     public function __construct(Nette\Database\Context $database)
  6.     {
  7.        $this->mapper = new UserMapper($database)
  8.     }
  9. }
  10.  
  11. class UserMapper
  12. {
  13.     private $database;
  14.    
  15.     private $table = 'users';
  16.    
  17.     public function __construct(Nette\Database\Context $database)
  18.     {
  19.         $this->database = $database;
  20.     }
  21.    
  22.     /** REGISTRACE UZIVATELE
  23.         @return int (user id)
  24.     **/
  25.     public function insertNewUser(USERENTITY $user)
  26.     {
  27.         return $this->database->table($this->table)->insert($user->toArray());
  28.     }
  29.    
  30.  
  31. }
  32.  
  33. class User
  34. {
  35.  
  36.     private $id;
  37.  
  38.     private $username;
  39.  
  40.     private $password;
  41.  
  42. // etc ...
  43. // musis si udelat neco cim ty entity naplnnis
  44.    
  45.     /**
  46.        @param $data (data z formulare nebo radek z databaze whatever)
  47.     **/
  48.     public function __construct($data)
  49.     {
  50.         // naplnis entitu datama a si libovej
  51.         // rekneme ze ti prijde http request na registraci
  52.             // nejak to vymrdas ti data z JSONU zavolas si new User(json data api)
  53.         // a pak zavolas jenom repository
  54.         // $repository->insertNewUser($userEntity)
  55.  
  56.         $this->populate($data);
  57.     }
  58.    
  59.     /** VYMYSLI JAK SI BUDES CHTIT NAPLNOVAT PROPERTIES TY TRIDY **/
  60.     private function populate()
  61.     {
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement