Domain.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Actions;
  3. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\AbstractAction;
  4. use SoapFault;
  5. use SoapParam;
  6. use SoapVar;
  7. /**
  8. *
  9. * Created by PhpStorm.
  10. * User: ThurData
  11. * Date: 28.08.19
  12. * Time: 13:46
  13. * Class Domain
  14. */
  15. class Domain extends AbstractAction
  16. {
  17. /**
  18. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  19. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain|\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  20. */
  21. public function create(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  22. {
  23. $params = array(
  24. new SoapParam($domain->getName(), "name"),
  25. );
  26. foreach ($domain->getAttrs() as $key => $value)
  27. {
  28. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  29. }
  30. $result = $this->connection->request("CreateDomainRequest", $params);
  31. $this->setLastResult($result);
  32. /**
  33. * check data has been returned or return false
  34. */
  35. if($data = $result->getResponseBody()['CREATEDOMAINRESPONSE']['DOMAIN'])
  36. {
  37. $domain->fill($data);
  38. return $domain;
  39. }
  40. $this->setError($result->getLastError());
  41. return false;
  42. }
  43. /**
  44. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  45. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  46. */
  47. public function update(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  48. {
  49. $params = array(
  50. new SoapParam($domain->getId(), "id"),
  51. );
  52. foreach ($domain->getAttrs() as $key => $value)
  53. {
  54. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  55. }
  56. $result = $this->connection->request("ModifyDomainRequest", $params);
  57. $this->setLastResult($result);
  58. if($data = $result->getResponseBody()['MODIFYDOMAINRESPONSE']['DOMAIN'])
  59. {
  60. $domain->fill($data);
  61. return $domain;
  62. }
  63. $this->setError($result->getLastError());
  64. return false;
  65. }
  66. /**
  67. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  68. * @return bool
  69. */
  70. public function delete(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  71. {
  72. $params = array(
  73. new SoapParam($domain->getId(), "id"),
  74. );
  75. $result = $this->connection->cleanResponse()->request("DeleteDomainRequest", $params);
  76. $this->setLastResult($result);
  77. if($result->getResponseBody()['DELETEDOMAINRESPONSE'])
  78. {
  79. return true;
  80. }
  81. $this->setError($result->getLastError());
  82. return false;
  83. }
  84. /**
  85. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  86. */
  87. public function getAll()
  88. {
  89. $result = $this->connection->request("GetAllDomainsRequest", []);
  90. return $result;
  91. }
  92. /**
  93. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  94. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  95. */
  96. function getDomainId(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  97. {
  98. $params = array(
  99. new SoapVar('<ns1:domain by="name">' . $domain->getName() . '</ns1:domain>', XSD_ANYXML),
  100. );
  101. $result = $this->connection->cleanResponse()->request("GetDomainInfoRequest", $params);
  102. $this->setLastResult($result);
  103. return $result;
  104. }
  105. /**
  106. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  107. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  108. */
  109. function getDomain(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  110. {
  111. $params = array(
  112. new SoapVar('<ns1:domain by="name">' . $domain->getName() . '</ns1:domain>', XSD_ANYXML),
  113. );
  114. $result = $this->connection->cleanResponse()->request("GetDomainRequest", $params);
  115. $this->setLastResult($result);
  116. return $result;
  117. }
  118. /**
  119. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  120. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response
  121. */
  122. public function getDomainUsages(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain)
  123. {
  124. $params = array(
  125. new SoapVar('<ns1:GetQuotaUsageRequest />', XSD_ANYXML),
  126. new SoapParam($domain->getName(), 'domain'),
  127. new SoapParam("1", 'refresh')
  128. );
  129. $result = $this->connection->request("GetQuotaUsageRequest", $params);
  130. $this->setLastResult($result);
  131. return $result;
  132. }
  133. }