From 03cdac78cce3a807e2d22da2723b556f8dce3e49 Mon Sep 17 00:00:00 2001 From: Thomas Dutrion Date: Sat, 15 Aug 2015 09:59:14 +0100 Subject: [PATCH 1/4] [CS] PSR-2 compliance: breaks compatibility (snake case => camel case) --- .gitignore | 3 +- composer.json | 44 +- src/Api.php | 462 +++++++------ src/User/User.php | 260 ++++---- src/Zone/Cache/Cache.php | 75 ++- src/Zone/CustomPages/CustomPages.php | 84 ++- src/Zone/Dns/Dns.php | 186 +++--- src/Zone/KeylessSSL/KeylessSSL.php | 155 +++-- src/Zone/Plan/Plan.php | 79 ++- src/Zone/Railgun/Railgun.php | 79 ++- src/Zone/SSL/SSL.php | 164 +++-- src/Zone/Settings/Settings.php | 963 ++++++++++++++++----------- src/Zone/Zone.php | 187 +++--- tests/ApiTest.php | 202 +++--- 14 files changed, 1667 insertions(+), 1276 deletions(-) diff --git a/.gitignore b/.gitignore index 7020df5..78519b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor composer.lock -.ds_store \ No newline at end of file +.ds_store +.idea \ No newline at end of file diff --git a/composer.json b/composer.json index c60c17b..38c14e6 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,28 @@ { - "name": "jamesryanbell/cloudflare", - "description": "Cloudflare API V4 PHP wrapper", - "license": "MIT", - "keywords": ["cloudflare", "api"], - "authors": [ - { - "name": "James Bell", - "email": "james@james-bell.co.uk" - } - ], - "require": {}, - "require-dev": { - "phpunit/phpunit": "*", - "satooshi/php-coveralls": "dev-master" - }, - "autoload": { - "psr-4": { - "JamesRyanBell\\Cloudflare\\": "src" - } + "name": "jamesryanbell/cloudflare", + "description": "Cloudflare API V4 PHP wrapper", + "license": "MIT", + "keywords": [ + "cloudflare", + "api" + ], + "authors": [ + { + "name": "James Bell", + "email": "james@james-bell.co.uk" } + ], + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "*", + "satooshi/php-coveralls": "dev-master" + }, + "autoload": { + "psr-4": { + "JamesRyanBell\\Cloudflare\\": "src", + "JamesRyanBell\\CloudflareTests\\": "tests" + } + } } diff --git a/src/Api.php b/src/Api.php index bae6f2c..e5cb203 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1,229 +1,261 @@ + * * @version 1 */ - class Api { - protected $permission_level = array('read' => null, 'edit' => null); - - public $email; - public $auth_key; - public $curl_options; - private $permissions = null; - - /** - * Make a new instance of the API client - * This can be done via providing the email address and api key as seperate parameters - * or by passing in an already instantiated object from which the details will be extracted - */ - public function __construct() - { - $num_args = func_num_args(); - if ($num_args === 1) - { - $parameters = func_get_args(); - $client = $parameters[0]; - $this->email = $client->email; - $this->auth_key = $client->auth_key; - $this->curl_options = $client->curl_options; - $this->permissions = $client->permissions; - } else if ($num_args === 2) { - $parameters = func_get_args(); - $this->email = $parameters[0]; - $this->auth_key = $parameters[1]; - } - } - - /** - * Setter to allow the setting of the email address - * @param string $email The email address associated with the Cloudflare account - */ - public function setEmail($email) - { - $this->email = $email; - } - - /** - * Setter to allow the setting of the Authentication Key - * @param string $token Authentication key, this can be retrieve from the 'My Account' section of the Cloudflare account - */ - public function setAuthKey($token) - { - $this->auth_key = $token; - } - - /** - * Setter to allow the adding / changing of the Curl options that will be used within the HTTP requests - * @param long $key The CURLOPT_XXX option to set e.g. CURLOPT_TIMEOUT - * @param mixed $value The value to be set on option e.g. 10 - */ - public function setCurlOption($key, $value) { - $this->curl_options[$key] = $value; - } - - /** - * API call method for sending requests using GET - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - */ - public function get($path, $data = array()) - { - return $this->request($path, $data, 'get', 'read'); - } - - /** - * API call method for sending requests using POST - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - */ - public function post($path, $data = array()) - { - return $this->request($path, $data, 'post', 'edit'); - } - - /** - * API call method for sending requests using PUT - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - */ - public function put($path, $data = array()) - { - return $this->request($path, $data, 'put', 'edit'); - } - - /** - * API call method for sending requests using DELETE - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - */ - public function delete($path, $data = array()) - { - return $this->request($path, $data, 'delete', 'edit'); - } - - /** - * API call method for sending requests using PATCH - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - */ - public function patch($path, $data = array()) - { - return $this->request($path, $data, 'patch', 'edit'); - } - - public function _permissions() { - if(!$this->permissions) { - $api = new User($this->email, $this->auth_key); - $user = $api->user(); - $this->permissions = $user->result->organizations[0]->permissions; - } - return $this->permissions; - } - - /** - * - * @codeCoverageIgnore - * - * API call method for sending requests using GET, POST, PUT, DELETE OR PATCH - * @param string $path Path of the endpoint - * @param array $data Data to be sent along with the request - * @param string $method Type of method that should be used ('GET', 'POST', 'PUT', 'DELETE', 'PATCH') - * @param string $permission_level Permission level required to preform the action - */ - protected function request($path, $data = array(), $method = 'get', $permission_level = 'read') - { - if( !isset($this->email) || !isset($this->auth_key) ) { - throw new Exception('Authentication information must be provided'); - return false; - } - - if( !is_null($this->permission_level[$permission_level]) ) { - if( !$this->permissions ) { $this->_permissions(); } - if( !isset($this->permissions) || !in_array($this->permission_level[$permission_level], $this->permissions) ) { - throw new Exception('You do not have permission to perform this request'); - return false; - } - } - - //Removes null entries - $data = array_filter($data, function($val) { - return !is_null($val); - }); - - $url = 'https://api.cloudflare.com/client/v4/' . $path; - - $default_curl_options = array( - CURLOPT_VERBOSE => false, - CURLOPT_FORBID_REUSE => true, - CURLOPT_RETURNTRANSFER => 1, - CURLOPT_HEADER => false, - CURLOPT_TIMEOUT => 5, - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_FOLLOWLOCATION => true - ); - - $curl_options = $default_curl_options; - if(isset($this->curl_options) && is_array($this->curl_options)) { - $curl_options = array_replace($default_curl_options, $this->curl_options); - } - - $headers = array("X-Auth-Email: {$this->email}", "X-Auth-Key: {$this->auth_key}"); - - $ch = curl_init(); - - curl_setopt_array($ch, $curl_options); - - if( $method === 'post' ) { - curl_setopt($ch, CURLOPT_POST, true); - //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - } else if ( $method === 'put' ) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - //curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT')); - } else if ( $method === 'delete' ) { - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - $headers[] = "Content-type: application/json"; - } else if ($method === 'patch') { - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); - $headers[] = "Content-type: application/json"; - } else { - $url .= '?' . http_build_query($data); - } - - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_URL, $url); - - $http_result = curl_exec($ch); - $error = curl_error($ch); - $information = curl_getinfo($ch); - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - curl_close($ch); - if ($http_code != 200) { - return array( - 'error' => $error, - 'http_code' => $http_code, - 'method' => $method, - 'result' => $http_result, - 'information' => $information - ); - } else { - return json_decode($http_result); - } - } + protected $permissionLevel = [ + 'read' => null, + 'edit' => null, + ]; + + public $email; + public $authKey; + public $curlOptions; + private $permissions = null; + + /** + * Make a new instance of the API client. + * + * This can be done via providing the email address and api key as separate parameters + * or by passing in an already instantiated object from which the details will be extracted + */ + public function __construct() + { + $num_args = func_num_args(); + if ($num_args === 1) { + $parameters = func_get_args(); + $client = $parameters[0]; + $this->email = $client->email; + $this->authKey = $client->authKey; + $this->curlOptions = $client->curlOptions; + $this->permissions = $client->permissions; + } elseif ($num_args === 2) { + $parameters = func_get_args(); + $this->email = $parameters[0]; + $this->authKey = $parameters[1]; + } + } + + /** + * Setter to allow the setting of the email address. + * + * @param string $email The email address associated with the Cloudflare account + */ + public function setEmail($email) + { + $this->email = $email; + } + + /** + * Setter to allow the setting of the Authentication Key. + * + * @param string $token Authentication key, can be retrieve from the 'My Account' section of the Cloudflare account + */ + public function setAuthKey($token) + { + $this->authKey = $token; + } + + /** + * Setter to allow the adding / changing of the Curl options that will be used within the HTTP requests. + * + * @param long $key The CURLOPT_XXX option to set e.g. CURLOPT_TIMEOUT + * @param mixed $value The value to be set on option e.g. 10 + */ + public function setCurlOption($key, $value) + { + $this->curlOptions[$key] = $value; + } + + /** + * API call method for sending requests using GET. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * + * @return array|mixed + */ + public function get($path, array $data = []) + { + return $this->request($path, $data, 'get', 'read'); + } + + /** + * API call method for sending requests using POST. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * + * @return array|mixed + */ + public function post($path, array $data = []) + { + return $this->request($path, $data, 'post', 'edit'); + } + + /** + * API call method for sending requests using PUT. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * + * @return array|mixed + */ + public function put($path, array $data = []) + { + return $this->request($path, $data, 'put', 'edit'); + } + + /** + * API call method for sending requests using DELETE. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * + * @return array|mixed + */ + public function delete($path, array $data = []) + { + return $this->request($path, $data, 'delete', 'edit'); + } + + /** + * API call method for sending requests using PATCH. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * + * @return array|mixed + */ + public function patch($path, array $data = []) + { + return $this->request($path, $data, 'patch', 'edit'); + } + + /** + * Fetch permissions from API and set them in the object. + * + * @return mixed|null Permissions + */ + public function setPermissions() + { + if (!$this->permissions) { + $api = new User($this->email, $this->authKey); + $user = $api->user(); + $this->permissions = $user->result->organizations[0]->permissions; + } + + return $this->permissions; + } + + /** + * API call method for sending requests using GET, POST, PUT, DELETE OR PATCH. + * + * @param string $path Path of the endpoint + * @param array $data Data to be sent along with the request + * @param string $method Type of method that should be used ('GET', 'POST', 'PUT', 'DELETE', 'PATCH') + * @param string $permissionLevel Permission level required to preform the action + * + * @return array|mixed + * + * @throws Exception + * + * @codeCoverageIgnore + */ + protected function request($path, array $data = [], $method = 'get', $permissionLevel = 'read') + { + if (!isset($this->email) || !isset($this->authKey)) { + throw new Exception('Authentication information must be provided'); + } + + if (!is_null($this->permissionLevel[$permissionLevel])) { + if (!$this->permissions) { + $this->setPermissions(); + } + if (!isset($this->permissions) || !in_array($this->permissionLevel[$permissionLevel], $this->permissions)) { + throw new Exception('You do not have permission to perform this request'); + } + } + + //Removes null entries + $data = array_filter($data, function ($val) { + return !is_null($val); + }); + + $url = 'https://api.cloudflare.com/client/v4/'.$path; + + $default_curl_options = [ + CURLOPT_VERBOSE => false, + CURLOPT_FORBID_REUSE => true, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_HEADER => false, + CURLOPT_TIMEOUT => 5, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_FOLLOWLOCATION => true, + ]; + + $curl_options = $default_curl_options; + if (isset($this->curlOptions) && is_array($this->curlOptions)) { + $curl_options = array_replace($default_curl_options, $this->curlOptions); + } + + $headers = ["X-Auth-Email: {$this->email}", "X-Auth-Key: {$this->authKey}"]; + + $ch = curl_init(); + + curl_setopt_array($ch, $curl_options); + + if ($method === 'post') { + curl_setopt($ch, CURLOPT_POST, true); + //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + } elseif ($method === 'put') { + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + //curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT')); + } elseif ($method === 'delete') { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + $headers[] = 'Content-type: application/json'; + } elseif ($method === 'patch') { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); + $headers[] = 'Content-type: application/json'; + } else { + $url .= '?'.http_build_query($data); + } + + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_URL, $url); + + $http_result = curl_exec($ch); + $error = curl_error($ch); + $information = curl_getinfo($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + if ($http_code != 200) { + return [ + 'error' => $error, + 'http_code' => $http_code, + 'method' => $method, + 'result' => $http_result, + 'information' => $information, + ]; + } + + return json_decode($http_result); + } } diff --git a/src/User/User.php b/src/User/User.php index 1566ca9..31b9351 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -1,128 +1,164 @@ + * * @version 1 */ - class User extends Api { - protected $permission_level = array('read' => null, 'edit' => null); - - /** - * User details - */ - public function user() - { - return $this->get('user'); - } - - /** - * Update part of your user details - * @param string $first_name User's first name - * @param string $last_name User's last name - * @param string $telephone User's telephone number - * @param string $country The country in which the user lives. (Full list is here: http://en.wikipedia.org/wiki/List_of_country_calling_codes) - * @param string $zipcode The zipcode or postal code where the user lives. - */ - public function update($first_name = null, $last_name = null, $telephone = null, $country = null, $zipcode = null) - { - $data = array( - 'first_name' => $first_name, - 'last_name' => $last_name, - 'telephone' => $telephone, - 'country' => $country, - 'zipcode' => $zipcode - ); - return $this->patch('user', $data); - } - - /** - * Change your email address. Note: You must provide your current password. - * @param string $email Your contact email address - * @param string $email_confirm Your contact email address, repeated - * @param string $password Your current password - */ - public function change_email($email, $email_confirm, $password) { - $data = array( - 'email' => $email, - 'confirm_email' => $confirm_email, - 'password' => $password - ); - return $this->put('user/email', $data); - } - - /** - * Change your password - * @param string $old_password Your current password - * @param string $new_password Your new password - * @param string $new_password_confirm Your new password, repeated - */ - public function change_password($old_password, $new_password, $new_password_confirm) { - $data = array( - 'old_password' => $old_password, - 'new_password' => $new_password, - 'new_password_confirm' => $new_password_confirm - ); - return $this->put('user/password', $data); - } - - /** - * Change your username. Note: You must provide your current password. - * @param string $username A username used to access other cloudflare services, like support - * @param string $password Your current password - */ - public function change_username($username, $password) { - $data = array( - 'username' => $username, - 'password' => $password - ); - return $this->put('user/username', $data); - } - - /** - * Begin setting up CloudFlare two-factor authentication with a given telephone number - * @param int $country_code The country code of your mobile phone number - * @param string $mobile_phone_number Your mobile phone number - * @param string $current_password Your current CloudFlare password - */ - public function initialize_two_factor_authentication($country_code, $mobile_phone_number, $current_password) { - $data = array( - 'country_code' => $country_code, - 'mobile_phone_number' => $mobile_phone_number, - 'current_password' => $current_password - ); - return $this->post('/user/two_factor_authentication', $data); - } - - /** - * Finish setting up CloudFlare two-factor authentication with a given telephone number - * @param int $auth_token The token provided by the two-factor authenticator - */ - public function finalize_two_factor_authentication($auth_token) { - $data = array( - 'auth_token' => $auth_token - ); - return $this->put('user/two_factor_authentication', $data); - } - - /** - * Disable two-factor authentication for your CloudFlare user account - * @param int The token provided by the two-factor authenticator - */ - public function disable_two_factor_authentication($auth_token) { - $data = array( - 'auth_token' => $auth_token - ); - return $this->delete('user/two_factor_authentication', $data); - } + protected $permissionLevel = [ + 'read' => null, + 'edit' => null, + ]; + + /** + * User details. + */ + public function user() + { + return $this->get('user'); + } + + /** + * Update part of your user details. + * + * @param string $firstName User's first name + * @param string $lastName User's last name + * @param string $telephone User's telephone number + * @param string $country The country in which the user lives. + * (Full list is here: http://en.wikipedia.org/wiki/List_of_country_calling_codes) + * @param string $zipcode The zipcode or postal code where the user lives. + * + * @return array|mixed + */ + public function update($firstName = null, $lastName = null, $telephone = null, $country = null, $zipcode = null) + { + $data = [ + 'first_name' => $firstName, + 'last_name' => $lastName, + 'telephone' => $telephone, + 'country' => $country, + 'zipcode' => $zipcode, + ]; + + return $this->patch('user', $data); + } + + /** + * Change your email address. Note: You must provide your current password. + * + * @param string $email Your contact email address + * @param string $emailConfirm Your contact email address, repeated + * @param string $password Your current password + * + * @return array|mixed + */ + public function changeEmail($email, $emailConfirm, $password) + { + $data = [ + 'email' => $email, + 'confirm_email' => $emailConfirm, + 'password' => $password, + ]; + + return $this->put('user/email', $data); + } + + /** + * Change your password. + * + * @param string $oldPassword Your current password + * @param string $newPassword Your new password + * @param string $newPasswordConfirm Your new password, repeated + * + * @return array|mixed + */ + public function changePassword($oldPassword, $newPassword, $newPasswordConfirm) + { + $data = [ + 'old_password' => $oldPassword, + 'new_password' => $newPassword, + 'new_password_confirm' => $newPasswordConfirm, + ]; + + return $this->put('user/password', $data); + } + + /** + * Change your username. Note: You must provide your current password. + * + * @param string $username A username used to access other cloudflare services, like support + * @param string $password Your current password + * + * @return array|mixed + */ + public function changeUsername($username, $password) + { + $data = [ + 'username' => $username, + 'password' => $password, + ]; + + return $this->put('user/username', $data); + } + + /** + * Begin setting up CloudFlare two-factor authentication with a given telephone number. + * + * @param int $countryCode The country code of your mobile phone number + * @param string $mobilePhoneNumber Your mobile phone number + * @param string $currentPassword Your current CloudFlare password + * + * @return array|mixed + */ + public function initializeTwoFactorAuthentication($countryCode, $mobilePhoneNumber, $currentPassword) + { + $data = [ + 'country_code' => $countryCode, + 'mobile_phone_number' => $mobilePhoneNumber, + 'current_password' => $currentPassword, + ]; + + return $this->post('/user/two_factor_authentication', $data); + } + + /** + * Finish setting up CloudFlare two-factor authentication with a given telephone number. + * + * @param int $authToken The token provided by the two-factor authenticator + * + * @return array|mixed + */ + public function finalizeTwoFactorAuthentication($authToken) + { + $data = [ + 'auth_token' => $authToken, + ]; + + return $this->put('user/two_factor_authentication', $data); + } + + /** + * Disable two-factor authentication for your CloudFlare user account. + * + * @param int $authToken The token provided by the two-factor authenticator + * + * @return array|mixed + */ + public function disableTwoFactorAuthentication($authToken) + { + $data = [ + 'auth_token' => $authToken, + ]; + return $this->delete('user/two_factor_authentication', $data); + } } diff --git a/src/Zone/Cache/Cache.php b/src/Zone/Cache/Cache.php index cbdb153..ad85036 100644 --- a/src/Zone/Cache/Cache.php +++ b/src/Zone/Cache/Cache.php @@ -1,51 +1,62 @@ + * * @version 1 */ - class Cache extends Zone { - protected $permission_level = array('read' => '#zone:read', 'edit' => '#zone:edit'); + protected $permissionLevel = [ + 'read' => '#zone:read', + 'edit' => '#zone:edit', + ]; - /** - * Purge all files (permission needed: #zone:edit) - * Remove ALL files from CloudFlare's cache - * @param string $identifier API item identifier tag - * @param boolean A flag that indicates all resources in CloudFlare's cache should be removed. - * Note: This may have dramatic affects on your origin server load after - * performing this action. (true) - */ - public function purge($identifier, $purge_everything = true) - { - $data = array( - 'purge_everything' => $purge_everything - ); - return $this->delete('zones/' . $identifier . '/purge_cache', $data); - } + /** + * Purge all files (permission needed: #zone:edit). + * + * Remove ALL files from CloudFlare's cache + * + * @param string $identifier API item identifier tag + * @param bool $purgeEverything A flag that indicates all resources in CloudFlare's cache should be removed. + * Note: This may have dramatic affects on your origin server load after + * performing this action. (true) + * + * @return array|mixed + */ + public function purge($identifier, bool $purgeEverything = true) + { + $data = [ + 'purgeEverything' => $purgeEverything, + ]; - /** - * Purge individual files (permission needed: #zone:edit) - * Remove one or more files from CloudFlare's cache - * @param string $identifier API item identifier tag - * @param array $files An array of URLs that should be removed from cache - */ - public function purge_files($identifier, array $files) - { - $data = array( - 'files' => $files - ); - return $this->delete('zones/' . $identifier . '/purge_cache', $data); - } + return $this->delete('zones/'.$identifier.'/purge_cache', $data); + } + /** + * Purge individual files (permission needed: #zone:edit). + * + * Remove one or more files from CloudFlare's cache + * + * @param string $identifier API item identifier tag + * @param array $files An array of URLs that should be removed from cache + * + * @return array|mixed + */ + public function purgeFiles($identifier, array $files) + { + $data = [ + 'files' => $files, + ]; + return $this->delete('zones/'.$identifier.'/purge_cache', $data); + } } diff --git a/src/Zone/CustomPages/CustomPages.php b/src/Zone/CustomPages/CustomPages.php index f70bdf4..903af55 100644 --- a/src/Zone/CustomPages/CustomPages.php +++ b/src/Zone/CustomPages/CustomPages.php @@ -1,55 +1,67 @@ + * * @version 1 */ - class CustomPages extends Zone { - protected $permission_level = array('read' => '#zone_settings:read', 'edit' => '#zone_settings:edit'); + protected $permissionLevel = [ + 'read' => '#zone_settings:read', + 'edit' => '#zone_settings:edit', + ]; - /** - * Available Custom Pages (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function custom_pages($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/custom_pages'); - } + /** + * Available Custom Pages (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function customPages($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/custom_pages'); + } - /** - * Custom Page details (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/custom_pages/' . $identifier); - } + /** + * Custom Page details (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function details($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/custom_pages/'.$identifier); + } - /** - * Update Custom page URL (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - * @param string $url A URL that is associated with the Custom Page. - * @param string $state The Custom Page state - */ - public function update($zone_identifier, $identifier, $url, $state) - { - $data = array( - 'url' => $url, - 'state' => $state - ); - return $this->patch('zones/' . $zone_identifier . '/custom_pages/' . $identifier, $data); - } + /** + * Update Custom page URL (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * @param string $url A URL that is associated with the Custom Page. + * @param string $state The Custom Page state + * + * @return array|mixed + */ + public function update($zoneIdentifier, $identifier, $url, $state) + { + $data = [ + 'url' => $url, + 'state' => $state, + ]; + return $this->patch('zones/'.$zoneIdentifier.'/custom_pages/'.$identifier, $data); + } } diff --git a/src/Zone/Dns/Dns.php b/src/Zone/Dns/Dns.php index d71d946..2bb4ddb 100644 --- a/src/Zone/Dns/Dns.php +++ b/src/Zone/Dns/Dns.php @@ -1,102 +1,130 @@ + * * @version 1 */ - class Dns extends Zone { - protected $permission_level = array('read' => '#dns_records:read', 'edit' => '#dns_records:edit'); - - /** - * Create DNS record (permission needed: #dns_records:edit) - * @param string $zone_identifier - * @param string $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF) - * @param string $name DNS record name - * @param string $content DNS record content - * @param integer $ttl Time to live for DNS record. Value of 1 is 'automatic' - */ - public function create($zone_identifier, $type, $name, $content, $ttl = 1) - { - $data = array( - 'type' => strtoupper($type), - 'name' => $name, - 'content' => $content, - 'ttl' => $ttl - ); + protected $permissionLevel = [ + 'read' => '#dns_records:read', + 'edit' => '#dns_records:edit', + ]; - return $this->post('zones/' . $zone_identifier . '/dns_records', $data); - } + /** + * Create DNS record (permission needed: #dns_records:edit). + * + * @param string $zoneIdentifier + * @param string $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF) + * @param string $name DNS record name + * @param string $content DNS record content + * @param int $ttl Time to live for DNS record. Value of 1 is 'automatic' + * + * @return array|mixed + */ + public function create($zoneIdentifier, $type, $name, $content, $ttl = 1) + { + $data = [ + 'type' => strtoupper($type), + 'name' => $name, + 'content' => $content, + 'ttl' => $ttl, + ]; - /** - * List DNS Records (permission needed: #dns_records:read) - * List, search, sort, and filter a zones' DNS records. - * @param string $zone_identifier - * @param string $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF) - * @param string $name DNS record name - * @param string $content DNS record content - * @param string $vanity_name_server_record Flag for records that were created for the vanity name server feature (true, false) - * @param integer $page Page number of paginated results - * @param integer $per_page Number of DNS records per page - * @param string $order Field to order records by (type, name, content, ttl, proxied) - * @param string $direction Direction to order domains (asc, desc) - * @param string $match Whether to match all search requirements or at least one (any) (any, all) - */ - public function list_records($zone_identifier, $type = 'A', $name = null, $content = null, $vanity_name_server_record = null, $page = 1, $per_page = 20, $order = '', $direction = 'desc', $match = 'all') - { - $data = array( - 'type' => $type, - 'name' => $name, - 'content' => $content, - 'vanity_name_server_record' => $vanity_name_server_record, - 'page' => $page, - 'per_page' => $per_page, - 'order' => $order, - 'direction' => $direction, - 'match' => $match - ); + return $this->post('zones/'.$zoneIdentifier.'/dns_records', $data); + } - return $this->get('zones/' . $zone_identifier . '/dns_records', $data); - } + /** + * List DNS Records (permission needed: #dns_records:read). + * + * List, search, sort, and filter a zones' DNS records. + * + * @param string $zoneIdentifier + * @param string $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF) + * @param string $name DNS record name + * @param string $content DNS record content + * @param string $vanityNameServerRecord Flag for records created for the vanity name server feature (true, false) + * @param int $page Page number of paginated results + * @param int $perPage Number of DNS records per page + * @param string $order Field to order records by (type, name, content, ttl, proxied) + * @param string $direction Direction to order domains (asc, desc) + * @param string $match Whether to match all search requirements or at least one (any) (any, all) + * + * @return array|mixed + */ + public function listRecords( + $zoneIdentifier, + $type = 'A', + $name = null, + $content = null, + $vanityNameServerRecord = null, + $page = 1, + $perPage = 20, + $order = '', + $direction = 'desc', + $match = 'all' + ) { + $data = [ + 'type' => $type, + 'name' => $name, + 'content' => $content, + 'vanity_name_server_record' => $vanityNameServerRecord, + 'page' => $page, + 'per_page' => $perPage, + 'order' => $order, + 'direction' => $direction, + 'match' => $match, + ]; - /** - * DNS record details (permission needed: #dns_records:read) - * @param string $zone_identifier - * @param string $identifier API item identifier tag - */ - public function details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/dns_records/' . $identifier); - } + return $this->get('zones/'.$zoneIdentifier.'/dns_records', $data); + } - /** - * Update DNS record (permission needed: #dns_records:edit) - * @param string $zone_identifier - * @param string $identifier API item identifier tag - */ - public function update($zone_identifier, $identifier) - { - return $this->put('zones/' . $zone_identifier . '/dns_records/' . $identifier); - } + /** + * DNS record details (permission needed: #dns_records:read). + * + * @param string $zoneIdentifier + * @param string $identifier API item identifier tag + * + * @return array|mixed + */ + public function details($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/dns_records/'.$identifier); + } - /** - * Update DNS record (permission needed: #dns_records:edit) - * @param string $zone_identifier - * @param string $identifier API item identifier tag - */ - public function delete_record($zone_identifier, $identifier) - { - return $this->delete('zones/' . $zone_identifier . '/dns_records/' . $identifier); - } + /** + * Update DNS record (permission needed: #dns_records:edit). + * + * @param string $zoneIdentifier + * @param string $identifier API item identifier tag + * + * @return array|mixed + */ + public function update($zoneIdentifier, $identifier) + { + return $this->put('zones/'.$zoneIdentifier.'/dns_records/'.$identifier); + } + /** + * Update DNS record (permission needed: #dns_records:edit). + * + * @param string $zoneIdentifier + * @param string $identifier API item identifier tag + * + * @return array|mixed + */ + public function deleteRecord($zoneIdentifier, $identifier) + { + return $this->delete('zones/'.$zoneIdentifier.'/dns_records/'.$identifier); + } } diff --git a/src/Zone/KeylessSSL/KeylessSSL.php b/src/Zone/KeylessSSL/KeylessSSL.php index fd5a404..67994b1 100644 --- a/src/Zone/KeylessSSL/KeylessSSL.php +++ b/src/Zone/KeylessSSL/KeylessSSL.php @@ -1,89 +1,108 @@ + * * @version 1 */ - class KeylessSSL extends Zone { - protected $permission_level = array('read' => '#ssl:read', 'edit' => '#ssl:edit'); + protected $permissionLevel = [ + 'read' => '#ssl:read', + 'edit' => '#ssl:edit', + ]; + + /** + * List Keyless SSLs (permission needed: #ssl:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function certificates($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/keyless_certificates'); + } - /** - * List Keyless SSLs (permission needed: #ssl:read) - * @param string $zone_identifier API item identifier tag - */ - public function certificates($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/keyless_certificates'); - } + /** + * Keyless SSL details (permission needed: #ssl:read). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function details($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/keyless_certificates/'.$identifier); + } - /** - * Keyless SSL details (permission needed: #ssl:read) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/keyless_certificates/' . $identifier); - } + /** + * Create a Keyless SSL configuration (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) + * @param string $host The keyless SSL hostname + * @param int $port The keyless SSL port used for CloudFlare <=> client's Keyless SSL server comm + * @param string $name The keyless SSL name + * @param string $certificate The zone's SSL certificate or SSL certificate and intermediate(s) + * + * @return array|mixed + */ + public function create($zoneIdentifier, $host, $port, $name, $certificate) + { + $data = [ + 'host' => $host, + 'port' => $port, + 'name' => $name, + 'certificate' => $certificate, + ]; - /** - * Create a Keyless SSL configuration (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) - * @param string $host The keyless SSL hostname - * @param int $port The keyless SSL port used to commmunicate between CloudFlare and the client's Keyless SSL server - * @param string $name The keyless SSL name - * @param string $certificate The zone's SSL certificate or SSL certificate and intermediate(s) - */ - public function create($zone_identifier, $host, $port, $name, $certificate) - { - $data = array( - 'host' => $host, - 'port' => $port, - 'name' => $name, - 'certificate' => $certificate - ); - return $this->post('zones/' . $zone_identifier . '/keyless_certificates', $data); - } + return $this->post('zones/'.$zoneIdentifier.'/keyless_certificates', $data); + } - /** - * Update SSL configuration (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - * @param string $host The keyless SSL hostname - * @param string $name The keyless SSL name - * @param int $port The keyless SSL port used to commmunicate between CloudFlare and the client's Keyless SSL server - * @param bool $enabled Whether or not the Keyless SSL is on or off - */ - public function update($zone_identifier, $identifier, $host, $name, $port, $enabled = false) - { - $data = array( - 'host' => $host, - 'port' => $port, - 'name' => $name, - 'enabled' => $enabled - ); - return $this->patch('zones/' . $zone_identifier . '/keyless_certificates/' . $identifier, $data); - } + /** + * Update SSL configuration (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * @param string $host The keyless SSL hostname + * @param string $name The keyless SSL name + * @param int $port The keyless SSL port used for CloudFlare <=> client's Keyless SSL server comm + * @param bool $enabled Whether or not the Keyless SSL is on or off + * + * @return array|mixed + */ + public function update($zoneIdentifier, $identifier, $host, $name, $port, $enabled = false) + { + $data = [ + 'host' => $host, + 'port' => $port, + 'name' => $name, + 'enabled' => $enabled, + ]; - /** - * Delete an SSL certificate (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function delete($zone_identifier, $identifier) - { - return $this->delete('zones/' . $zone_identifier . '/keyless_certificates/' . $identifier); - } + return $this->patch('zones/'.$zoneIdentifier.'/keyless_certificates/'.$identifier, $data); + } + /** + * Delete an SSL certificate (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function delete($zoneIdentifier, $identifier) + { + return $this->delete('zones/'.$zoneIdentifier.'/keyless_certificates/'.$identifier); + } } diff --git a/src/Zone/Plan/Plan.php b/src/Zone/Plan/Plan.php index e9b7ca3..e5a506b 100644 --- a/src/Zone/Plan/Plan.php +++ b/src/Zone/Plan/Plan.php @@ -1,50 +1,65 @@ + * * @version 1 */ - class Plan extends Zone { - protected $permission_level = array('read' => '#billing:read', 'edit' => '#billing:edit'); + protected $permissionLevel = [ + 'read' => '#billing:read', + 'edit' => '#billing:edit', + ]; - /** - * Available plans (permission needed: #billing:read) - * List all plans the zone can subscribe to. - * @param string $zone_identifier - */ - public function available($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/plans'); - } + /** + * Available plans (permission needed: #billing:read). + * + * List all plans the zone can subscribe to. + * + * @param string $zoneIdentifier + * + * @return array|mixed + */ + public function available($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/plans'); + } - /** - * Available plans (permission needed: #billing:read) - * @param string $zone_identifier - * @param string $identifier API item identifier tag - */ - public function details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/plans/' . $identifier); - } + /** + * Available plans (permission needed: #billing:read). + * + * @param string $zoneIdentifier + * @param string $identifier API item identifier tag + * + * @return array|mixed + */ + public function details($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/plans/'.$identifier); + } - /** - * Change plan (permission needed: #billing:edit) - * Change the plan level for the zone. This will cancel any previous subscriptions and subscribe the zone to the new plan. - * @param string $zone_identifier - * @param string $identifier API item identifier tag - */ - public function change($zone_identifier, $identifier) - { - return $this->put('zones/' . $zone_identifier . '/plans/' . $identifier . '/subscribe'); - } + /** + * Change plan (permission needed: #billing:edit). + * + * Change the plan level for the zone. + * This will cancel any previous subscriptions and subscribe the zone to the new plan. + * + * @param string $zoneIdentifier + * @param string $identifier API item identifier tag + * + * @return array|mixed + */ + public function change($zoneIdentifier, $identifier) + { + return $this->put('zones/'.$zoneIdentifier.'/plans/'.$identifier.'/subscribe'); + } } diff --git a/src/Zone/Railgun/Railgun.php b/src/Zone/Railgun/Railgun.php index d010adf..08e4040 100644 --- a/src/Zone/Railgun/Railgun.php +++ b/src/Zone/Railgun/Railgun.php @@ -1,52 +1,65 @@ + * * @version 1 */ - class Railgun extends Zone { - protected $permission_level = array('read' => '#zone_settings:read', 'edit' => '#zone_settings:edit'); + protected $permissionLevel = [ + 'read' => '#zone_settings:read', + 'edit' => '#zone_settings:edit', + ]; - /** - * Get available Railguns (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function railguns($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/railguns'); - } + /** + * Get available Railguns (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function railguns($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/railguns'); + } - /** - * Get Railgun details (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function railgun_details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/railguns/' . $identifier); - } + /** + * Get Railgun details (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function railgunDetails($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/railguns/'.$identifier); + } - /** - * Connect or disconnect a Railgun (permission needed: #zone_settings:edit) - * @param string $identifier API item identifier tag - * @param bool $connected A flag indicating whether the given zone is connected to the Railgun [valid values: (true,false)] - */ - public function railgun_connected($zone_identifier, $identifier, bool $connected) - { - $data = array( - 'connected' => $connected - ); - return $this->get('zones/' . $zone_identifier . '/railguns/' . $identifier, $data); - } + /** + * Connect or disconnect a Railgun (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * @param bool $connected Flag indicating whether the zone is connected to the Railgun + * + * @return array|mixed + */ + public function railgunConnected($zoneIdentifier, $identifier, bool $connected) + { + $data = [ + 'connected' => $connected, + ]; + return $this->get('zones/'.$zoneIdentifier.'/railguns/'.$identifier, $data); + } } diff --git a/src/Zone/SSL/SSL.php b/src/Zone/SSL/SSL.php index 93ef42b..6dffda0 100644 --- a/src/Zone/SSL/SSL.php +++ b/src/Zone/SSL/SSL.php @@ -1,93 +1,117 @@ + * * @version 1 */ - class SSL extends Zone { - protected $permission_level = array('read' => '#ssl:read', 'edit' => '#ssl:edit'); + protected $permissionLevel = [ + 'read' => '#ssl:read', + 'edit' => '#ssl:edit', + ]; + + /** + * List SSL configurations (permission needed: #ssl:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function certificates($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/custom_certificates'); + } + + /** + * List SSL configuration details (permission needed: #ssl:read). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function details($zoneIdentifier, $identifier) + { + return $this->get('zones/'.$zoneIdentifier.'/custom_certificates/'.$identifier); + } - /** - * List SSL configurations (permission needed: #ssl:read) - * @param string $zone_identifier API item identifier tag - */ - public function certificates($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/custom_certificates'); - } + /** + * Create SSL configuration (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) + * @param string $privateKey The zone's private key + * + * @return array|mixed + */ + public function create($zoneIdentifier, $certificate, $privateKey) + { + $data = [ + 'certificate' => $certificate, + 'private_key' => $privateKey, + ]; - /** - * List SSL configuration details (permission needed: #ssl:read) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function details($zone_identifier, $identifier) - { - return $this->get('zones/' . $zone_identifier . '/custom_certificates/' . $identifier); - } + return $this->post('zones/'.$zoneIdentifier.'/custom_certificates', $data); + } - /** - * Create SSL configuration (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) - * @param string $private_key The zone's private key - */ - public function create($zone_identifier, $certificate, $private_key) - { - $data = array( - 'certificate' => $certificate, - 'private_key' => $private_key - ); - return $this->post('zones/' . $zone_identifier . '/custom_certificates', $data); - } + /** + * Update SSL configuration (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) + * @param string $privateKey The zone's private key + * + * @return array|mixed + */ + public function update($zoneIdentifier, $identifier, $certificate, $privateKey) + { + $data = [ + 'certificate' => $certificate, + 'private_key' => $privateKey, + ]; - /** - * Update SSL configuration (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - * @param string $certificate The zone's SSL certificate or certificate and the intermediate(s) - * @param string $private_key The zone's private key - */ - public function update($zone_identifier, $identifier, $certificate, $private_key) - { - $data = array( - 'certificate' => $certificate, - 'private_key' => $private_key - ); - return $this->patch('zones/' . $zone_identifier . '/custom_certificates/' . $identifier, $data); - } + return $this->patch('zones/'.$zoneIdentifier.'/custom_certificates/'.$identifier, $data); + } - /** - * Re-prioritize SSL certificates (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $certificates Array of ordered certificates - */ - public function prioritize($zone_identifier, $certificates) - { - $data = array( - 'certificates' => $certificates - ); - return $this->patch('zones/' . $zone_identifier . '/custom_certificates/prioritize', $data); - } + /** + * Re-prioritize SSL certificates (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $certificates Array of ordered certificates + * + * @return array|mixed + */ + public function prioritize($zoneIdentifier, $certificates) + { + $data = [ + 'certificates' => $certificates, + ]; - /** - * Delete an SSL certificate (permission needed: #ssl:edit) - * @param string $zone_identifier API item identifier tag - * @param string $identifier - */ - public function delete($zone_identifier, $identifier) - { - return $this->delete('zones/' . $zone_identifier . '/custom_certificates/' . $identifier); - } + return $this->patch('zones/'.$zoneIdentifier.'/custom_certificates/prioritize', $data); + } + /** + * Delete an SSL certificate (permission needed: #ssl:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $identifier + * + * @return array|mixed + */ + public function delete($zoneIdentifier, $identifier) + { + return $this->delete('zones/'.$zoneIdentifier.'/custom_certificates/'.$identifier); + } } diff --git a/src/Zone/Settings/Settings.php b/src/Zone/Settings/Settings.php index 6714597..e09dc1e 100644 --- a/src/Zone/Settings/Settings.php +++ b/src/Zone/Settings/Settings.php @@ -1,419 +1,574 @@ + * * @version 1 */ - class Settings extends Zone { - protected $permission_level = array('read' => '#zone_settings:read', 'edit' => '#zone_settings:edit'); - - /** - * Zone settings (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function settings($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings'); - } - - /** - * Advanced DDOS setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function advanced_ddos($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/advanced_ddos'); - } - - /** - * Get Always Online setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function always_online($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/always_online'); - } - - /** - * Get Browser Cache TTL setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function browser_cache_ttl($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/browser_cache_ttl'); - } - - /** - * Get Browser Check setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function browser_check($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/browser_check'); - } - - /** - * Get Cache Level setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function cache_level($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/cache_level'); - } - - /** - * Get Challenge TTL setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function challenge_ttl($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/challenge_ttl'); - } - - /** - * Get Development Mode setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function development_mode($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/development_mode'); - } - - /** - * Get Email Obfuscation setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function email_obfuscation($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/email_obfuscation'); - } - - /** - * Get Hotlink Protection setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function hotlink_protection($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/hotlink_protection'); - } - - /** - * Get IP Geolocation setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function ip_geolocation($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/ip_geolocation'); - } - - /** - * Get IP IPv6 setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function ipv6($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/ipv6'); - } - - /** - * Get IP Minify setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function minify($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/minify'); - } - - /** - * Get Mobile Redirect setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function mobile_redirect($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/mobile_redirect'); - } - - /** - * Get Mirage setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function mirage($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/mirage'); - } - - /** - * Get Polish setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function polish($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/polish'); - } - - /** - * Get Rocket Loader setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function rocket_loader($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/rocket_loader'); - } - - /** - * Get Security Level setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function security_level($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/security_level'); - } - - /** - * Get Server Side Exclude setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function server_side_exclude($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/server_side_exclude'); - } - - /** - * Get SSL setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function ssl($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/ssl'); - } - - /** - * Get Web Application Firewall (WAF) setting (permission needed: #zone_settings:read) - * @param string $zone_identifier API item identifier tag - */ - public function waf($zone_identifier) - { - return $this->get('zones/' . $zone_identifier . '/settings/waf'); - } - - /** - * Get Web Application Firewall (WAF) setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param array $items One or more zone setting objects. Must contain an ID and a value. - */ - public function edit($zone_identifier, array $data) - { - return $this->patch('zones/' . $zone_identifier . '/settings', $data); - } - - /** - * Change Always Online setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_always_on($zone_identifier, $value = 'on') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/always_online', $data); - } - - /** - * Change Browser Cache TTL setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param int $value Value of the zone setting (default: 14400) - */ - public function change_browser_cache_ttl($zone_identifier, $value = 14400) - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/browser_cache_ttl', $data); - } - - /** - * Change Browser Check setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_browser_check($zone_identifier, $value = 'on') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/browser_check', $data); - } - - /** - * Change Cache Level setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_cache_level($zone_identifier, $value = 'aggressive') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/cache_level', $data); - } - - /** - * Change Challenge TTL setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param int $value Value of the zone setting (default: on) - */ - public function change_challenge_ttl($zone_identifier, $value = 1800) - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/challenge_ttl', $data); - } - - /** - * Change Development Mode setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_development_mode($zone_identifier, $value = 'off') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/development_mode', $data); - } - - /** - * Change Email Obfuscation setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_email_obfuscation($zone_identifier, $value = 'on') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/email_obfuscation', $data); - } - - /** - * Change Hotlink Protection setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_hotlink_protection($zone_identifier, $value = 'off') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/hotlink_protection', $data); - } - - /** - * Change IP Geolocation setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_ip_geolocation($zone_identifier, $value = 'on') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/ip_geolocation', $data); - } - - /** - * Change IP Geolocation setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_ipv6($zone_identifier, $value = 'off') - { - $data = array('value' => $value); - return $this->patch('zones/' . $zone_identifier . '/settings/ipv6', $data); - } - - /** - * Change Minify setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting - */ - public function change_minify($zone_identifier, $data) - { - return $this->patch('zones/' . $zone_identifier . '/settings/minify', $data); - } - - /** - * Change Mobile Redirect setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_mobile_redirect($zone_identifier, $data) - { - return $this->patch('zones/' . $zone_identifier . '/settings/minify', $data); - } - - /** - * Change Mirage setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: off) - */ - public function change_mirage($zone_identifier, $value = 'off') - { - return $this->patch('zones/' . $zone_identifier . '/settings/mirage', $value); - } - - /** - * Change Polish setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: off) - */ - public function change_polish($zone_identifier, $value = 'off') - { - return $this->patch('zones/' . $zone_identifier . '/settings/polish', $value); - } - - /** - * Change Rocket Loader setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: off) - */ - public function change_rocket_loader($zone_identifier, $value = 'off') - { - return $this->patch('zones/' . $zone_identifier . '/settings/rocket_loader', $value); - } - - /** - * Change Security Level setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: medium) - */ - public function change_security_level($zone_identifier, $value = 'medium') - { - return $this->patch('zones/' . $zone_identifier . '/settings/security_level', $value); - } - - /** - * Change Server Side Exclude setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: on) - */ - public function change_server_side_exclude($zone_identifier, $value = 'on') - { - return $this->patch('zones/' . $zone_identifier . '/settings/server_side_exclude', $value); - } - - /** - * Change SSL setting (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: off) - */ - public function change_ssl($zone_identifier, $value = 'off') - { - return $this->patch('zones/' . $zone_identifier . '/settings/ssl', $value); - } - - /** - * Change Web Application Firewall (WAF) (permission needed: #zone_settings:edit) - * @param string $zone_identifier API item identifier tag - * @param string $value Value of the zone setting (default: off) - */ - public function change_waf($zone_identifier, $value = 'off') - { - return $this->patch('zones/' . $zone_identifier . '/settings/waf', $value); - } - + protected $permissionLevel = [ + 'read' => '#zone_settings:read', + 'edit' => '#zone_settings:edit', + ]; + + /** + * Zone settings (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function settings($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings'); + } + + /** + * Advanced DDOS setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function advancedDdos($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/advanced_ddos'); + } + + /** + * Get Always Online setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function alwaysOnline($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/always_online'); + } + + /** + * Get Browser Cache TTL setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function browserCacheTtl($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/browser_cache_ttl'); + } + + /** + * Get Browser Check setting (permission needed: #zone_settings:read). + * + * @param string $zone_identifier API item identifier tag + * + * @return array|mixed + */ + public function browserCheck($zone_identifier) + { + return $this->get('zones/'.$zone_identifier.'/settings/browser_check'); + } + + /** + * Get Cache Level setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function cacheLevel($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/cache_level'); + } + + /** + * Get Challenge TTL setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function challengeTtl($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/challenge_ttl'); + } + + /** + * Get Development Mode setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function developmentMode($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/development_mode'); + } + + /** + * Get Email Obfuscation setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function emailObfuscation($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/email_obfuscation'); + } + + /** + * Get Hotlink Protection setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function hotlinkProtection($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/hotlink_protection'); + } + + /** + * Get IP Geolocation setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function ipGeolocation($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/ip_geolocation'); + } + + /** + * Get IP IPv6 setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function ipv6($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/ipv6'); + } + + /** + * Get IP Minify setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function minify($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/minify'); + } + + /** + * Get Mobile Redirect setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function mobileRedirect($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/mobile_redirect'); + } + + /** + * Get Mirage setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function mirage($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/mirage'); + } + + /** + * Get Polish setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function polish($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/polish'); + } + + /** + * Get Rocket Loader setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function rocketLoader($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/rocket_loader'); + } + + /** + * Get Security Level setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function securityLevel($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/security_level'); + } + + /** + * Get Server Side Exclude setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function serverSideExclude($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/server_side_exclude'); + } + + /** + * Get SSL setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function ssl($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/ssl'); + } + + /** + * Get Web Application Firewall (WAF) setting (permission needed: #zone_settings:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function waf($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier.'/settings/waf'); + } + + /** + * Get Web Application Firewall (WAF) setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param array $data $items One or more zone setting objects. Must contain an ID and a value. + * + * @return array|mixed + */ + public function edit($zoneIdentifier, array $data) + { + return $this->patch('zones/'.$zoneIdentifier.'/settings', $data); + } + + /** + * Change Always Online setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeAlwaysOn($zoneIdentifier, $value = 'on') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/always_online', $data); + } + + /** + * Change Browser Cache TTL setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param int $value Value of the zone setting (default: 14400) + * + * @return array|mixed + */ + public function changeBrowserCacheTtl($zoneIdentifier, $value = 14400) + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/browser_cache_ttl', $data); + } + + /** + * Change Browser Check setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeBrowserCheck($zoneIdentifier, $value = 'on') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/browser_check', $data); + } + + /** + * Change Cache Level setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeCacheLevel($zoneIdentifier, $value = 'aggressive') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/cache_level', $data); + } + + /** + * Change Challenge TTL setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param int $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeChallengeTtl($zoneIdentifier, $value = 1800) + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/challenge_ttl', $data); + } + + /** + * Change Development Mode setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeDevelopmentMode($zoneIdentifier, $value = 'off') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/development_mode', $data); + } + + /** + * Change Email Obfuscation setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeEmailObfuscation($zoneIdentifier, $value = 'on') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/email_obfuscation', $data); + } + + /** + * Change Hotlink Protection setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeHotlinkProtection($zoneIdentifier, $value = 'off') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/hotlink_protection', $data); + } + + /** + * Change IP Geolocation setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeIpGeolocation($zoneIdentifier, $value = 'on') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/ip_geolocation', $data); + } + + /** + * Change IP Geolocation setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeIpv6($zoneIdentifier, $value = 'off') + { + $data = [ + 'value' => $value, + ]; + + return $this->patch('zones/'.$zoneIdentifier.'/settings/ipv6', $data); + } + + /** + * Change Minify setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting + * + * @return array|mixed + */ + public function changeMinify($zoneIdentifier, $value) + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/minify', $value); + } + + /** + * Change Mobile Redirect setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeMobileRedirect($zoneIdentifier, $value = 'on') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/mobile_redirect', $value); + } + + /** + * Change Mirage setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: off) + * + * @return array|mixed + */ + public function changeMirage($zoneIdentifier, $value = 'off') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/mirage', $value); + } + + /** + * Change Polish setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: off) + * + * @return array|mixed + */ + public function changePolish($zoneIdentifier, $value = 'off') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/polish', $value); + } + + /** + * Change Rocket Loader setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: off) + * + * @return array|mixed + */ + public function changeRocketLoader($zoneIdentifier, $value = 'off') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/rocket_loader', $value); + } + + /** + * Change Security Level setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: medium) + * + * @return array|mixed + */ + public function changeSecurityLevel($zoneIdentifier, $value = 'medium') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/security_level', $value); + } + + /** + * Change Server Side Exclude setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: on) + * + * @return array|mixed + */ + public function changeServerSideExclude($zoneIdentifier, $value = 'on') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/server_side_exclude', $value); + } + + /** + * Change SSL setting (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: off) + * + * @return array|mixed + */ + public function changeSsl($zoneIdentifier, $value = 'off') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/ssl', $value); + } + + /** + * Change Web Application Firewall (WAF) (permission needed: #zone_settings:edit). + * + * @param string $zoneIdentifier API item identifier tag + * @param string $value Value of the zone setting (default: off) + * + * @return array|mixed + */ + public function changeWaf($zoneIdentifier, $value = 'off') + { + return $this->patch('zones/'.$zoneIdentifier.'/settings/waf', $value); + } } diff --git a/src/Zone/Zone.php b/src/Zone/Zone.php index e6e63ae..46e62ef 100644 --- a/src/Zone/Zone.php +++ b/src/Zone/Zone.php @@ -1,99 +1,132 @@ + * * @version 1 */ - class Zone extends Api { - protected $permission_level = array('read' => '#zone:read', 'edit' => '#zone:edit'); + protected $permissionLevel = [ + 'read' => '#zone:read', + 'edit' => '#zone:edit', + ]; + + /** + * Create a zone (permission needed: #zone:edit). + * + * @param $name + * @param bool $jumpStart Automatically attempt to fetch existing DNS records + * @param null $organization Organization that this zone will belong to + * + * @return array|mixed + * + * @internal param string $domain The domain name + */ + public function create($name, $jumpStart = true, $organization = null) + { + $data = [ + 'name' => $name, + 'jump_start' => $jumpStart, + 'organization' => $organization, + ]; - /** - * Create a zone (permission needed: #zone:edit) - * @param string $domain The domain name - * @param boolean $jump_start Automatically attempt to fetch existing DNS records - * @param null $organization Organization that this zone will belong to - */ - public function create($name, $jump_start = true, $organization = null) - { - $data = array( - 'name' => $name, - 'jump_start' => $jump_start, - 'organization' => $organization - ); - return $this->post('zones', $data); - } + return $this->post('zones', $data); + } - /** - * List zones permission needed: #zone:read - * List, search, sort, and filter your zones - * @param string $name A domain name - * @param string $status Status of the zone (active, pending, initializing, moved, deleted) - * @param integer $page Page number of paginated results - * @param integer $per_page Number of zones per page - * @param string $order Field to order zones by (name, status, email) - * @param string $direction Direction to order zones (asc, desc) - * @param string $match Whether to match all search requirements or at least one (any) (any, all) - */ - public function zones($name = '', $status = 'active', $page = 1, $per_page = 20, $order = 'status', $direction = 'desc', $match = 'all') - { - $data = array( - 'name' => $name, - 'status' => $status, - 'page' => $page, - 'per_page' => $per_page, - 'order' => $order, - 'direction' => $direction, - 'match' => $match - ); - return $this->get('zones', $data); - } + /** + * List zones permission needed: #zone:read. + * + * List, search, sort, and filter your zones + * + * @param string $name A domain name + * @param string $status Status of the zone (active, pending, initializing, moved, deleted) + * @param int $page Page number of paginated results + * @param int $perPage Number of zones per page + * @param string $order Field to order zones by (name, status, email) + * @param string $direction Direction to order zones (asc, desc) + * @param string $match Whether to match all search requirements or at least one (any) (any, all) + * + * @return array|mixed + */ + public function zones( + $name = '', + $status = 'active', + $page = 1, + $perPage = 20, + $order = 'status', + $direction = 'desc', + $match = 'all' + ) { + $data = [ + 'name' => $name, + 'status' => $status, + 'page' => $page, + 'per_page' => $perPage, + 'order' => $order, + 'direction' => $direction, + 'match' => $match, + ]; - /** - * Zone details (permission needed: #zone:read) - * @param string $zone_identifier API item identifier tag - */ - public function zone($zone_identifier) - { - return $this->get('zones/' . $zone_identifier); - } + return $this->get('zones', $data); + } - /** - * Pause all CloudFlare features (permission needed: #zone:edit) - * This will pause all features and settings for the zone. DNS will still resolve - * @param string $zone_identifier API item identifier tag - */ - public function pause($zone_identifier) - { - return $this->put('zones/' . $zone_identifier . '/pause'); - } + /** + * Zone details (permission needed: #zone:read). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function zone($zoneIdentifier) + { + return $this->get('zones/'.$zoneIdentifier); + } - /** - * Re-enable all CloudFlare features (permission needed: #zone:edit) - * This will restore all features and settings for the zone - * @param string $zone_identifier API item identifier tag - */ - public function unpause($zone_identifier) - { - return $this->put('zones/' . $zone_identifier . '/unpause'); - } + /** + * Pause all CloudFlare features (permission needed: #zone:edit). + * + * This will pause all features and settings for the zone. DNS will still resolve + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function pause($zoneIdentifier) + { + return $this->put('zones/'.$zoneIdentifier.'/pause'); + } - /** - * Delete a zone (permission needed: #zone:edit) - * @param string $zone_identifier API item identifier tag - */ - public function delete_zone($zone_identifier) - { - return $this->delete('zones/' . $zone_identifier); - } + /** + * Re-enable all CloudFlare features (permission needed: #zone:edit). + * + * This will restore all features and settings for the zone + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function unpause($zoneIdentifier) + { + return $this->put('zones/'.$zoneIdentifier.'/unpause'); + } + /** + * Delete a zone (permission needed: #zone:edit). + * + * @param string $zoneIdentifier API item identifier tag + * + * @return array|mixed + */ + public function deleteZone($zoneIdentifier) + { + return $this->delete('zones/'.$zoneIdentifier); + } } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 3eaa913..58caf40 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -1,102 +1,108 @@ assertTrue((bool)$api); - } - - public function testApiInitialised() - { - $api = new Api('email@example.com', 'Auth Key'); - $this->assertEquals('email@example.com', $api->email); - $this->assertEquals('Auth Key', $api->auth_key); - } - - public function testApiInitialisedFromPreviousObject() - { - $client = new Api('email@example.com', 'Auth Key'); - $api = new Api($client); - $this->assertEquals('email@example.com', $api->email); - $this->assertEquals('Auth Key', $api->auth_key); - } - - public function testSetAuthKey() - { - $api = new Api; - $api->setAuthKey('Auth Key'); - $this->assertEquals('Auth Key', $api->auth_key); - } - - public function testSetEmail() - { - $api = new Api; - $api->setEmail('email@example.com'); - $this->assertEquals('email@example.com', $api->email); - } - - public function testSetCurlOption() - { - $api = new Api; - $api->setCurlOption(CURLOPT_TIMEOUT, 5); - $this->assertEquals(5, $api->curl_options[CURLOPT_TIMEOUT]); - } - - public function testHttpNoCredentials() - { - $http = new Api(); - try { - $http->get('test'); - $this->fail("Expected exception not thrown"); - } catch(Exception $e) { - $this->assertEquals("Authentication information must be provided", $e->getMessage()); - } - } - - public function testHttpGetMethodSet() { - $api = new Api('email@example.com', 'Auth Key'); - $result = $api->get('test'); - $this->assertEquals("get", $result['method']); - } - - public function testHttpPostMethodSet() { - $api = new Api('email@example.com', 'Auth Key'); - $result = $api->post('test'); - $this->assertEquals("post", $result['method']); - } - - public function testHttpPutMethodSet() { - $api = new Api('email@example.com', 'Auth Key'); - $result = $api->put('test'); - $this->assertEquals("put", $result['method']); - } - - public function testHttpPatchMethodSet() { - $api = new Api('email@example.com', 'Auth Key'); - $result = $api->patch('test'); - $this->assertEquals("patch", $result['method']); - } - - public function testHttpDeleteMethodSet() { - $api = new Api('email@example.com', 'Auth Key'); - $result = $api->delete('test'); - $this->assertEquals("delete", $result['method']); - } - - public function testHttpRequest() { - $reflectionClass = new ReflectionClass('\\JamesryanBell\Cloudflare\\Api'); - $method = $reflectionClass->getMethod('request'); - $method->setAccessible(true); - - $api = new Api('email@example.com', 'Auth Key'); - $result = $method->invoke($api, 'test'); - - $this->assertEquals('get', $result['method']); - } - -} \ No newline at end of file +class ApiTest extends \PHPUnit_Framework_TestCase +{ + public function testApiClassFound() + { + $api = new Api(); + $this->assertTrue((bool) $api); + } + + public function testApiInitialised() + { + $api = new Api('email@example.com', 'Auth Key'); + $this->assertEquals('email@example.com', $api->email); + $this->assertEquals('Auth Key', $api->authKey); + } + + public function testApiInitialisedFromPreviousObject() + { + $client = new Api('email@example.com', 'Auth Key'); + $api = new Api($client); + $this->assertEquals('email@example.com', $api->email); + $this->assertEquals('Auth Key', $api->authKey); + } + + public function testSetAuthKey() + { + $api = new Api(); + $api->setAuthKey('Auth Key'); + $this->assertEquals('Auth Key', $api->authKey); + } + + public function testSetEmail() + { + $api = new Api(); + $api->setEmail('email@example.com'); + $this->assertEquals('email@example.com', $api->email); + } + + public function testSetCurlOption() + { + $api = new Api(); + $api->setCurlOption(CURLOPT_TIMEOUT, 5); + $this->assertEquals(5, $api->curlOptions[CURLOPT_TIMEOUT]); + } + + public function testHttpNoCredentials() + { + $http = new Api(); + try { + $http->get('test'); + $this->fail('Expected exception not thrown'); + } catch (\Exception $e) { + $this->assertEquals('Authentication information must be provided', $e->getMessage()); + } + } + + public function testHttpGetMethodSet() + { + $api = new Api('email@example.com', 'Auth Key'); + $result = $api->get('test'); + $this->assertEquals('get', $result['method']); + } + + public function testHttpPostMethodSet() + { + $api = new Api('email@example.com', 'Auth Key'); + $result = $api->post('test'); + $this->assertEquals('post', $result['method']); + } + + public function testHttpPutMethodSet() + { + $api = new Api('email@example.com', 'Auth Key'); + $result = $api->put('test'); + $this->assertEquals('put', $result['method']); + } + + public function testHttpPatchMethodSet() + { + $api = new Api('email@example.com', 'Auth Key'); + $result = $api->patch('test'); + $this->assertEquals('patch', $result['method']); + } + + public function testHttpDeleteMethodSet() + { + $api = new Api('email@example.com', 'Auth Key'); + $result = $api->delete('test'); + $this->assertEquals('delete', $result['method']); + } + + public function testHttpRequest() + { + $reflectionClass = new \ReflectionClass('\\JamesryanBell\Cloudflare\\Api'); + $method = $reflectionClass->getMethod('request'); + $method->setAccessible(true); + + $api = new Api('email@example.com', 'Auth Key'); + $result = $method->invoke($api, 'test'); + + $this->assertEquals('get', $result['method']); + } +} From d4d9ea4397d915a921dd86919b22bb15696e5d2e Mon Sep 17 00:00:00 2001 From: Thomas Dutrion Date: Sat, 15 Aug 2015 10:19:56 +0100 Subject: [PATCH 2/4] Update travis configuration to remove PHP5.3 support (EOL for a while already) --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7676a8c..135aaca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 From bce2ab4829903b7ce15bd0911cc6da7db0b8384b Mon Sep 17 00:00:00 2001 From: Thomas Dutrion Date: Sun, 16 Aug 2015 17:09:36 +0100 Subject: [PATCH 3/4] Update namespaces (missing last directory) --- src/Api.php | 9 ++++++--- src/User/User.php | 4 +++- src/Zone/Cache/Cache.php | 6 +++--- src/Zone/CustomPages/CustomPages.php | 4 ++-- src/Zone/Dns/Dns.php | 4 ++-- src/Zone/KeylessSSL/KeylessSSL.php | 4 ++-- src/Zone/Plan/Plan.php | 4 ++-- src/Zone/Railgun/Railgun.php | 4 ++-- src/Zone/SSL/SSL.php | 5 ++--- src/Zone/Settings/Settings.php | 4 ++-- src/Zone/Zone.php | 2 +- tests/ApiTest.php | 2 +- 12 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Api.php b/src/Api.php index e5cb203..26133b1 100644 --- a/src/Api.php +++ b/src/Api.php @@ -150,9 +150,12 @@ public function patch($path, array $data = []) */ public function setPermissions() { - if (!$this->permissions) { - $api = new User($this->email, $this->authKey); - $user = $api->user(); + if ($this->permissions) { + return $this->permissions; + } + $api = new User($this->email, $this->authKey); + $user = $api->user(); + if (isset($user->result->organisations) && count() > 0) { $this->permissions = $user->result->organizations[0]->permissions; } diff --git a/src/User/User.php b/src/User/User.php index 31b9351..c9bcccb 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -1,6 +1,8 @@ $purgeEverything, diff --git a/src/Zone/CustomPages/CustomPages.php b/src/Zone/CustomPages/CustomPages.php index 903af55..8dc93a5 100644 --- a/src/Zone/CustomPages/CustomPages.php +++ b/src/Zone/CustomPages/CustomPages.php @@ -1,8 +1,8 @@ Date: Sun, 16 Aug 2015 18:03:52 +0100 Subject: [PATCH 4/4] Fix namespaces problems --- src/Api.php | 5 +++-- src/Zone/Zone.php | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Api.php b/src/Api.php index 26133b1..69eb834 100644 --- a/src/Api.php +++ b/src/Api.php @@ -3,6 +3,7 @@ namespace JamesRyanBell\Cloudflare; use Exception; +use JamesRyanBell\Cloudflare\User\User; /** * CloudFlare API wrapper. @@ -155,7 +156,7 @@ public function setPermissions() } $api = new User($this->email, $this->authKey); $user = $api->user(); - if (isset($user->result->organisations) && count() > 0) { + if (isset($user->result->organisations) && count($user->result->organisations) > 0) { $this->permissions = $user->result->organizations[0]->permissions; } @@ -186,7 +187,7 @@ protected function request($path, array $data = [], $method = 'get', $permission if (!$this->permissions) { $this->setPermissions(); } - if (!isset($this->permissions) || !in_array($this->permissionLevel[$permissionLevel], $this->permissions)) { + if ($this->permissions && !in_array($this->permissionLevel[$permissionLevel], $this->permissions)) { throw new Exception('You do not have permission to perform this request'); } } diff --git a/src/Zone/Zone.php b/src/Zone/Zone.php index a1de524..c45a8b1 100644 --- a/src/Zone/Zone.php +++ b/src/Zone/Zone.php @@ -2,6 +2,8 @@ namespace JamesRyanBell\Cloudflare\Zone; +use JamesRyanBell\Cloudflare\Api; + /** * CloudFlare API wrapper. *