fork download
  1. <?php
  2. class Root {
  3.  
  4. public $domainList = array();
  5.  
  6. public function addDomain($domainName)
  7. {
  8. $domain = new Domain($domainName);
  9. $this->domainList[$domainName] = $domain;
  10. }
  11. }
  12.  
  13. class Domain {
  14.  
  15. public $domainName = null;
  16. public $memberList = array();
  17.  
  18. public function __construct($domainName) {
  19. $this->domainName = $domainName;
  20. }
  21.  
  22. public function addMember($email, $orders, $value) {
  23. $member = new Member($this->domainName, $email, $orders, $value);
  24. $this->memberList[$email] = $member;
  25. }
  26.  
  27. public function getMember($memberName) {
  28. return $this->memberList[$memberName];
  29. }
  30. }
  31.  
  32. class Member {
  33.  
  34. public $domain = null;
  35. public $email = null;
  36. public $orders = null;
  37. public $value = null;
  38.  
  39. public function __construct($domain, $email, $orders, $value) {
  40. $this->domain = $domain;
  41. $this->email = $email;
  42. $this->orders = $orders;
  43. $this->value = $value;
  44. }
  45.  
  46. public function getDomain() {
  47. return $this->domain;
  48. }
  49.  
  50. }
  51.  
  52. $root = new Root();
  53.  
  54. $root->addDomain("hotmail.com");
  55. $root->addDomain("gmail.com");
  56. $root->domainList["hotmail.com"]->addMember("john.doe",1,12);
  57. $root->domainList["hotmail.com"]->addMember("jessie.anderson",1,12);
  58. $root->domainList["hotmail.com"]->addMember("paul.whitney",1,12);
  59. $root->domainList["gmail.com"]->addMember("alexis",1,12);
  60.  
  61. print_r($root->domainList["hotmail.com"]->getMember("john.doe"));
  62. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Member Object
(
    [domain] => hotmail.com
    [email] => john.doe
    [orders] => 1
    [value] => 12
)