|
3 | 3 |
|
4 | 4 | namespace PleskX\Api\Operator; |
5 | 5 |
|
| 6 | +use PleskX\Api\Struct\ProtectedDirectory as Struct; |
| 7 | + |
6 | 8 | class ProtectedDirectory extends \PleskX\Api\Operator |
7 | 9 | { |
8 | 10 |
|
9 | 11 | protected $_wrapperTag = 'protected-dir'; |
10 | 12 |
|
| 13 | + /** |
| 14 | + * @param string $name |
| 15 | + * @param integer $siteId |
| 16 | + * @param string $header |
| 17 | + * @return Struct\Info |
| 18 | + */ |
| 19 | + public function add($name, $siteId, $header = '') |
| 20 | + { |
| 21 | + $packet = $this->_client->getPacket(); |
| 22 | + $info = $packet->addChild($this->_wrapperTag)->addChild('add'); |
| 23 | + |
| 24 | + $info->addChild('site-id', $siteId); |
| 25 | + $info->addChild('name', $name); |
| 26 | + $info->addChild('header', $header); |
| 27 | + |
| 28 | + return new Struct\Info($this->_client->request($packet)); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @param string $field |
| 33 | + * @param integer|string $value |
| 34 | + * @return bool |
| 35 | + */ |
| 36 | + public function delete($field, $value) |
| 37 | + { |
| 38 | + return $this->_delete($field, $value, 'delete'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @param string $field |
| 43 | + * @param integer|string $value |
| 44 | + * @return Struct\DataInfo|false |
| 45 | + */ |
| 46 | + public function get($field, $value) |
| 47 | + { |
| 48 | + $items = $this->getAll($field, $value); |
| 49 | + return reset($items); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @param string $field |
| 54 | + * @param integer|string $value |
| 55 | + * @return Struct\DataInfo[] |
| 56 | + */ |
| 57 | + public function getAll($field, $value) |
| 58 | + { |
| 59 | + $response = $this->_get('get', $field, $value); |
| 60 | + $items = []; |
| 61 | + foreach ($response->xpath('//result/data') as $xmlResult) { |
| 62 | + $items[] = new Struct\DataInfo($xmlResult); |
| 63 | + } |
| 64 | + return $items; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @param Struct\Info $protectedDirectory |
| 69 | + * @param string $login |
| 70 | + * @param string $password |
| 71 | + * @return Struct\UserInfo |
| 72 | + */ |
| 73 | + public function addUser($protectedDirectory, $login, $password) |
| 74 | + { |
| 75 | + $packet = $this->_client->getPacket(); |
| 76 | + $info = $packet->addChild($this->_wrapperTag)->addChild('add-user'); |
| 77 | + |
| 78 | + $info->addChild('pd-id', $protectedDirectory->id); |
| 79 | + $info->addChild('login', $login); |
| 80 | + $info->addChild('password', $password); |
| 81 | + |
| 82 | + return new Struct\UserInfo($this->_client->request($packet)); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @param string $field |
| 87 | + * @param integer|string $value |
| 88 | + * @return bool |
| 89 | + */ |
| 90 | + public function deleteUser($field, $value) |
| 91 | + { |
| 92 | + return $this->_delete($field, $value, 'delete-user'); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @param $command |
| 97 | + * @param $field |
| 98 | + * @param $value |
| 99 | + * @return \PleskX\Api\XmlResponse |
| 100 | + */ |
| 101 | + private function _get($command, $field, $value) |
| 102 | + { |
| 103 | + $packet = $this->_client->getPacket(); |
| 104 | + $getTag = $packet->addChild($this->_wrapperTag)->addChild($command); |
| 105 | + |
| 106 | + $filterTag = $getTag->addChild('filter'); |
| 107 | + if (!is_null($field)) { |
| 108 | + $filterTag->addChild($field, $value); |
| 109 | + } |
| 110 | + |
| 111 | + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
| 112 | + return $response; |
| 113 | + } |
| 114 | + |
11 | 115 | } |
0 commit comments