Guest User

Untitled

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