Guest User

Untitled

a guest
Jul 9th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. class Person
  3. {
  4. //metadata
  5. protected $_email;
  6. protected $_password;
  7. protected $_username;
  8.  
  9. public function __get($name) { }
  10. public function __set($name, $value) { }
  11.  
  12. //Behaviors
  13. public function authenticate() { }
  14. public function logout() { }
  15. public function ban() { }
  16.  
  17. }
  18.  
  19. class personTable extends Zend_Db_Table_Abstract 
  20. {
  21.     protected $_name='person';
  22.     protected $_primary='username';
  23. public function save($data) {
  24. // insert || update logic
  25. }
  26. }
  27.  
  28.  
  29. class personMapper
  30. {
  31. private $table;
  32.  
  33.     public function save(Person $person)
  34.     {
  35.         $data  = array(
  36.         'username' => $person->username,
  37.         'password' => $person->password,
  38.         'email'    => $person->email
  39.         );
  40.         $this->getTable()->save($data);
  41.     }
  42.     public function fetch($username=null);
  43.     public function getTable() {
  44. if(! $this->table) {
  45. $this->table = new personTable();
  46. }
  47. return $this->table;
  48. };
  49.     public function setTable($table) {
  50. $this->table = $table;
  51. }
  52. }
  53.  
  54.  
  55.  
  56. class PersonService
  57. {
  58.     public function create(array $data)
  59.     {
  60.         // у нас ведь нет класса Person! - почему он тут используется?
  61.         $person = new Person();
  62.         if(!$data = $this->getValidator()
  63.         ->isValid($data)
  64.         )
  65.         {
  66.             throw new  InvalidArgumentExeption();
  67.         }
  68.         $person->username= $data['username'];
  69.         $person->password=$data['password'];
  70.         $person->email = $data['email'];
  71.          
  72.         //нет метода getMapper() - я так понимаю что он возвращает обьект класса PersonMapper?
  73. // Уже есть! что дальше?
  74.         $this->getMapper()->save($person);
  75.         return $person;
  76.     }
  77. function getMapper() {
  78. if(!$this->personMapper) {
  79.   return new PersonMapper();
  80. }
  81. return $this->personMapper;
  82. }
  83.  
  84. }
Add Comment
Please, Sign In to add comment