diff --git a/.gitignore b/.gitignore index 17c52938..190889d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ /php/tests/node_modules /vendor /phpunit.xml +composer.lock +composer.phar +node_modules + diff --git a/README.md b/README.md index 8a927d0c..d2d86645 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ ## PHP library for Plesk API-RPC -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/plesk/api-php-lib/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/plesk/api-php-lib/?branch=master) - PHP object-oriented library for Plesk API-RPC. ## Install Via Composer [Composer](https://getcomposer.org/) is a preferable way to install the library: -`composer require plesk/api-php-lib:@dev` +`composer require lucasmarin/api-php-lib:@dev-master` ## How to Run Unit Tests @@ -16,11 +14,11 @@ One the possible ways to become familiar with the library is to check the unit t To run the unit tests use the following command: -`REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password phpunit` +`REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password REMOTE_LOGIN=login phpunit` ## Using Grunt for Continuous Testing * Install Node.js * Install dependencies via `npm install` command -* Run `REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password grunt watch:test` +* Run `REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password REMOTE_LOGIN=user grunt watch:test` diff --git a/composer.json b/composer.json index bfe3ee03..66f8f005 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,17 @@ { - "name": "plesk/api-php-lib", - "description": "PHP object-oriented library for Plesk API-RPC", + "name": "lucasmarin/api-php-lib", + "description": "PHP object-oriented library for Plesk API-RPC. forked >> plesk/api-php-lib", "license": "Apache-2.0", "authors": [ { "name": "Alexei Yuzhakov", "email": "sibprogrammer@gmail.com" + }, + { + "name": "Lucas Stevanelli Marin", + "email": "lucasmarin@gmail.com" } + ], "minimum-stability": "dev", "require": { diff --git a/src/PleskX/Api/Client.php b/src/PleskX/Api/Client.php index 1b069a65..f0e91652 100644 --- a/src/PleskX/Api/Client.php +++ b/src/PleskX/Api/Client.php @@ -85,6 +85,51 @@ public function getPacket($version = null) return new SimpleXMLElement($content); } + + /** + * Recursive function that transforms array to XML + * + * @param array $attributes + * @param SimpleXMLElement $xmlData + * @return SimpleXMLElement + */ + protected function _createXml( $data, &$xmlData ) { + foreach ($data as $key => $value) { + if (is_array($value)) { + if (is_numeric($key)) { + $key = array_keys($data[$key])[0]; + $subnode = $xmlData->addChild($key); + foreach ($value[$key] as $k => $v) { + if (is_array($v)) { + $this->_createXml($v, $subnode); + } else { + $subnode->addChild("$k",htmlspecialchars("$v")); + } + } + } else { + $subnode = $xmlData->addChild($key); + $this->_createXml($value, $subnode); + } + } else { + $xmlData->addChild("$key",htmlspecialchars("$value")); + } + } + } + + /** + * Gen XML Request by Array + * + * @param array $attributes + * @param string|null $version + * @return SimpleXMLElement + */ + public function genRequestXml($attributes, $version = null) + { + $res = $this->getPacket($version); + $this->_createXml($attributes,$res); + return $res; + } + /** * Perform API request * @@ -646,4 +691,12 @@ public function wpInstance() return $this->_getOperator('WpInstance'); } + /** + * @return Operator\PHPHandler + */ + public function phpHandler() + { + return $this->_getOperator('PHPHandler'); + } + } diff --git a/src/PleskX/Api/Operator/Customer.php b/src/PleskX/Api/Operator/Customer.php index 1ee0b229..0924435b 100644 --- a/src/PleskX/Api/Operator/Customer.php +++ b/src/PleskX/Api/Operator/Customer.php @@ -42,14 +42,43 @@ public function delete($field, $value) * @param integer|string $value * @return Struct\GeneralInfo */ - public function get($field, $value) + public function get($field=null, $value=null) { $packet = $this->_client->getPacket(); $getTag = $packet->addChild('customer')->addChild('get'); - $getTag->addChild('filter')->addChild($field, $value); + $f = $getTag->addChild('filter'); + if ($field) $f->addChild($field, $value); $getTag->addChild('dataset')->addChild('gen_info'); - $response = $this->_client->request($packet); - return new Struct\GeneralInfo($response->data->gen_info); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'customer'}->get->result; + if ($field) + return new Struct\GeneralInfo($response); + else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + return $ret; + } + } + + /** + * @param string $field + * @param integer|string $value + * @return array[Struct\Domain] + */ + public function getDomainList($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('customer')->addChild('get-domain-list'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet)->domains->domain; + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\Domain($f); + } + return $ret; } } diff --git a/src/PleskX/Api/Operator/Database.php b/src/PleskX/Api/Operator/Database.php index 98c00472..a7877d0b 100644 --- a/src/PleskX/Api/Operator/Database.php +++ b/src/PleskX/Api/Operator/Database.php @@ -3,7 +3,134 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\Database as Struct; + class Database extends \PleskX\Api\Operator { + /** + * Create database + * + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['database' => ['add-db' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * Delete Database + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('database')->addChild('del-db')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get database + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfo|Array + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('database')->addChild('get-db'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'database'}->{'get-db'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } + + + /** + * Create database user + * + * @param array $properties + * @return Struct\InfoUser + */ + public function createUser($properties) + { + $properties = ['database' => ['add-db-user' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\InfoUser($response); + } + + /** + * Change database user + * + * @param integer $id The database user id + * @param array $properties + * @return Struct\InfoUser + */ + public function setUser($id, $properties) + { + $properties = ['database' => ['set-db-user' => array_merge(['id' => $id], $properties)]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + + /** + * Delete Database user + * @param string $field + * @param integer|string $value + * @return bool + */ + public function deleteUser($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('database')->addChild('del-db-user')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get database user + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfoUser|Array + */ + public function getUser($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('database')->addChild('get-db-users'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'database'}->{'get-db-users'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfoUser($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfoUser($f); + } + } + return $ret; + } + } diff --git a/src/PleskX/Api/Operator/DatabaseServer.php b/src/PleskX/Api/Operator/DatabaseServer.php index 70924b7a..a430ab2e 100644 --- a/src/PleskX/Api/Operator/DatabaseServer.php +++ b/src/PleskX/Api/Operator/DatabaseServer.php @@ -3,6 +3,8 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\DatabaseServer as Struct; + class DatabaseServer extends \PleskX\Api\Operator { @@ -17,4 +19,32 @@ public function getSupportedTypes() return (array)$response->type; } + + /** + * Get database + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfo|Array + */ + public function get($field = null, $value = null) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); + $filter = $getTag->addChild('filter'); + if ($field && $value) $filter->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{$this->_wrapperTag}->{'get'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } + } diff --git a/src/PleskX/Api/Operator/FtpUser.php b/src/PleskX/Api/Operator/FtpUser.php index 76f113c7..3307197d 100644 --- a/src/PleskX/Api/Operator/FtpUser.php +++ b/src/PleskX/Api/Operator/FtpUser.php @@ -3,7 +3,79 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\FtpUser as Struct; + class FtpUser extends \PleskX\Api\Operator { + + /** + * Create FTP account + * + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['ftp-user' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * Change FTP account + * + * @param string $field + * @param integer|string $value + * @param array $properties + * @return Struct\Info + */ + public function set($field, $value, $properties) + { + $properties = ['ftp-user' => ['set' => ['filter' => [ $field => $value ], 'values' => $properties ]]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('ftp-user')->addChild('del')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get FTP accounts + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfo|Array + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('ftp-user')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'ftp-user'}->get->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } + } diff --git a/src/PleskX/Api/Operator/PHPHandler.php b/src/PleskX/Api/Operator/PHPHandler.php new file mode 100644 index 00000000..bf402c63 --- /dev/null +++ b/src/PleskX/Api/Operator/PHPHandler.php @@ -0,0 +1,44 @@ +_client->getPacket(); + + $filter = $packet->addChild('php-handler')->addChild('get')->addChild('filter'); + if ($field) { + $filter->addChild($field, $value); + } + + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'php-handler'}->get->result; + + $ret = null; + if ($field == 'id' && isset($response->id)) { + $ret = new Struct\Info($response); + } else { + $ret = []; + foreach ($response as $f) { + if (isset($f->id)) { + $ret[] = new Struct\Info($f); + } + } + } + + return $ret; + } + +} diff --git a/src/PleskX/Api/Operator/ServicePlan.php b/src/PleskX/Api/Operator/ServicePlan.php index 37644cf1..2ebdbe97 100644 --- a/src/PleskX/Api/Operator/ServicePlan.php +++ b/src/PleskX/Api/Operator/ServicePlan.php @@ -3,7 +3,40 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\ServicePlan as Struct; + class ServicePlan extends \PleskX\Api\Operator { + /** + * @param string $field + * @param integer|string $value + * @return Struct\Data + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('service-plan')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; + return new Struct\Data($response); + } + + /** + * @return array [Struct\Data] + */ + public function getAll() + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('service-plan')->addChild('get'); + $getTag->addChild('filter'); + $getTag->addChild('owner-all'); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\Data($f); + } + return $ret; + } + } diff --git a/src/PleskX/Api/Operator/Site.php b/src/PleskX/Api/Operator/Site.php index 4b2a1bc6..e18c20a2 100644 --- a/src/PleskX/Api/Operator/Site.php +++ b/src/PleskX/Api/Operator/Site.php @@ -3,7 +3,80 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\Site as Struct; + class Site extends \PleskX\Api\Operator { + /** + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $getTag->addChild('dataset')->addChild('gen_info'); + $response = $this->_client->request($packet); + return new Struct\GeneralInfo($response->data->gen_info); + } + + /** + * Get Data of site + * + * @param string $field + * @param integer|string $value + * @return mixed Array|Struct\Data + */ + public function getData($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $dataset = $getTag->addChild('dataset'); + $dataset->addChild('gen_info'); + $dataset->addChild('hosting'); + $dataset->addChild('stat'); + $dataset->addChild('prefs'); + $dataset->addChild('disk_usage'); + $ret = NULL; + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'site'}->{'get'}->result; + if ( in_array($field,['id','name','guid']) && isset( $response->id ) ) { + $ret = new Struct\Data($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\Data($f); + } + } + return $ret; + } + + /** + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['site' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('site')->addChild('del')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + } diff --git a/src/PleskX/Api/Operator/SiteAlias.php b/src/PleskX/Api/Operator/SiteAlias.php index cb0ca391..4c05c179 100644 --- a/src/PleskX/Api/Operator/SiteAlias.php +++ b/src/PleskX/Api/Operator/SiteAlias.php @@ -3,7 +3,90 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\SiteAlias as Struct; + class SiteAlias extends \PleskX\Api\Operator { -} + /** + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site-alias')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $ret = NULL; + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'site-alias'}->{'get'}->result; + if ( in_array($field,['id','name']) && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } + + + /** + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['site-alias' => ['create' => $properties]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + + /** + * @param array $filter + * @param array $properties + * @return Struct\Info + */ + public function update($filter, $settings) + { + $properties = ['site-alias'=>['set'=>['filter'=>$filter,'settings'=>$settings]]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('site-alias')->addChild('delete')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + + /** + * @param string $filter + * @param string|integer $valueFilter + * @param string $newName + * @param integer|string $value + * @return bool + */ + public function rename($filter, $valueFilter, $newName) + { + $packet = $this->_client->getPacket(); + $operator = $packet->addChild('site-alias')->addChild('rename'); + $operator->addChild( $filter, $valueFilter ); + $operator->addChild( 'new_name', $newName ); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 2f8fe107..10307489 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -31,13 +31,8 @@ public function getPhysicalHostingDescriptor() */ public function create($properties) { - $packet = $this->_client->getPacket(); - $info = $packet->addChild('webspace')->addChild('add')->addChild('gen_setup'); - - foreach ($properties as $name => $value) { - $info->addChild($name, $value); - } - + $properties = ['webspace' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml($properties); $response = $this->_client->request($packet); return new Struct\Info($response); } @@ -55,7 +50,26 @@ public function delete($field, $value) return 'ok' === (string)$response->status; } + /** + * Change Webspace + * + * @param string $field + * @param integer|string $value + * @param array $properties + * @return Struct\Info + */ + public function set($field, $value, $properties) + { + $properties = ['webspace' => ['set' => ['filter' => [ $field => $value ], 'values' => $properties ]]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * Get gen_info of webspace [name,guid] + * * @param string $field * @param integer|string $value * @return Struct\GeneralInfo @@ -69,5 +83,62 @@ public function get($field, $value) $response = $this->_client->request($packet); return new Struct\GeneralInfo($response->data->gen_info); } + + /** + * Get Data of webspace + * + * @param string $field optional + * @param integer|string $value optional + * @return mixed Struct\Data|Array + */ + public function getData($field=null,$value=null) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('webspace')->addChild('get'); + $g = $getTag->addChild('filter'); + if ($field) $g->addChild($field, $value); + $dataset = $getTag->addChild('dataset'); + $dataset->addChild('gen_info'); + $dataset->addChild('hosting'); + $dataset->addChild('limits'); + $dataset->addChild('stat'); + $dataset->addChild('prefs'); + $dataset->addChild('disk_usage'); + $dataset->addChild('performance'); + $dataset->addChild('subscriptions'); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'webspace'}->{'get'}->result; + $ret = NULL; + if ( in_array($field,['id','name']) && isset( $response->id ) ) { + $ret = new Struct\Data($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\Data($f); + } + } + return $ret; + } + + /** + * Get Traffic of webspace + * + * @param string $field + * @param integer|string $value + * @param DateTime $sinceDate optional + * @param DateTime $toDate optional + * @return Struct\Data + */ + public function getTraffic($field, $value, $sinceDate = NULL, $toDate = NULL ) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('webspace')->addChild('get_traffic'); + $getTag->addChild('filter')->addChild($field, $value); + if ( $sinceDate ) $getTag->addChild('since_date', $sinceDate->format('Y-m-d')); + if ( $toDate ) $getTag->addChild('to_date', $toDate->format('Y-m-d')); + $response = $this->_client->request($packet); + return new Struct\Traffic($response->traffic); + } + } diff --git a/src/PleskX/Api/Struct.php b/src/PleskX/Api/Struct.php index 928d8fba..7a996302 100644 --- a/src/PleskX/Api/Struct.php +++ b/src/PleskX/Api/Struct.php @@ -20,18 +20,19 @@ public function __set($property, $value) */ protected function _initScalarProperties($apiResponse, array $properties) { + foreach ($properties as $property) { if (is_array($property)) { $classPropertyName = current($property); $value = $apiResponse->{key($property)}; } else { - $classPropertyName = $this->_underToCamel(str_replace('-', '_', $property)); + $classPropertyName = $this->_underToCamel($property); $value = $apiResponse->$property; } $reflectionProperty = new \ReflectionProperty($this, $classPropertyName); $docBlock = $reflectionProperty->getDocComment(); - $propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\1', $docBlock); + $propertyType = trim(preg_replace('/^.+ @var ([^\*]+) .+$/', '\1', $docBlock)); if ('string' == $propertyType) { $value = (string)$value; @@ -40,7 +41,9 @@ protected function _initScalarProperties($apiResponse, array $properties) } else if ('boolean' == $propertyType) { $value = in_array((string)$value, ['true', 'on', 'enabled']); } else { - throw new \Exception("Unknown property type '$propertyType'."); + if ( class_exists($propertyType) ) $value = new $propertyType($value); + else + throw new \Exception("Unknown property type '$propertyType'."); } $this->$classPropertyName = $value; @@ -53,9 +56,9 @@ protected function _initScalarProperties($apiResponse, array $properties) * @param string $under * @return string */ - private function _underToCamel($under) + protected function _underToCamel($under) { - $under = '_' . str_replace('_', ' ', strtolower($under)); + $under = '_' . str_replace(['_','-'], ' ', strtolower($under)); return ltrim(str_replace(' ', '', ucwords($under)), '_'); } diff --git a/src/PleskX/Api/Struct/Customer/Domain.php b/src/PleskX/Api/Struct/Customer/Domain.php new file mode 100644 index 00000000..41d9a53b --- /dev/null +++ b/src/PleskX/Api/Struct/Customer/Domain.php @@ -0,0 +1,50 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + ['ascii-name' => 'asciiName'], + 'type', + 'main', + 'guid', + ['external-id' => 'externalId'], + ['parent-id' => 'parentId'], + ['domain-id' => 'domainId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Customer/GeneralInfo.php b/src/PleskX/Api/Struct/Customer/GeneralInfo.php index 74a50b9d..cc1e553a 100644 --- a/src/PleskX/Api/Struct/Customer/GeneralInfo.php +++ b/src/PleskX/Api/Struct/Customer/GeneralInfo.php @@ -11,11 +11,15 @@ class GeneralInfo extends \PleskX\Api\Struct /** @var string */ public $login; + /** @var integer */ + public $id; + public function __construct($apiResponse) { - $this->_initScalarProperties($apiResponse, [ + $this->id = (integer) $apiResponse->id; + $this->_initScalarProperties($apiResponse->data->gen_info, [ ['pname' => 'personalName'], - 'login', + 'login' ]); } } \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/GeneralInfo.php b/src/PleskX/Api/Struct/Database/GeneralInfo.php new file mode 100644 index 00000000..43b1f61f --- /dev/null +++ b/src/PleskX/Api/Struct/Database/GeneralInfo.php @@ -0,0 +1,38 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'type', + ['webspace-id' => 'webspaceId'], + ['default-user-id' => 'defaultUserId'], + ['db-server-id' => 'dbServerId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/GeneralInfoUser.php b/src/PleskX/Api/Struct/Database/GeneralInfoUser.php new file mode 100644 index 00000000..eb13d0b8 --- /dev/null +++ b/src/PleskX/Api/Struct/Database/GeneralInfoUser.php @@ -0,0 +1,26 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'login', + ['db-id' => 'dbId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/Info.php b/src/PleskX/Api/Struct/Database/Info.php new file mode 100644 index 00000000..3b77f55d --- /dev/null +++ b/src/PleskX/Api/Struct/Database/Info.php @@ -0,0 +1,18 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/InfoUser.php b/src/PleskX/Api/Struct/Database/InfoUser.php new file mode 100644 index 00000000..c647718f --- /dev/null +++ b/src/PleskX/Api/Struct/Database/InfoUser.php @@ -0,0 +1,6 @@ +id = (integer) $apiResponse->id; + $this->_initScalarProperties($apiResponse->data, [ + 'host', + 'port', + 'type' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php b/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php new file mode 100644 index 00000000..7c7626c9 --- /dev/null +++ b/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php @@ -0,0 +1,34 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'home', + 'quota', + ['webspace-id' => 'webspaceId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/FtpUser/Info.php b/src/PleskX/Api/Struct/FtpUser/Info.php new file mode 100644 index 00000000..639b2e97 --- /dev/null +++ b/src/PleskX/Api/Struct/FtpUser/Info.php @@ -0,0 +1,18 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/PHPHandler/Info.php b/src/PleskX/Api/Struct/PHPHandler/Info.php new file mode 100644 index 00000000..4ddb6bf6 --- /dev/null +++ b/src/PleskX/Api/Struct/PHPHandler/Info.php @@ -0,0 +1,33 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'display-name', + 'full-version', + 'version', + 'type', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Server/Statistics/Version.php b/src/PleskX/Api/Struct/Server/Statistics/Version.php index d01e6b77..a446ddc9 100644 --- a/src/PleskX/Api/Struct/Server/Statistics/Version.php +++ b/src/PleskX/Api/Struct/Server/Statistics/Version.php @@ -12,11 +12,19 @@ class Version extends \PleskX\Api\Struct /** @var string */ public $version; + /** @var string */ + public $pleskOs; + + /** @var string */ + public $pleskOsVersion; + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ ['plesk_name' => 'internalName'], ['plesk_version' => 'version'], + ['plesk_os' => 'pleskOs'], + ['plesk_os_version' => 'pleskOsVersion'], ]); } } \ No newline at end of file diff --git a/src/PleskX/Api/Struct/ServicePlan/Data.php b/src/PleskX/Api/Struct/ServicePlan/Data.php new file mode 100644 index 00000000..a0cfdf7a --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Data.php @@ -0,0 +1,26 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'limits', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/ServicePlan/Info.php b/src/PleskX/Api/Struct/ServicePlan/Info.php new file mode 100644 index 00000000..e58e43cb --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Info.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/ServicePlan/Limits.php b/src/PleskX/Api/Struct/ServicePlan/Limits.php new file mode 100644 index 00000000..2a5b9748 --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Limits.php @@ -0,0 +1,34 @@ +_limitScalarProperties($apiResponse,['limit']); + } + + private function _limitScalarProperties($apiResponse, array $arrayElement) + { + foreach( $arrayElement as $el ) { + $this->{$el} = new \stdClass(); + } + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + if ( FALSE !== in_array($k, $arrayElement) ) { + $this->{$k}->{parent::_underToCamel($sxe->current()->name)} = $sxe->current()->value; + } else $this->{parent::_underToCamel($k)} = $sxe->current(); + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Data.php b/src/PleskX/Api/Struct/Site/Data.php new file mode 100644 index 00000000..b8bf08af --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Data.php @@ -0,0 +1,40 @@ +data; + $data->addChild('id',$apiResponse->id); + $this->_initScalarProperties($data, [ + 'id', + 'gen_info', + 'hosting', + 'stat', + 'prefs', + 'disk_usage', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/DiskUsage.php b/src/PleskX/Api/Struct/Site/DiskUsage.php new file mode 100644 index 00000000..88d6286d --- /dev/null +++ b/src/PleskX/Api/Struct/Site/DiskUsage.php @@ -0,0 +1,66 @@ +_initScalarProperties($apiResponse, [ + 'httpdocs', + 'httpsdocs', + 'subdomains', + 'web_users', + 'anonftp', + 'logs', + 'dbases', + 'mailboxes', + 'webapps', + 'maillists', + 'domaindumps', + 'configs', + 'chroot' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/GeneralInfo.php b/src/PleskX/Api/Struct/Site/GeneralInfo.php new file mode 100644 index 00000000..b0f3e62e --- /dev/null +++ b/src/PleskX/Api/Struct/Site/GeneralInfo.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'cr_date', + 'name', + ['ascii-name' => 'asciiName'], + 'status', + 'real_size', + ['owner-login' => 'ownerLogin'], + 'dns_ip_address', + 'htype', + 'guid', + ['vendor-guid' => 'vendorGuid'], + ['external-id' => 'externalId'], + ['sb-site-uuid' => 'sbSiteUuid'], + 'description', + ['admin-description' => 'adminDescription'] + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Hosting.php b/src/PleskX/Api/Struct/Site/Hosting.php new file mode 100644 index 00000000..5a5cc44e --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Hosting.php @@ -0,0 +1,36 @@ +_hostingScalarProperties($apiResponse, ['property']); + } + + private function _hostingScalarProperties($apiResponse, array $arrayElement) + { + $xml = $apiResponse->asXML(); + $sxe = new \SimpleXmlIterator($xml); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + $this->types[$k] = new \stdClass(); + if ( $sxe->hasChildren() ) { + foreach ($sxe->getChildren() as $element => $value) { + if ( FALSE !== in_array($element, $arrayElement) ) { + $this->types[$k]->{parent::_underToCamel($value->name)} = $value->value; + } else { + $this->types[$k]->{parent::_underToCamel($element)} = $value; + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Info.php b/src/PleskX/Api/Struct/Site/Info.php new file mode 100644 index 00000000..626eeb43 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Info.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'guid', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Preference.php b/src/PleskX/Api/Struct/Site/Preference.php new file mode 100644 index 00000000..0b3c5c27 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Preference.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'www', + 'stat_ttl', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Stat.php b/src/PleskX/Api/Struct/Site/Stat.php new file mode 100644 index 00000000..b2810038 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Stat.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'traffic', + 'subdom', + 'wu', + 'box', + 'redir', + 'mg', + 'resp', + 'maillists', + 'db', + 'mssql_db', + 'webapps', + 'traffic_prevday', + 'domains', + 'sites' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php new file mode 100644 index 00000000..ac8532b3 --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php @@ -0,0 +1,33 @@ +id = $apiResponse->id; + $this->_initScalarProperties($apiResponse->info, [ + ['pref' => 'preferences'], + ['site-id' => 'siteId'], + 'name', + ['ascii-name' => 'asciiName'] + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/Info.php b/src/PleskX/Api/Struct/SiteAlias/Info.php new file mode 100644 index 00000000..b64836c5 --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/Info.php @@ -0,0 +1,17 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/Preferences.php b/src/PleskX/Api/Struct/SiteAlias/Preferences.php new file mode 100644 index 00000000..ec9247c3 --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/Preferences.php @@ -0,0 +1,25 @@ +_initScalarProperties($apiResponse, [ + 'web', + 'tomcat', + 'seo-redirect', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php new file mode 100644 index 00000000..ceefdc7b --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -0,0 +1,52 @@ +data; + $data->addChild('id',$apiResponse->id); + $this->_initScalarProperties($data, [ + 'id', + 'gen_info', + 'hosting', + 'limits', + 'stat', + 'prefs', + 'disk_usage', + 'performance', + 'subscriptions' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/DiskUsage.php b/src/PleskX/Api/Struct/Webspace/DiskUsage.php new file mode 100644 index 00000000..82f7a80d --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/DiskUsage.php @@ -0,0 +1,66 @@ +_initScalarProperties($apiResponse, [ + 'httpdocs', + 'httpsdocs', + 'subdomains', + 'web_users', + 'anonftp', + 'logs', + 'dbases', + 'mailboxes', + 'webapps', + 'maillists', + 'domaindumps', + 'configs', + 'chroot' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php index 40e0a466..ce8fe00e 100644 --- a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php +++ b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php @@ -5,17 +5,65 @@ class GeneralInfo extends \PleskX\Api\Struct { - /** @var string */ + /** @var string */ + public $crDate; + + /** @var string */ public $name; - /** @var string */ + /** @var string */ + public $asciiName; + + /** @var string */ + public $status; + + /** @var integer */ + public $realSize; + + /** @var string */ + public $ownerLogin; + + /** @var string */ + public $dnsIpAddress; + + /** @var string */ + public $htype; + + /** @var string */ public $guid; + /** @var string */ + public $vendorGuid; + + /** @var string */ + public $externalId; + + /** @var string */ + public $sbSiteUuid; + + /** @var string */ + public $description; + + /** @var string */ + public $adminDescription; + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ + 'cr_date', 'name', + ['ascii-name' => 'asciiName'], + 'status', + 'real_size', + ['owner-login' => 'ownerLogin'], + 'dns_ip_address', + 'htype', 'guid', + ['vendor-guid' => 'vendorGuid'], + ['external-id' => 'externalId'], + ['sb-site-uuid' => 'sbSiteUuid'], + 'description', + ['admin-description' => 'adminDescription'] ]); } } \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Hosting.php b/src/PleskX/Api/Struct/Webspace/Hosting.php new file mode 100644 index 00000000..fe4fc64b --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Hosting.php @@ -0,0 +1,35 @@ +_hostingScalarProperties($apiResponse, ['property']); + } + + private function _hostingScalarProperties($apiResponse, array $arrayElement) + { + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + $this->types[$k] = new \stdClass(); + if ( $sxe->hasChildren() ) { + foreach ($sxe->getChildren() as $element => $value) { + if ( FALSE !== in_array($element, $arrayElement) ) { + $this->types[$k]->{parent::_underToCamel($value->name)} = $value->value; + } else { + $this->types[$k]->{parent::_underToCamel($element)} = $value; + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Limits.php b/src/PleskX/Api/Struct/Webspace/Limits.php new file mode 100644 index 00000000..da7ed927 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Limits.php @@ -0,0 +1,34 @@ +_limitScalarProperties($apiResponse,['limit']); + } + + private function _limitScalarProperties($apiResponse, array $arrayElement) + { + foreach( $arrayElement as $el ) { + $this->{$el} = new \stdClass(); + } + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + if ( FALSE !== in_array($k, $arrayElement) ) { + $this->{$k}->{parent::_underToCamel($sxe->current()->name)} = $sxe->current()->value; + } else $this->{parent::_underToCamel($k)} = $sxe->current(); + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Perfomance.php b/src/PleskX/Api/Struct/Webspace/Perfomance.php new file mode 100644 index 00000000..f4ffb3b9 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Perfomance.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'bandwidth', + 'max_connections', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Plan.php b/src/PleskX/Api/Struct/Webspace/Plan.php new file mode 100644 index 00000000..bff313ed --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Plan.php @@ -0,0 +1,14 @@ +_initScalarProperties($apiResponse, [ + 'www', + 'stat_ttl', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Stat.php b/src/PleskX/Api/Struct/Webspace/Stat.php new file mode 100644 index 00000000..6dda0386 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Stat.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'traffic', + 'subdom', + 'wu', + 'box', + 'redir', + 'mg', + 'resp', + 'maillists', + 'db', + 'mssql_db', + 'webapps', + 'traffic_prevday', + 'domains', + 'sites' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Subscription.php b/src/PleskX/Api/Struct/Webspace/Subscription.php new file mode 100644 index 00000000..764b0b2b --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Subscription.php @@ -0,0 +1,24 @@ +locked = $apiResponse->locked; + $this->synchronized = $apiResponse->synchronized; + $this->plan = new Plan(); + $this->plan->planGuid = $apiResponse->plan->{'plan-guid'}; + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Subscriptions.php b/src/PleskX/Api/Struct/Webspace/Subscriptions.php new file mode 100644 index 00000000..dd5e9b38 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Subscriptions.php @@ -0,0 +1,18 @@ +data = []; + foreach ($apiResponse->subscription as $sb) { + $this->data[] = new Subscription($sb); + } + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Traffic.php b/src/PleskX/Api/Struct/Webspace/Traffic.php new file mode 100644 index 00000000..3018e5ec --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Traffic.php @@ -0,0 +1,52 @@ +_trafficScalarProperties($apiResponse); + } + + /** + * Initialize list of scalar properties of traffic response + * + * @param \SimpleXMLElement $apiResponse + * @throws \Exception + */ + protected function _trafficScalarProperties( $apiResponse ) { + + $first = $apiResponse->xpath('//traffic'); + if ( ! $first ) return; + + $this->sinceDate = $first[0]->date; + $this->toDate = $apiResponse->xpath('//traffic[last()]')[0]->date; + foreach( $apiResponse as $i => $traffic ) { + $this->httpIn += $traffic->http_in; + $this->httpOut += $traffic->http_out; + $this->ftpIn += $traffic->ftp_in; + $this->ftpOut += $traffic->ftp_out; + } + } + +} diff --git a/src/PleskX/Api/StructData.php b/src/PleskX/Api/StructData.php new file mode 100644 index 00000000..1a6a83e9 --- /dev/null +++ b/src/PleskX/Api/StructData.php @@ -0,0 +1,49 @@ +{key($property)}; + } else { + $classPropertyName = $this->_underToCamel(str_replace('-', '_', $property)); + $value = $apiResponse->$property; + } + + $reflectionProperty = new \ReflectionProperty($this, $classPropertyName); + $docBlock = $reflectionProperty->getDocComment(); + $propertyType = trim(preg_replace('/^.+ @var ([^\*]+) .+$/', '\1', $docBlock)); + + if ('string' == $propertyType) { + $value = (string)$value; + } else if ('integer' == $propertyType) { + $value = (int)$value; + } else if ('boolean' == $propertyType) { + $value = in_array((string)$value, ['true', 'on', 'enabled']); + } else { + if ( class_exists($propertyType) ) { + $value = new $property($value); + } + throw new \Exception("Unknown property type '$propertyType'."); + } + + $this->$classPropertyName = $value; + } + } + + +} \ No newline at end of file diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 8d4a3bc2..4c04d07f 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -32,8 +32,21 @@ public function testGet() $customerInfo = $this->_client->customer()->get('id', $customer->id); $this->assertEquals('John Smith', $customerInfo->personalName); $this->assertEquals('john-unit-test', $customerInfo->login); + $this->assertEquals($customer->id, $customerInfo->id); $this->_client->customer()->delete('id', $customer->id); } + public function testGetDomainList() + { + $domainList = $this->_client->customer()->getDomainList('login', 1); + $this->assertGreaterThan(0, $domainList[0]->id); + } + + public function testGetAll() + { + $customerList = $this->_client->customer()->get(); + $this->assertGreaterThan(0, $customerList[0]->id); + } + } diff --git a/tests/DatabaseServerTest.php b/tests/DatabaseServerTest.php index 855f6102..c0dfaf3e 100644 --- a/tests/DatabaseServerTest.php +++ b/tests/DatabaseServerTest.php @@ -11,4 +11,11 @@ public function testGetSupportedTypes() $this->assertContains('mysql', $types); } + + public function testGet() + { + $servers = $this->_client->databaseServer()->get(); + $this->assertGreaterThan(0, $servers[0]->id); + } + } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php new file mode 100644 index 00000000..6682e21c --- /dev/null +++ b/tests/DatabaseTest.php @@ -0,0 +1,143 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'passwordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + + private function _createDatabase( $webspace, $name = 'newdatabase' ) + { + return $this->_client->database()->create([ + 'webspace-id' => $webspace->id, + 'name' => $name, + 'type' => 'mysql' + ]); + } + + private function _createUser( $database, $login = 'newuserdatabase' ) + { + return $this->_client->database()->createUser([ + 'db-id' => $database->id, + 'login' => $login, + 'password' => 'dbpassword' + ]); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $this->assertGreaterThan(0, $database->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $result = $this->_client->database()->delete('id', $database->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $databaseInfo = $this->_client->database()->get('id', $database->id); + $this->assertGreaterThan(0, $databaseInfo->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGetAllWebspace() + { + $webspace = $this->_createWebspace(); + $database1 = $this->_createDatabase( $webspace ); + $database2 = $this->_createDatabase( $webspace, 'database2' ); + + $databaseInfo = $this->_client->database()->get('webspace-id', $webspace->id); + $this->assertGreaterThan(0, $databaseInfo[0]->id); + $this->assertGreaterThan(0, $databaseInfo[1]->id); + + $this->_client->database()->delete('id', $database1->id); + $this->_client->database()->delete('id', $database2->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testCreateUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $this->assertGreaterThan(0, $user->id); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testSetUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $result = $this->_client->database()->setUser($user->id,['password'=>'daskljaskljdaskladj']); + $this->assertTrue($result); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDeleteUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $result = $this->_client->database()->deleteUser('id', $user->id); + $this->assertTrue($result); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGetUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $userInfo = $this->_client->database()->getUser('id', $user->id); + $this->assertGreaterThan(0, $userInfo->id); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + +} \ No newline at end of file diff --git a/tests/FtpUserTest.php b/tests/FtpUserTest.php new file mode 100644 index 00000000..112acfec --- /dev/null +++ b/tests/FtpUserTest.php @@ -0,0 +1,104 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'passwordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + + private function _createFtpUser( $webspace, $name = 'newftpuser' ) + { + return $this->_client->ftpUser()->create([ + 'name' => $name, + 'password' => 'userpassword', + 'home' => '', + 'webspace-id' => $webspace->id + ]); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $this->assertGreaterThan(0, $ftpuser->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testSet() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $result = $this->_client->ftpuser()->set('id', $ftpuser->id, ['password' => 'kjklasdjlkaj']); + $this->assertGreaterThan(0, $result->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $result = $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $ftpUserInfo = $this->_client->ftpUser()->get('id', $ftpuser->id); + $this->assertGreaterThan(0, $ftpUserInfo->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGetAllWebspace() + { + $webspace = $this->_createWebspace(); + $ftpuser1 = $this->_createFtpUser( $webspace ); + $ftpuser2 = $this->_createFtpUser( $webspace, 'ftpuser22' ); + + $ftpUserInfo = $this->_client->ftpUser()->get('webspace-id', $webspace->id); + $this->assertGreaterThan(0, $ftpUserInfo[0]->id); + $this->assertGreaterThan(0, $ftpUserInfo[1]->id); + + $this->_client->ftpuser()->delete('id', $ftpuser1->id); + $this->_client->ftpuser()->delete('id', $ftpuser2->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + +} \ No newline at end of file diff --git a/tests/PHPHandlerTest.php b/tests/PHPHandlerTest.php new file mode 100644 index 00000000..a56003a0 --- /dev/null +++ b/tests/PHPHandlerTest.php @@ -0,0 +1,13 @@ +_client->phpHandler()->get('id', 'cgi'); + $this->assertEquals('cgi', $get->id); + } + +} \ No newline at end of file diff --git a/tests/ServicePlanTest.php b/tests/ServicePlanTest.php new file mode 100644 index 00000000..4afd3230 --- /dev/null +++ b/tests/ServicePlanTest.php @@ -0,0 +1,60 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + $servicePlan = $this->_client->servicePlan()->get('guid', $webspaceInfo->subscriptions->data[0]->plan->planGuid); + $this->assertGreaterThan(0, $servicePlan->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGetAll() + { + $servicePlan = $this->_client->servicePlan()->getAll(); + $this->assertGreaterThan(0, $servicePlan[0]->id); + } + +} \ No newline at end of file diff --git a/tests/SiteAliasTest.php b/tests/SiteAliasTest.php new file mode 100644 index 00000000..ae1ad44c --- /dev/null +++ b/tests/SiteAliasTest.php @@ -0,0 +1,107 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + /** + * @return \PleskX\Api\Struct\SiteAlias\Info + */ + private function _createSiteAlias($webspace) + { + return $this->_client->siteAlias()->create([ + 'site-id' => $webspace->id, + 'name' => $this->aliasName + ]); + } + + // public function testGet() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + // $this->assertEquals($this->aliasName, $siteAlias->name); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + public function testGetSearchBySiteName() + { + $webspace = $this->_createWebspace(); + $siteAlias = $this->_createSiteAlias($webspace); + $siteAlias = $this->_client->siteAlias()->get('site-id', $webspace->id); + $this->assertEquals($this->aliasName, $siteAlias[0]->name); + $this->_client->siteAlias()->delete('id', $siteAlias[0]->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + + // public function testCreate() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $this->assertInternalType('integer', $siteAlias->id); + // $this->assertGreaterThan(0, $siteAlias->id); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $result = $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->assertTrue($result); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testRename() { + + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $result = $this->_client->siteAlias()->rename('id', $siteAlias->id, $this->aliasNewName); + // $this->assertTrue($result); + // $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + // $this->assertEquals($this->aliasNewName, $siteAlias->name); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + +} diff --git a/tests/SiteTest.php b/tests/SiteTest.php new file mode 100644 index 00000000..e5392beb --- /dev/null +++ b/tests/SiteTest.php @@ -0,0 +1,108 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + /** + * @return \PleskX\Api\Struct\Webspace\Info + */ + private function _createSite($webspace) + { + return $this->_client->site()->create([ + 'gen_setup' => [ + 'name' => $this->siteName, + 'webspace-id' => $webspace->id + ], + ]); + } + + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $this->assertInternalType('integer', $site->id); + // $this->assertGreaterThan(0, $site->id); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $result = $this->_client->site()->delete('id', $site->id); + // $this->assertTrue($result); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $siteInfo = $this->_client->site()->get('id', $site->id); + // $this->assertEquals($this->siteName, $siteInfo->name); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + public function testData() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $siteInfo = $this->_client->site()->getData('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->genInfo->name); + $this->assertEquals($site->id, $siteInfo->id); + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + // public function testDataSearchBySpace() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $siteInfo = $this->_client->site()->getData('parent-id', $webspace->id); + // $this->assertEquals($this->siteName, $siteInfo[0]->genInfo->name); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + +} diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index f3f55a03..ceec7785 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -4,19 +4,46 @@ class WebspaceTest extends TestCase { + private $webspaceSiteName = 'example-test-parent.dom'; + private $siteName = 'example-test-child.dom'; + private $trafficTestSite = 'worksecurity.net'; //SITE HOSTED BY MY PLESK + /** + * + * * @return \PleskX\Api\Struct\Webspace\Info */ private function _createWebspace() { + $ips = $this->_client->ip()->get(); $ipInfo = reset($ips); + return $this->_client->webspace()->create([ - 'name' => 'example-test.dom', - 'ip_address' => $ipInfo->ipAddress, + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' ]); + } + public function testGetPermissionDescriptor() { $descriptor = $this->_client->webspace()->getPermissionDescriptor(); @@ -62,9 +89,53 @@ public function testGet() { $webspace = $this->_createWebspace(); $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals('example-test.dom', $webspaceInfo->name); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + $this->_client->webspace()->delete('id', $webspace->id); + } + public function testSet() + { + $webspace = $this->_createWebspace(); + $result = $this->_client->webspace()->set('id', $webspace->id, [ 'hosting' => ['vrt_hst' => [ 'property' => [ 'name' => 'ftp_password', 'value' => 'kjklasdjlkaj']]]]); + $this->assertGreaterThan(0, $result->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testData() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); $this->_client->webspace()->delete('id', $webspace->id); } + public function testDataAll() + { + $webspaceInfo = $this->_client->webspace()->getData(); + $this->assertGreaterThan(0, $webspaceInfo[0]->id); + } + + public function testGetTrafficThisMonth() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of this month')) + ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } + + public function testGetTrafficLastMonth() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of previous month')), + new DateTime('@'.strtotime('last day of previous month'))) + ; + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } + + public function testGetTraffic() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } + }