Client.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap;
  3. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Interfaces\ClientInterface;
  4. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\Account;
  5. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\ClassOfServices;
  6. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\Server;
  7. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\DistributionList;
  8. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\Domain;
  9. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions\User;
  10. use ModulesGarden\Servers\ZimbraEmail\App\Traits\StorageTrait;
  11. use MySoapClient;
  12. use SoapFault;
  13. use SoapHeader;
  14. use SoapParam;
  15. use SoapVar;
  16. /**
  17. *
  18. * Created by PhpStorm.
  19. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  20. * Date: 27.08.19
  21. * Time: 15:39
  22. * Class SoapClient
  23. * @property Account $account
  24. * @property DistributionList $distributionList
  25. * @property Domain $domain
  26. * @property User $user
  27. * @property ClassOfServices $classOfServices
  28. * @property Server $server
  29. * @property Connection $connection
  30. *
  31. */
  32. class Client implements ClientInterface
  33. {
  34. use StorageTrait;
  35. /**
  36. * @var Connection
  37. */
  38. protected $connection;
  39. /**
  40. * @var Repository
  41. */
  42. protected $repository;
  43. /**
  44. * @var Services
  45. */
  46. protected $service;
  47. /**
  48. * Client constructor.
  49. * @param $server
  50. * @param int $port
  51. * @param $username
  52. * @param $password
  53. * @param string $user
  54. * @throws SoapFault
  55. */
  56. public function __construct($server, $port = 7071, $username, $password, $user = "admin")
  57. {
  58. $this->connection = new Connection($server, $port, $username, $password, $user);
  59. $this->connection->login();
  60. }
  61. /**
  62. * @param $conection
  63. */
  64. public function setConnection($conection)
  65. {
  66. $this->connection = $conection;
  67. }
  68. /**
  69. * @return Connection
  70. */
  71. public function getConnection()
  72. {
  73. return $this->connection;
  74. }
  75. /**
  76. *
  77. * return repository manager
  78. * @return Repository
  79. */
  80. public function repository()
  81. {
  82. if(!$this->repository)
  83. {
  84. $this->repository = new Repository($this);
  85. }
  86. return $this->repository;
  87. }
  88. /**
  89. * @return Services
  90. */
  91. public function service()
  92. {
  93. if(!$this->service)
  94. {
  95. $this->service = new Services($this);
  96. }
  97. return $this->service;
  98. }
  99. /**
  100. * @param $name
  101. * @return mixed
  102. * @throws \Exception
  103. */
  104. public function __get($name)
  105. {
  106. if(!$this->getStorage()->exists(strtolower($name)))
  107. {
  108. $class = '\\ModulesGarden\\Servers\\ZimbraEmail\\App\\Libs\\Zimbra\\Components\\Api\\Soap\\Actions\\'.ucfirst($name);
  109. if(!class_exists($class))
  110. {
  111. throw new \Exception('Action class '.$class.' does not exists');
  112. }
  113. $action = new $class($this->connection);
  114. $this->getStorage()->set(strtolower($name), $action);
  115. }else{
  116. $action = $this->getStorage()->get(strtolower($name));
  117. }
  118. return $action;
  119. }
  120. }