Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Encje w Domain Driven Design, DDD
Psajkus
post
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 5
Dołączył: 26.06.2011

Ostrzeżenie: (0%)
-----


Siema,
pisze do was z następującym problemem... zastanawiam się czy we dopuszczalne jest uzycie repozytorium w encji, (chodzi mi o metode setProfil)

  1. class UserEntity
  2. {
  3. //jakies atrybuty
  4.  
  5. //jakies metody
  6.  
  7. /** @var ProfilEntity */
  8. private $_oProfil;
  9.  
  10. public function addProfil(ProfilEntity $oProfilEntity)
  11. {
  12. $this->_oProfil = $oProfilEntity;
  13. }
  14.  
  15. public functin getProfil()
  16. {
  17. if(!isset($this->_oProfil)
  18. {
  19. return $this->setProfil();
  20. }
  21. else
  22. {
  23. return $this->_oProfil;
  24. }
  25. }
  26.  
  27.  
  28. private function setProfil()
  29. {
  30. $oProfilRepository = new ProfilRepository;
  31.  
  32. return $oProfilRepository->find();
  33. }
  34.  
  35.  
  36. }
  37.  
  38. class ProfilEntity
  39. {
  40. //jakies atrryburty i metody
  41. }
  42.  



Czy powinienem odwoływac się do repozytorium z poziomu encji czy raczej przeslać obiekt (wykorzystujac metode addProfil). Jak wy robicie?

Ten post edytował Psajkus 26.06.2011, 11:12:49
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Psajkus
post
Post #2





Grupa: Zarejestrowani
Postów: 45
Pomógł: 5
Dołączył: 26.06.2011

Ostrzeżenie: (0%)
-----


A jak powinno wyglądać tworzenie encji dla kolekcji userow . Czy powinienem pobrać tablice danych w jednym zapytaniu joinem i na podstawioe nich stworzyc encje czy tworzyc kilka osobnych zapytań, np.:

1) zapytanie z joinem
  1. class UserRepository
  2. {
  3. //jakies atrybuty i metdody
  4.  
  5. public function findAll()
  6. {
  7. $aRows = $_usersDAO->findAll(); //zwraca uerow z profilami
  8. $aContener = array();
  9. foreach($aRows as $row)
  10. {
  11. $aUser = array('id' => $row['id'],
  12. 'imie' => $row['imie'],
  13. 'nazwisko' => $row['nazwisko'],
  14. 'profil_id' => $row['profil_id']
  15. );
  16.  
  17. $oUserEntity = new UserEntity($aUser);
  18.  
  19. $aProfil = array('id' => $row['profil_id'],
  20. 'telefon' => $row['telefon'],
  21. 'email' => $row['email']
  22. );
  23.  
  24. $oUserEntity->addProfil(new ProfilEntity($aProfil));
  25.  
  26. $aContener[] = $oUserEntity;
  27. }
  28.  
  29. return new UserCollection($aContener);
  30. }
  31.  
  32. }


2) zwykly select
  1. class UserRepository
  2. {
  3. //jakies atrybuty i metdody
  4.  
  5. public function findAll()
  6. {
  7. $aRows = $this->_usersDAO->findAll(); //zwraca userow
  8. $aContener = array();
  9. foreach($aRows as $row)
  10. {
  11. $aUser = array('id' => $row['id'],
  12. 'imie' => $row['imie'],
  13. 'nazwisko' => $row['nazwisko'],
  14. 'profil_id' => $row['profil_id']
  15. );
  16.  
  17. $oUserEntity = new UserEntity($aUser);
  18.  
  19. $oProfilEntity = $this->_oProfilRepository->find($row['profil_id'])
  20.  
  21. $oUserEntity->addProfil($oProfilEntity);
  22.  
  23. $aContener[] = $oUserEntity;
  24. }
  25.  
  26. return new UserCollection($aContener);
  27. }
  28.  
  29. }
  30.  
  31.  
  32. class ProfilRepository
  33. {
  34. //jakies atrybuty i metody
  35.  
  36. public function find($id)
  37. {
  38. $aRow = $this->_oProfilDao->find($id);
  39.  
  40. return new ProfilEntity($aRow);
  41. }
  42.  
  43. }


3) tworze kolekcje userow bez pobierania profilu i dopiero w widoku gdy wyswietlam userow wywoluje metdoe (z pierwszego postu) getProfil, ktora zwroci mi obiekt Profil.

4) jakieś inne rozwiązanie?


Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 9.10.2025 - 03:11