diegosouza /
laravel-zimbra
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DiegoSouza\Zimbra; |
||
| 4 | |||
| 5 | use Illuminate\Log\LogManager; |
||
| 6 | use Illuminate\Support\Traits\ForwardsCalls; |
||
| 7 | use Zimbra\Admin\AdminFactory; |
||
| 8 | use Zimbra\Admin\Struct\DistributionListSelector; |
||
| 9 | use Zimbra\Admin\Struct\DomainSelector; |
||
| 10 | use Zimbra\Enum\AccountBy; |
||
| 11 | use Zimbra\Enum\DistributionListBy; |
||
| 12 | use Zimbra\Enum\DomainBy; |
||
| 13 | use Zimbra\Struct\AccountSelector; |
||
| 14 | use Zimbra\Struct\KeyValuePair; |
||
| 15 | |||
| 16 | class ZimbraApiClient |
||
| 17 | { |
||
| 18 | use ForwardsCalls; |
||
| 19 | |||
| 20 | protected $api; |
||
| 21 | protected $logger; |
||
| 22 | protected $domain; |
||
| 23 | |||
| 24 | public function __construct($host, $emailDomain, $user, $password, LogManager $logger) |
||
| 25 | { |
||
| 26 | $this->api = AdminFactory::instance("https://{$host}:7071/service/admin/soap"); |
||
| 27 | $this->api->auth($user, $password); |
||
| 28 | |||
| 29 | $this->domain = $emailDomain; |
||
| 30 | $this->logger = $logger; |
||
| 31 | |||
| 32 | $this->api->getClient()->on('before.request', function ($request) { |
||
|
0 ignored issues
–
show
|
|||
| 33 | $this->logger->debug("SOAP REQUEST: {$request}"); |
||
| 34 | }); |
||
| 35 | |||
| 36 | $this->api->getClient()->on('after.request', function ($response) { |
||
| 37 | $this->logger->debug("SOAP RESPONSE: {$response}"); |
||
| 38 | }); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function createDistributionList($name) |
||
| 42 | { |
||
| 43 | $dynamic = false; |
||
| 44 | $attr = $this->createKeyPair(); |
||
| 45 | |||
| 46 | return $this->api->createDistributionList("{$name}@{$this->domain}", $dynamic, [$attr]); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function deleteDistributionList($id) |
||
| 50 | { |
||
| 51 | return $this->api->deleteDistributionList($id); |
||
| 52 | } |
||
| 53 | |||
| 54 | public function getAllDistributionLists() |
||
| 55 | { |
||
| 56 | $domainSelector = new DomainSelector(DomainBy::NAME(), $this->domain); |
||
| 57 | return $this->api->getAllDistributionLists($domainSelector); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function addDistributionListMember($listId, array $users) |
||
| 61 | { |
||
| 62 | return $this->api->addDistributionListMember($listId, $users); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function getDistributionListById($id) |
||
| 66 | { |
||
| 67 | $limit = 0; |
||
| 68 | $offset = 0; |
||
| 69 | $sortAscending = true; |
||
| 70 | $attr = $this->createKeyPair(); |
||
| 71 | |||
| 72 | $dl = new DistributionListSelector(DistributionListBy::ID(), $id); |
||
| 73 | |||
| 74 | return $this->api->getDistributionList($dl, $limit, $offset, $sortAscending, [$attr]); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function getDistributionListByName($name) |
||
| 78 | { |
||
| 79 | $limit = 0; |
||
| 80 | $offset = 0; |
||
| 81 | $sortAscending = true; |
||
| 82 | $attr = $this->createKeyPair(); |
||
| 83 | |||
| 84 | $dl = new DistributionListSelector(DistributionListBy::NAME(), $name); |
||
| 85 | |||
| 86 | return $this->api->getDistributionList($dl, $limit, $offset, $sortAscending, [$attr]); |
||
| 87 | } |
||
| 88 | |||
| 89 | public function getDistributionListMembership($distListName) |
||
| 90 | { |
||
| 91 | $limit = 0; |
||
| 92 | $offset = 0; |
||
| 93 | |||
| 94 | $dl = new DistributionListSelector(DistributionListBy::Name(), $distListName); |
||
| 95 | |||
| 96 | return $this->api->getDistributionListMembership($dl, $limit, $offset); |
||
| 97 | } |
||
| 98 | |||
| 99 | public function getAllAccounts() { |
||
| 100 | $serverSelector = null; |
||
| 101 | $domainSelector = new DomainSelector(DomainBy::NAME(), $this->domain); |
||
| 102 | |||
| 103 | return $this->api->getAllAccounts($serverSelector, $domainSelector); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function modifyCoS($accountId, $cosId) |
||
| 107 | { |
||
| 108 | $attr = $this->createKeyPair('zimbraCOSId', $cosId); |
||
| 109 | return $this->api->modifyAccount($accountId, [$attr]); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function removeDistributionListMember($listId, $member) |
||
| 113 | { |
||
| 114 | $dlms = [$member]; |
||
| 115 | $accounts = []; |
||
| 116 | |||
| 117 | return $this->api->removeDistributionListMember($listId, $dlms, $accounts); |
||
| 118 | } |
||
| 119 | |||
| 120 | public function renameDistributionList($listId, $newName) |
||
| 121 | { |
||
| 122 | return $this->api->renameDistributionList($listId, $newName); |
||
| 123 | } |
||
| 124 | |||
| 125 | public function getAccountById($id) |
||
| 126 | { |
||
| 127 | $apllyCos = null; |
||
| 128 | |||
| 129 | $attr = [ |
||
| 130 | 'sn', |
||
| 131 | 'uid', |
||
| 132 | 'mail', |
||
| 133 | 'givenName', |
||
| 134 | 'zimbraMailQuota', |
||
| 135 | 'zimbraAccountStatus', |
||
| 136 | ]; |
||
| 137 | |||
| 138 | $account = new AccountSelector(AccountBy::ID(), $id); |
||
| 139 | |||
| 140 | return $this->api->getAccount($account, $apllyCos, $attr)->account; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getAccountByName($name) |
||
| 144 | { |
||
| 145 | $apllyCos = null; |
||
| 146 | |||
| 147 | $attr = [ |
||
| 148 | 'sn', |
||
| 149 | 'uid', |
||
| 150 | 'mail', |
||
| 151 | 'givenName', |
||
| 152 | 'zimbraMailQuota', |
||
| 153 | 'zimbraAccountStatus', |
||
| 154 | ]; |
||
| 155 | |||
| 156 | $account = new AccountSelector(AccountBy::NAME(), $name); |
||
| 157 | |||
| 158 | return $this->api->getAccount($account, $apllyCos, $attr)->account; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getAccountMembershipByName($name) |
||
| 162 | { |
||
| 163 | $account = new AccountSelector(AccountBy::NAME(), $name); |
||
| 164 | return $this->api->getAccountMembership($account); |
||
| 165 | } |
||
| 166 | |||
| 167 | public function getAccountMembershipbyId($id) |
||
| 168 | { |
||
| 169 | $account = new AccountSelector(AccountBy::ID(), $id); |
||
| 170 | return $this->api->getAccountMembership($account); |
||
| 171 | } |
||
| 172 | |||
| 173 | public function getAccountInfoById($id) |
||
| 174 | { |
||
| 175 | $account = new AccountSelector(AccountBy::ID(), $id); |
||
| 176 | return $this->api->getAccountInfo($account); |
||
| 177 | } |
||
| 178 | |||
| 179 | public function getAccountInfoByName($name) |
||
| 180 | { |
||
| 181 | $account = new AccountSelector(AccountBy::NAME(), $name); |
||
| 182 | return $this->api->getAccountInfo($account); |
||
| 183 | } |
||
| 184 | |||
| 185 | public function getAllCos() |
||
| 186 | { |
||
| 187 | return $this->api->getAllCos()->cos; |
||
| 188 | } |
||
| 189 | |||
| 190 | public function getAllDomains() |
||
| 191 | { |
||
| 192 | return $this->api->getAllDomains()->domain; |
||
| 193 | } |
||
| 194 | |||
| 195 | public function api() |
||
| 196 | { |
||
| 197 | return $this->api; |
||
| 198 | } |
||
| 199 | |||
| 200 | public function __call($method, $parameters) |
||
| 201 | { |
||
| 202 | return $this->forwardCallTo($this->api, $method, $parameters); |
||
| 203 | } |
||
| 204 | |||
| 205 | private function createKeyPair($key = '', $value = '') |
||
| 206 | { |
||
| 207 | return new KeyValuePair($key, $value); |
||
| 208 | } |
||
| 209 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.