From 2881ee4c8fe55cf4bf8b5751a31e6da3ee608acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BB=A5=E8=BE=BE?= <> Date: Thu, 12 Sep 2019 08:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Einterface=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=B9=E6=B3=95return=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Acl.php | 126 ++++++++++++------ src/Agent.php | 84 ++++++++---- src/Catalog.php | 27 ++-- src/Connect.php | 33 +++-- src/ConsulConfig.php | 15 ++- src/ConsulInterface/AclInterface.php | 111 +++++++++++++++ src/ConsulInterface/AgentInterface.php | 90 +++++++++++++ src/ConsulInterface/CatalogInterface.php | 36 +++++ src/ConsulInterface/ConnectInterface.php | 35 +++++ src/ConsulInterface/ConsulConfigInterface.php | 21 +++ src/ConsulInterface/CoordinatesInterface.php | 24 ++++ src/ConsulInterface/EventInterface.php | 18 +++ src/ConsulInterface/HealthInterface.php | 27 ++++ src/ConsulInterface/KVStoreInterface.php | 21 +++ src/ConsulInterface/OperatorInterface.php | 57 ++++++++ src/ConsulInterface/QueryInterface.php | 27 ++++ src/ConsulInterface/SessionInterface.php | 30 +++++ src/ConsulInterface/SnapshotInterface.php | 17 +++ src/ConsulInterface/StatusInterface.php | 18 +++ src/ConsulInterface/TransactionInterface.php | 15 +++ src/Coordinates.php | 17 ++- src/Event.php | 9 +- src/Health.php | 18 ++- src/KVStore.php | 15 ++- src/Operator.php | 61 ++++++--- src/Query.php | 21 ++- src/Session.php | 21 ++- src/Snapshot.php | 9 +- src/Status.php | 9 +- src/Transaction.php | 6 +- tests/StatusTest.php | 4 +- 31 files changed, 861 insertions(+), 161 deletions(-) create mode 100644 src/ConsulInterface/AclInterface.php create mode 100644 src/ConsulInterface/AgentInterface.php create mode 100644 src/ConsulInterface/CatalogInterface.php create mode 100644 src/ConsulInterface/ConnectInterface.php create mode 100644 src/ConsulInterface/ConsulConfigInterface.php create mode 100644 src/ConsulInterface/CoordinatesInterface.php create mode 100644 src/ConsulInterface/EventInterface.php create mode 100644 src/ConsulInterface/HealthInterface.php create mode 100644 src/ConsulInterface/KVStoreInterface.php create mode 100644 src/ConsulInterface/OperatorInterface.php create mode 100644 src/ConsulInterface/QueryInterface.php create mode 100644 src/ConsulInterface/SessionInterface.php create mode 100644 src/ConsulInterface/SnapshotInterface.php create mode 100644 src/ConsulInterface/StatusInterface.php create mode 100644 src/ConsulInterface/TransactionInterface.php diff --git a/src/Acl.php b/src/Acl.php index ae281cd..7ed4781 100644 --- a/src/Acl.php +++ b/src/Acl.php @@ -7,6 +7,7 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\AclInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Acl\AuthMethod; use EasySwoole\Consul\Request\Acl\AuthMethods; @@ -32,48 +33,52 @@ use EasySwoole\Consul\Request\Acl\Translate; use EasySwoole\Consul\Request\Acl\Update; -class Acl extends BaseFunc +class Acl extends BaseFunc implements AclInterface { /** * Bootstrap ACLs * @param Bootstrap $bootstrap + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function bootstrap(Bootstrap $bootstrap) { - $this->putJSON($bootstrap); + return $this->putJSON($bootstrap); } /** * Check ACL Replication * @param Replication $replication + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function replication(Replication $replication) { - $this->getJson($replication); + return $this->getJson($replication); } /** * Translate Rules * @param Translate $translate + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ - public function translate (Translate $translate) + public function translate(Translate $translate) { if ($translate->getAccessorId()) { $translate->setUrl(sprintf($translate->getUrl(), $translate->getAccessorId())); $translate->setAccessorId(''); - $this->getJson($translate); + return $this->getJson($translate); } else { $translate->setUrl(substr($translate->getUrl(), 0, strlen($translate->getUrl()) -3)); - $this->postJson($translate); + return $this->postJson($translate); } } /** * Login to Auth Method * @param Login $login + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -85,12 +90,13 @@ public function login(Login $login) if (empty($login->getBearerToken())) { throw new MissingRequiredParamsException('Missing the required param: BearerToken.'); } - $this->postJson($login); + return $this->postJson($login); } /** * Logout from Auth Method * @param Logout $logout + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function logout(Logout $logout) @@ -99,23 +105,25 @@ public function logout(Logout $logout) 'X-Consul-Token' => $logout->getToken(), ); $logout->setToken(''); - $this->postJson($logout, $header); + return $this->postJson($logout, $header); } /** * Create a Token OR Read a Token OR Update a Token * @param Token $token + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function token(Token $token) { $token->setUrl(substr($token->getUrl(), 0, strlen($token->getUrl()) -3)); - $this->putJSON($token); + return $this->putJSON($token); } /** * Read a Token * @param Token $token + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -126,12 +134,13 @@ public function readToken(Token $token) } $token->setUrl(sprintf($token->getUrl(), $token->getAccessorId())); $token->setAccessorId(''); - $this->getJson($token); + return $this->getJson($token); } /** * Read Self Token * @param GetSelf $getSelf + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function self(GetSelf $getSelf) @@ -140,28 +149,30 @@ public function self(GetSelf $getSelf) 'X-Consul-Token' => $getSelf->getToken(), ); $getSelf->setToken(''); - $this->getJson($getSelf, $header); + return $this->getJson($getSelf, $header); } /** * Update a Token * @param Token $token + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ - public function updateToken (Token $token) + public function updateToken(Token $token) { if (empty($token->getAccessorID())) { throw new MissingRequiredParamsException('Missing the required param: AccessorID.'); } $token->setUrl(sprintf($token->getUrl(), $token->getAccessorId())); $token->setAccessorId(''); - $this->putJSON($token); + return $this->putJSON($token); } /** * Clone a Token * @param CloneToken $cloneToken + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -172,12 +183,13 @@ public function cloneToken(CloneToken $cloneToken) } $cloneToken->setUrl(sprintf($cloneToken->getUrl(), $cloneToken->getAccessorId())); $cloneToken->setAccessorId(''); - $this->putJSON($cloneToken); + return $this->putJSON($cloneToken); } /** * Delete a Token * @param Token $token + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -188,32 +200,35 @@ public function delete(Token $token) } $token->setUrl(sprintf($token->getUrl(), $token->getAccessorId())); $token->setAccessorId(''); - $this->deleteJson($token); + return $this->deleteJson($token); } /** * List Tokens * @param Tokens $tokens + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function tokens(Tokens $tokens) { - $this->getJson($tokens); + return $this->getJson($tokens); } /** * Create ACL Token * @param Create $create + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function create(Create $create) { - $this->putJSON($create); + return $this->putJSON($create); } /** * Update ACL Token * @param Update $update + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -222,12 +237,13 @@ public function update(Update $update) if (empty($update->getId())) { throw new MissingRequiredParamsException('Missing the required param: ID.'); } - $this->putJSON($update); + return $this->putJSON($update); } /** * Delete ACL Token * @param Destroy $destroy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -238,12 +254,13 @@ public function destroy(Destroy $destroy) } $destroy->setUrl(sprintf($destroy->getUrl(), $destroy->getUuid())); $destroy->setUuid(''); - $this->putJSON($destroy); + return $this->putJSON($destroy); } /** * Read ACL Token * @param Info $info + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -254,12 +271,13 @@ public function info(Info $info) } $info->setUrl(sprintf($info->getUrl(), $info->getUuid())); $info->setUuid(''); - $this->getJson($info); + return $this->getJson($info); } /** * Clone ACL Token * @param CloneACLToken $cloneACLToken + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -270,22 +288,24 @@ public function cloneAclToken(CloneACLToken $cloneACLToken) } $cloneACLToken->setUrl(sprintf($cloneACLToken->getUrl(), $cloneACLToken->getUuid())); $cloneACLToken->setUuid(''); - $this->putJSON($cloneACLToken); + return $this->putJSON($cloneACLToken); } /** * List ACLs * @param Lists $lists + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function getList(Lists $lists) { - $this->getJson($lists); + return $this->getJson($lists); } /** * Create a Policy * @param Policy $policy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -295,12 +315,13 @@ public function policy(Policy $policy) throw new MissingRequiredParamsException('Missing the required param: Name.'); } $policy->setUrl(substr($policy->getUrl(), 0, strlen($policy->getUrl()) -3)); - $this->putJSON($policy); + return $this->putJSON($policy); } /** * Read a Policy * @param Policy $policy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -311,12 +332,13 @@ public function readPolicy(Policy $policy) } $policy->setUrl(sprintf($policy->getUrl(), $policy->getId())); $policy->setId(''); - $this->getJson($policy); + return $this->getJson($policy); } /** * Update a Policy * @param Policy $policy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -329,13 +351,14 @@ public function updatePolicy(Policy $policy) throw new MissingRequiredParamsException('Missing the required param: Name.'); } $policy->setUrl(substr($policy->getUrl(), 0, strlen($policy->getUrl()) -3)); - $this->putJSON($policy); + return $this->putJSON($policy); } /** * Delete a Policy * @param Policy $policy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -346,22 +369,24 @@ public function deletePolicy(Policy $policy) } $policy->setUrl(sprintf($policy->getUrl(), $policy->getId())); $policy->setId(''); - $this->deleteJson($policy); + return $this->deleteJson($policy); } /** * List Policies * @param Policies $policies + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function policies (Policies $policies) { - $this->getJson($policies); + return $this->getJson($policies); } /** * Create a Role * @param Role $role + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -371,12 +396,13 @@ public function role(Role $role) throw new MissingRequiredParamsException('Missing the required param: Name.'); } $role->setUrl(substr($role->getUrl(), 0, strlen($role->getUrl()) -3)); - $this->putJSON($role); + return $this->putJSON($role); } /** * Read a Role * @param Role $role + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -387,12 +413,13 @@ public function readRole(Role $role) } $role->setUrl(sprintf($role->getUrl(), $role->getId())); $role->setId(''); - $this->getJson($role); + return $this->getJson($role); } /** * Read a Role by Name * @param Role $role + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -403,12 +430,13 @@ public function readRoleByName(Role $role) } $role->setUrl(sprintf($role->getUrl(), 'name/' . $role->getName())); $role->setName(''); - $this->getJson($role); + return $this->getJson($role); } /** * Update a Role * @param Role $role + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -421,12 +449,13 @@ public function updateRole(Role $role) throw new MissingRequiredParamsException('Missing the required param: Name.'); } $role->setUrl(sprintf($role->getUrl(), $role->getId())); - $this->putJSON($role); + return $this->putJSON($role); } /** * Delete a Role * @param Role $role + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -437,22 +466,24 @@ public function deleteRole(Role $role) } $role->setUrl(sprintf($role->getUrl(), $role->getId())); $role->setId(''); - $this->deleteJson($role); + return $this->deleteJson($role); } /** * List Roles * @param Roles $roles + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function roles(Roles $roles) { - $this->getJson($roles); + return $this->getJson($roles); } /** * Create an Auth Method * @param AuthMethod $authMethod + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -465,12 +496,13 @@ public function authMethod(AuthMethod $authMethod) throw new MissingRequiredParamsException('Missing the required param: Type.'); } $authMethod->setUrl(substr($authMethod->getUrl(), 0, strlen($authMethod->getUrl()) -3)); - $this->putJSON($authMethod); + return $this->putJSON($authMethod); } /** * Read an Auth Method * @param AuthMethod $authMethod + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -481,12 +513,13 @@ public function readAuthMethod(AuthMethod $authMethod) } $authMethod->setUrl(sprintf($authMethod->getUrl(), $authMethod->getName())); $authMethod->setName(''); - $this->getJson($authMethod); + return $this->getJson($authMethod); } /** * Update an Auth Method * @param AuthMethod $authMethod + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -499,12 +532,13 @@ public function updateAuthMethod(AuthMethod $authMethod) throw new MissingRequiredParamsException('Missing the required param: Type.'); } $authMethod->setUrl(sprintf($authMethod->getUrl(), $authMethod->getName())); - $this->putJSON($authMethod); + return $this->putJSON($authMethod); } /** * Delete an Auth Method * @param AuthMethod $authMethod + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -515,22 +549,24 @@ public function deleteAuthMethod(AuthMethod $authMethod) } $authMethod->setUrl(sprintf($authMethod->getUrl(), $authMethod->getName())); $authMethod->setName(''); - $this->deleteJson($authMethod); + return $this->deleteJson($authMethod); } /** * List Auth Methods * @param AuthMethods $authMethods + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function authMethods(AuthMethods $authMethods) { - $this->getJson($authMethods); + return $this->getJson($authMethods); } /** * Create a Binding Rule * @param BindingRule $bindingRule + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -547,12 +583,13 @@ public function bindingRule(BindingRule $bindingRule) } $bindingRule->setUrl(substr($bindingRule->getUrl(), 0, strlen($bindingRule->getUrl()) -3)); - $this->putJSON($bindingRule); + return $this->putJSON($bindingRule); } /** * Read a Binding Rule * @param BindingRule $bindingRule + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -563,12 +600,13 @@ public function readBindingRule(BindingRule $bindingRule) } $bindingRule->setUrl(sprintf($bindingRule->getUrl(), $bindingRule->getId())); $bindingRule->setId(''); - $this->getJson($bindingRule); + return $this->getJson($bindingRule); } /** * Update a Binding Rule * @param BindingRule $bindingRule + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -588,12 +626,13 @@ public function updateBindingRule(BindingRule $bindingRule) } $bindingRule->setUrl(sprintf($bindingRule->getUrl(), $bindingRule->getId())); $bindingRule->setId(''); - $this->putJSON($bindingRule); + return $this->putJSON($bindingRule); } /** * Delete a Binding Rule * @param BindingRule $bindingRule + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -604,16 +643,17 @@ public function deleteBindingRule(BindingRule $bindingRule) } $bindingRule->setUrl(sprintf($bindingRule->getUrl(), $bindingRule->getId())); $bindingRule->setId(''); - $this->deleteJson($bindingRule); + return $this->deleteJson($bindingRule); } /** * List Binding Rules * @param BindingRules $bindingRules + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function bindingRules(BindingRules $bindingRules) { - $this->getJson($bindingRules); + return $this->getJson($bindingRules); } } \ No newline at end of file diff --git a/src/Agent.php b/src/Agent.php index 1028fbd..9fc5eab 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -1,6 +1,7 @@ getJson($members); + return $this->getJson($members); } /** * Read Configuration * @param SelfParams $selfParams + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function self(SelfParams $selfParams) { - $this->getJson($selfParams); + return $this->getJson($selfParams); } /** * reload configuration * @param Reload $reload + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function reload(Reload $reload) { - $this->putJSON($reload); + return $this->putJSON($reload); } /** * Enable Maintenance Mode * @param Maintenance $maintenance + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -71,7 +76,7 @@ public function maintenance(Maintenance $maintenance) if (empty($maintenance->getEnable())) { throw new MissingRequiredParamsException('Missing the required param: enable.'); } - $this->putJSON($maintenance , false); + return $this->putJSON($maintenance , false); } /** @@ -79,26 +84,29 @@ public function maintenance(Maintenance $maintenance) * if format be set,the format set prometheus automatically, * and the return is text/plain; version=0.0.4; charset=utf-8 * @param Metrics $metrics + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function metrics(Metrics $metrics) { - $this->getJson($metrics); + return $this->getJson($metrics); } /** * Stream Logs * @param Monitor $monitor + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function monitor(Monitor $monitor) { - $this->getJson($monitor); + return $this->getJson($monitor); } /** * Join Agent * @param Join $join + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -109,22 +117,24 @@ public function join(Join $join) } $join->setUrl(sprintf($join->getUrl(), $join->getAddress())); $join->setAddress(''); - $this->putJSON($join); + return $this->putJSON($join); } /** * graceful leave and shutdown of the agent * @param Leave $leave + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function leave(Leave $leave) { - $this->putJSON($leave); + return $this->putJSON($leave); } /** * Force Leave and Shutdown * @param ForceLeave $forceLeave + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -136,12 +146,13 @@ public function forceLeave(ForceLeave $forceLeave) } $forceLeave->setUrl(sprintf($forceLeave->getUrl(), $forceLeave->getNode())); $forceLeave->setNode(''); - $this->putJSON($forceLeave); + return $this->putJSON($forceLeave); } /** * Update ACL Tokens * @param Token $token + * @return mixed * @throws MissingRequiredParamsException * @throws InvalidRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl @@ -166,22 +177,24 @@ public function token(Token $token) } $token->setUrl(sprintf($token->getUrl(), $token->getAction())); $token->setAction(''); - $this->putJSON($token); + return $this->putJSON($token); } /** * List Checks * @param Checks $checks + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function checks(Checks $checks) { - $this->getJson($checks); + return $this->getJson($checks); } /** * Register Check * @param Register $register + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -193,12 +206,13 @@ public function register(Register $register) if (empty($register->getTTL())) { throw new MissingRequiredParamsException('Missing the required param: TTL.'); } - $this->putJSON($register); + return $this->putJSON($register); } /** * Deregister Check * @param DeRegister $deregister + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -209,12 +223,13 @@ public function deRegister(DeRegister $deregister) } $deregister->setUrl(sprintf($deregister->getUrl(), $deregister->getCheckId())); $deregister->setCheckId(''); - $this->putJSON($deregister); + return $this->putJSON($deregister); } /** * TTL Check Pass * @param Pass $pass + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -225,12 +240,13 @@ public function pass(Pass $pass) } $pass->setUrl(sprintf($pass->getUrl(), $pass->getCheckId())); $pass->setCheckId(''); - $this->putJSON($pass); + return $this->putJSON($pass); } /** * TTL Check Warn * @param Warn $warn + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -241,12 +257,13 @@ public function warn(Warn $warn) } $warn->setUrl(sprintf($warn->getUrl(), $warn->getCheckId())); $warn->setCheckId(''); - $this->putJSON($warn); + return $this->putJSON($warn); } /** * TTL Check Fail * @param Fail $fail + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -257,12 +274,13 @@ public function fail(Fail $fail) } $fail->setUrl(sprintf($fail->getUrl(), $fail->getCheckId())); $fail->setCheckId(''); - $this->putJSON($fail); + return $this->putJSON($fail); } /** * TTL Check Update * @param Update $update + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -273,22 +291,24 @@ public function update(Update $update) } $update->setUrl(sprintf($update->getUrl(), $update->getCheckId())); $update->setCheckId(''); - $this->putJSON($update); + return $this->putJSON($update); } /** * List Services * @param Services $services + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function services(Services $services) { - $this->getJson($services); + return $this->getJson($services); } /** * Get Service Configuration * @param Service $service + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -299,12 +319,13 @@ public function service(Service $service) } $service->setUrl(sprintf($service->getUrl(), $service->getServiceId())); $service->setServiceId(''); - $this->getJson($service); + return $this->getJson($service); } /** * Get local service health by its name * @param Name $name + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -315,12 +336,13 @@ public function name(Name $name) } $name->setUrl(sprintf($name->getUrl(), $name->getServiceName())); $name->setServiceName(''); - $this->getJson($name); + return $this->getJson($name); } /** * Get local service health by its ID * @param ID $ID + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -331,12 +353,13 @@ public function id(ID $ID) } $ID->setUrl(sprintf($ID->getUrl(), $ID->getServiceID())); $ID->setServiceID(''); - $this->getJson($ID); + return $this->getJson($ID); } /** * Register Service * @param Service\Register $register + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -345,12 +368,13 @@ public function serviceRegister(Service\Register $register) if (empty($register->getName())) { throw new MissingRequiredParamsException('Missing the required param: Name.'); } - $this->putJSON($register); + return $this->putJSON($register); } /** * Deregister Service * @param Service\DeRegister $deregister + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -361,12 +385,13 @@ public function serviceDeregister(Service\DeRegister $deregister) } $deregister->setUrl(sprintf($deregister->getUrl(), $deregister->getServiceID())); $deregister->setServiceID(''); - $this->putJSON($deregister); + return $this->putJSON($deregister); } /** * Enable Maintenance Mode * @param Service\Maintenance $maintenance + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -380,12 +405,13 @@ public function serviceMaintenance(Service\Maintenance $maintenance) } $maintenance->setUrl(sprintf($maintenance->getUrl(), $maintenance->getServiceID())); $maintenance->setServiceID(''); - $this->putJSON($maintenance); + return $this->putJSON($maintenance); } /** * Authorize * @param Authorize $authorize + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -400,22 +426,24 @@ public function authorize(Authorize $authorize) if (empty($authorize->getClientCertSerial())) { throw new MissingRequiredParamsException('Missing the required param: ClientCertSerial.'); } - $this->postJson($authorize); + return $this->postJson($authorize); } /** * Certificate Authority (CA) Roots * @param Roots $roots + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function roots(Roots $roots) { - $this->getJson($roots); + return $this->getJson($roots); } /** * Service Leaf Certificate * @param Leaf $leaf + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -426,6 +454,6 @@ public function leaf(Leaf $leaf) } $leaf->setUrl(sprintf($leaf->getUrl(), $leaf->getService())); $leaf->setService(''); - $this->getJson($leaf); + return $this->getJson($leaf); } } \ No newline at end of file diff --git a/src/Catalog.php b/src/Catalog.php index d0e8bb0..4d979d5 100644 --- a/src/Catalog.php +++ b/src/Catalog.php @@ -1,6 +1,7 @@ getAddress())) { throw new MissingRequiredParamsException('Missing the required param: Address.'); } - $this->putJSON($register); + return $this->putJSON($register); } /** * Deregister Entity * @param Deregister $deregister + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -42,42 +45,46 @@ public function deRegister(Deregister $deregister) if (empty($deregister->getNode())) { throw new MissingRequiredParamsException('Missing the required param: Node.'); } - $this->putJSON($deregister); + return $this->putJSON($deregister); } /** * List Datacenters * @param Datacenters $datacenters + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function dataCenters(Datacenters $datacenters) { - $this->getJson($datacenters); + return $this->getJson($datacenters); } /** * List Nodes * @param Nodes $nodes + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function nodes(Nodes $nodes) { - $this->getJson($nodes); + return $this->getJson($nodes); } /** * List Services * @param Services $services + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function services(Services $services) { - $this->getJson($services); + return $this->getJson($services); } /** * List Nodes for service * @param Service $service + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -88,12 +95,13 @@ public function service(Service $service) } $service->url = sprintf($service->url, $service->getService()); $service->setService(''); - $this->getJson($service); + return $this->getJson($service); } /** * List Nodes for Connect-capable Service * @param Connect $connect + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -104,12 +112,13 @@ public function connect(Connect $connect) } $connect->url = sprintf($connect->url, $connect->getService()); $connect->setService(''); - $this->getJson($connect); + return $this->getJson($connect); } /** * List Services for Node * @param Node $node + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -120,6 +129,6 @@ public function node(Node $node) } $node->url = sprintf($node->url, $node->getNode()); $node->setNode(''); - $this->getJson($node); + return $this->getJson($node); } } \ No newline at end of file diff --git a/src/Connect.php b/src/Connect.php index cf28e06..b64bca2 100644 --- a/src/Connect.php +++ b/src/Connect.php @@ -8,6 +8,7 @@ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\ConnectInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Connect\Ca\Configuration; use EasySwoole\Consul\Request\Connect\Ca\Roots; @@ -15,31 +16,34 @@ use EasySwoole\Consul\Request\Connect\Intentions\Check; use EasySwoole\Consul\Request\Connect\Intentions\Match; -class Connect extends BaseFunc +class Connect extends BaseFunc implements ConnectInterface { /** * List CA Root Certificates * @param Roots $roots + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function roots(Roots $roots) { - $this->getJson($roots); + return $this->getJson($roots); } /** * Get CA Configuration * @param Configuration $configuration + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function configuration(Configuration $configuration) { - $this->getJson($configuration); + return $this->getJson($configuration); } /** * Update CA Configuration * @param Configuration $configuration + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -51,12 +55,13 @@ public function updateConfiguration(Configuration $configuration) if (empty($configuration->getConfig())) { throw new MissingRequiredParamsException('Missing the required param: Config.'); } - $this->putJSON($configuration); + return $this->putJSON($configuration); } /** * Create Intention * @param Intentions $intentions + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -75,12 +80,13 @@ public function intentions(Intentions $intentions) throw new MissingRequiredParamsException('Missing the required param: Action.'); } $intentions->setUrl(substr($intentions->getUrl(), 0, strlen($intentions->getUrl()) -3)); - $this->postJson($intentions); + return $this->postJson($intentions); } /** * Read Specific Intention * @param Intentions $intentions + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -91,23 +97,25 @@ public function readIntention(Intentions $intentions) } $intentions->setUrl(sprintf($intentions->getUrl(), $intentions->getUuid())); $intentions->setUuid(''); - $this->getJson($intentions); + return $this->getJson($intentions); } /** * List Intentions * @param Intentions $intentions + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function listIntention(Intentions $intentions) { $intentions->setUrl(substr($intentions->getUrl(), 0, strlen($intentions->getUrl()) -3)); - $this->getJson($intentions); + return $this->getJson($intentions); } /** * Update Intention * @param Intentions $intentions + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -118,12 +126,13 @@ public function updateIntention(Intentions $intentions) } $intentions->setUrl(sprintf($intentions->getUrl(), $intentions->getUuid())); $intentions->setUuid(''); - $this->putJSON($intentions); + return $this->putJSON($intentions); } /** * Delete Intention * @param Intentions $intentions + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -134,12 +143,13 @@ public function deleteIntention(Intentions $intentions) } $intentions->setUrl(sprintf($intentions->getUrl(), $intentions->getUuid())); $intentions->setUuid(''); - $this->deleteJson($intentions); + return $this->deleteJson($intentions); } /** * Check Intention Result * @param Check $check + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -151,12 +161,13 @@ public function check(Check $check) if (empty($check->getDestination())) { throw new MissingRequiredParamsException('Missing the required param: destination.'); } - $this->getJson($check); + return $this->getJson($check); } /** * List Matching Intentions * @param Match $match + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -168,6 +179,6 @@ public function match(Match $match) if (empty($match->getName())) { throw new MissingRequiredParamsException('Missing the required param: name.'); } - $this->getJson($match); + return $this->getJson($match); } } \ No newline at end of file diff --git a/src/ConsulConfig.php b/src/ConsulConfig.php index 90ff110..886cdf2 100644 --- a/src/ConsulConfig.php +++ b/src/ConsulConfig.php @@ -7,25 +7,28 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\ConsulConfigInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Config; -class ConsulConfig extends BaseFunc +class ConsulConfig extends BaseFunc implements ConsulConfigInterface { /** * Apply Configuration * @param Config $config + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function config(Config $config) { $config->setUrl(substr($config->getUrl(), 0, strlen($config->getUrl()) -3)); - $this->putJSON($config); + return $this->putJSON($config); } /** * Get Configuration * @param Config $config + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -40,12 +43,13 @@ public function getConfig(Config $config) $config->setUrl(sprintf($config->getUrl(), $config->getKind() . '/' . $config->getName())); $config->setKind(''); $config->setName(''); - $this->getJson($config); + return $this->getJson($config); } /** * List Configurations * @param Config $config + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -56,12 +60,13 @@ public function listConfig(Config $config) } $config->setUrl(sprintf($config->getUrl(), $config->getKind())); $config->setKind(''); - $this->getJson($config); + return $this->getJson($config); } /** * Delete Configuration * @param Config $config + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -76,6 +81,6 @@ public function deleteConfig(Config $config) $config->setUrl(sprintf($config->getUrl(), $config->getKind() . '/' . $config->getName())); $config->setKind(''); $config->setName(''); - $this->deleteJson($config); + return $this->deleteJson($config); } } \ No newline at end of file diff --git a/src/ConsulInterface/AclInterface.php b/src/ConsulInterface/AclInterface.php new file mode 100644 index 0000000..f5639cc --- /dev/null +++ b/src/ConsulInterface/AclInterface.php @@ -0,0 +1,111 @@ +getJson($datacenters); + return $this->getJson($datacenters); } /** * Read LAN Coordinates for all nodes * @param Nodes $nodes + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function nodes(Nodes $nodes) { - $this->getJson($nodes); + return $this->getJson($nodes); } /** * Read LAN Coordinates for a node * @param Node $node + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -48,23 +52,24 @@ public function node(Node $node) } $node->setUrl(sprintf($node->getUrl(), $node->getNode())); $node->setNode(''); - $this->getJson($node); + return $this->getJson($node); } /** * Update LAN Coordinates for a node * @param Update $update + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function update(Update $update) { if (empty($update->getDc())) { $update->setUrl(substr($update->getUrl(), 0, strlen($update->getUrl()) -3)); - $this->putJSON($update); + return $this->putJSON($update); } else { $update->setUrl(sprintf($update->getUrl(), '?dc=' . $update->getDc())); $update->setDc(''); - $this->putJSON($update); + return $this->putJSON($update); } } } \ No newline at end of file diff --git a/src/Event.php b/src/Event.php index 010ef51..b67b02f 100644 --- a/src/Event.php +++ b/src/Event.php @@ -7,15 +7,17 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\EventInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Event\Fire; use EasySwoole\Consul\Request\Event\ListEvent; -class Event extends BaseFunc +class Event extends BaseFunc implements EventInterface { /** * Fire Event * @param Fire $fire + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -26,12 +28,13 @@ public function fire(Fire $fire) } $fire->setUrl(sprintf($fire->getUrl(), $fire->getName())); $fire->setName(''); - $this->putJSON($fire); + return $this->putJSON($fire); } /** * List Events * @param ListEvent $listEvent + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -40,6 +43,6 @@ public function listEvent(ListEvent $listEvent) if (empty($listEvent->getName())) { throw new MissingRequiredParamsException('Missing the required param: Name.'); } - $this->getJson($listEvent); + return $this->getJson($listEvent); } } \ No newline at end of file diff --git a/src/Health.php b/src/Health.php index d682770..ca86394 100644 --- a/src/Health.php +++ b/src/Health.php @@ -1,6 +1,7 @@ setUrl(sprintf($node->getUrl(), $node->getNode())); $node->setNode(''); - $this->getJson($node); + return $this->getJson($node); } /** * List Checks for Service * @param Checks $checks + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -39,12 +42,13 @@ public function checks(Checks $checks) } $checks->setUrl(sprintf($checks->getUrl(), $checks->getService())); $checks->setService(''); - $this->getJson($checks); + return $this->getJson($checks); } /** * List Nodes for Service * @param Service $service + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -55,13 +59,14 @@ public function service(Service $service) } $service->setUrl(sprintf($service->getUrl(), $service->getService())); $service->setService(''); - $this->getJson($service); + return $this->getJson($service); } /** * List Nodes for Connect-capable Service * Parameters and response format are the same as Health/service * @param Connect $connect + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -72,12 +77,13 @@ public function connect(Connect $connect) } $connect->setUrl(sprintf($connect->getUrl(), $connect->getService())); $connect->setService(''); - $this->getJson($connect); + return $this->getJson($connect); } /** * List Checks in State * @param State $state + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -88,6 +94,6 @@ public function state(State $state) } $state->setUrl(sprintf($state->getUrl(), $state->getState())); $state->setState(''); - $this->getJson($state); + return $this->getJson($state); } } \ No newline at end of file diff --git a/src/KVStore.php b/src/KVStore.php index 8e777fb..731bd88 100644 --- a/src/KVStore.php +++ b/src/KVStore.php @@ -4,14 +4,16 @@ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\KVStoreInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Kv; -class KVStore extends BaseFunc +class KVStore extends BaseFunc implements KVStoreInterface { /** * Read Key * @param Kv $kv + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -22,12 +24,13 @@ public function kv(Kv $kv) } $kv->setUrl(sprintf($kv->getUrl(), $kv->getKey())); $kv->setKey(''); - $this->getJson($kv); + return $this->getJson($kv); } /** * Create Key * @param Kv $kv + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -38,12 +41,13 @@ public function create(Kv $kv) } $kv->setUrl(sprintf($kv->getUrl(), $kv->getKey())); $kv->setKey(''); - $this->putJSON($kv); + return $this->putJSON($kv); } /** * Update Key * @param Kv $kv + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -54,12 +58,13 @@ public function update(Kv $kv) } $kv->setUrl(sprintf($kv->getUrl(), $kv->getKey())); $kv->setKey(''); - $this->putJSON($kv); + return $this->putJSON($kv); } /** * Delete Key * @param Kv $kv + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -70,6 +75,6 @@ public function delete(Kv $kv) } $kv->setUrl(sprintf($kv->getUrl(), $kv->getKey())); $kv->setKey(''); - $this->deleteJson($kv); + return $this->deleteJson($kv); } } \ No newline at end of file diff --git a/src/Operator.php b/src/Operator.php index a99abd0..68c6437 100644 --- a/src/Operator.php +++ b/src/Operator.php @@ -7,8 +7,8 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\OperatorInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; -use EasySwoole\Consul\Request\Acl\Logout; use EasySwoole\Consul\Request\Operator\Area; use EasySwoole\Consul\Request\Operator\Autopilot\Configuration; use EasySwoole\Consul\Request\Operator\Autopilot\Health; @@ -18,22 +18,24 @@ use EasySwoole\Consul\Request\Operator\Raft\Peer; use EasySwoole\Consul\Request\Operator\Segment; -class Operator extends BaseFunc +class Operator extends BaseFunc implements OperatorInterface { /** * Create Network Area * @param Area $area + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function area(Area $area) { $area->setUrl(substr($area->getUrl(), 0, strlen($area->getUrl()) -3)); - $this->postJson($area); + return $this->postJson($area); } /** * List Network Areas OR List Specific Network Area * @param Area $area + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function areaList(Area $area) @@ -45,12 +47,13 @@ public function areaList(Area $area) $area->setUuid(''); } - $this->getJson($area); + return $this->getJson($area); } /** * Update Network Area * @param Area $area + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -61,12 +64,13 @@ public function updateArea(Area $area) } $area->setUrl(sprintf($area->getUrl(), $area->getUuid())); $area->setUuid(''); - $this->putJSON($area); + return $this->putJSON($area); } /** * Delete Network Area * @param Area $area + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -77,12 +81,13 @@ public function deleteArea(Area $area) } $area->setUrl(sprintf($area->getUrl(), $area->getUuid())); $area->setUuid(''); - $this->deleteJson($area); + return $this->deleteJson($area); } /** * Join Network Area * @param Area $area + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -93,12 +98,13 @@ public function joinArea(Area $area) } $area->setUrl(sprintf($area->getUrl(), $area->getUuid() . '/join')); $area->setUuid(''); - $this->getJson($area); + return $this->getJson($area); } /** * List Network Area Members * @param Area $area + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -109,52 +115,57 @@ public function membersArea(Area $area) } $area->setUrl(sprintf($area->getUrl(), $area->getUuid() . '/members')); $area->setUuid(''); - $this->getJson($area); + return $this->getJson($area); } /** * Read Configuration * @param Configuration $configuration + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function getConfiguration(Configuration $configuration) { - $this->getJson($configuration); + return $this->getJson($configuration); } /** * Update Configuration * @param Configuration $configuration + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function updateConfiguration(Configuration $configuration) { - $this->putJSON($configuration); + return $this->putJSON($configuration); } /** * Read Health * @param Health $health + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function health(Health $health) { - $this->getJson($health); + return $this->getJson($health); } /** * List Gossip Encryption Keys * @param Keyring $keyring + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function getKeyring(Keyring $keyring) { - $this->getJson($keyring); + return $this->getJson($keyring); } /** * Add New Gossip Encryption Key * @param Keyring $keyring + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -163,12 +174,13 @@ public function addKeyring(Keyring $keyring) if (empty($keyring->getKey())) { throw new MissingRequiredParamsException('Missing the required param: key.'); } - $this->postJson($keyring); + return $this->postJson($keyring); } /** * Change Primary Gossip Encryption Key * @param Keyring $keyring + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -177,12 +189,13 @@ public function changeKeyring(Keyring $keyring) if (empty($keyring->getKey())) { throw new MissingRequiredParamsException('Missing the required param: key.'); } - $this->putJSON($keyring); + return $this->putJSON($keyring); } /** * Delete Gossip Encryption Key * @param Keyring $keyring + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -191,59 +204,64 @@ public function deleteKeyring(Keyring $keyring) if (empty($keyring->getKey())) { throw new MissingRequiredParamsException('Missing the required param: key.'); } - $this->deleteJson($keyring); + return $this->deleteJson($keyring); } /** * Getting the Consul License * @param License $license + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function getLicense(License $license) { - $this->getJson($license); + return $this->getJson($license); } /** * Updating the Consul License * @param License $license + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function updateLicense(License $license) { - $this->putJSON($license); + return $this->putJSON($license); } /** * Resetting the Consul License * @param License $license + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function resetLicense(License $license) { - $this->deleteJson($license); + return $this->deleteJson($license); } /** * Read Configuration * @param raftConfig $configuration + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function getRaftConfiguration(raftConfig $configuration) { - $this->getJson($configuration); + return $this->getJson($configuration); } /** * Delete Raft Peer * @param Peer $peer + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function peer(Peer $peer) { if (! empty($peer->getId()) || ! empty($peer->getAddress())) { - $this->deleteJson($peer); + return $this->deleteJson($peer); } else { throw new MissingRequiredParamsException('Missing the required param: id or address.'); } @@ -252,10 +270,11 @@ public function peer(Peer $peer) /** * List Network Segments * @param Segment $segment + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function segment(Segment $segment) { - $this->getJson($segment); + return $this->getJson($segment); } } \ No newline at end of file diff --git a/src/Query.php b/src/Query.php index 48cd89f..7ba202f 100644 --- a/src/Query.php +++ b/src/Query.php @@ -7,26 +7,29 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\QueryInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Query\Execute; use EasySwoole\Consul\Request\Query\Explain; -class Query extends BaseFunc +class Query extends BaseFunc implements QueryInterface { /** * Create Prepared Query * @param Request\Query $query + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function query(\EasySwoole\Consul\Request\Query $query) { $query->setUrl(substr($query->getUrl(), 0, strlen($query->getUrl()) -3)); - $this->postJson($query); + return $this->postJson($query); } /** * Read Prepared Query * @param Request\Query $query + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function readQuery(\EasySwoole\Consul\Request\Query $query) @@ -37,12 +40,13 @@ public function readQuery(\EasySwoole\Consul\Request\Query $query) $query->setUrl(sprintf($query->getUrl(), $query->getUuid())); $query->setUuid(''); } - $this->getJson($query); + return $this->getJson($query); } /** * Update Prepared Query * @param Request\Query $query + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -53,12 +57,13 @@ public function updateQuery(\EasySwoole\Consul\Request\Query $query) } $query->setUrl(sprintf($query->getUrl(), $query->getUuid())); $query->setUuid(''); - $this->putJSON($query); + return $this->putJSON($query); } /** * Delete Prepared Query * @param Request\Query $query + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -69,12 +74,13 @@ public function deleteQuery(\EasySwoole\Consul\Request\Query $query) } $query->setUrl(sprintf($query->getUrl(), $query->getUuid())); $query->setUuid(''); - $this->deleteJson($query); + return $this->deleteJson($query); } /** * Execute Prepared Query * @param Execute $execute + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -85,12 +91,13 @@ public function execute(Execute $execute) } $execute->setUrl(sprintf($execute->getUrl(), $execute->getUuid())); $execute->setUuid(''); - $this->getJson($execute); + return $this->getJson($execute); } /** * Explain Prepared Query * @param Explain $explain + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -101,6 +108,6 @@ public function explain(Explain $explain) } $explain->setUrl(sprintf($explain->getUrl(), $explain->getUuid())); $explain->setUuid(''); - $this->getJson($explain); + return $this->getJson($explain); } } \ No newline at end of file diff --git a/src/Session.php b/src/Session.php index a0ca24f..a8c2f66 100644 --- a/src/Session.php +++ b/src/Session.php @@ -7,6 +7,7 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\SessionInterface; use EasySwoole\Consul\Exception\MissingRequiredParamsException; use EasySwoole\Consul\Request\Session\Create; use EasySwoole\Consul\Request\Session\Destroy; @@ -15,21 +16,23 @@ use EasySwoole\Consul\Request\Session\Renew; use EasySwoole\Consul\Request\Session\SessionList; -class Session extends BaseFunc +class Session extends BaseFunc implements SessionInterface { /** * Create Session * @param Create $create + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function create(Create $create) { - $this->putJSON($create); + return $this->putJSON($create); } /** * Delete Session * @param Destroy $destroy + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -40,12 +43,13 @@ public function destroy(Destroy $destroy) } $destroy->setUrl(sprintf($destroy->getUrl(), $destroy->getUuid())); $destroy->setUuid(''); - $this->putJSON($destroy); + return $this->putJSON($destroy); } /** * Read Session * @param Info $info + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -56,12 +60,13 @@ public function info(Info $info) } $info->setUrl(sprintf($info->getUrl(), $info->getUuid())); $info->setUuid(''); - $this->getJson($info); + return $this->getJson($info); } /** * List Sessions for Node * @param Node $node + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -72,22 +77,24 @@ public function node(Node $node) } $node->setUrl(sprintf($node->getUrl(), $node->getNode())); $node->setNode(''); - $this->getJson($node); + return $this->getJson($node); } /** * List Sessions * @param SessionList $sessionList + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function sessionList(SessionList $sessionList) { - $this->getJson($sessionList); + return $this->getJson($sessionList); } /** * Renew Session * @param Renew $renew + * @return mixed * @throws MissingRequiredParamsException * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ @@ -98,6 +105,6 @@ public function renew(Renew $renew) } $renew->setUrl(sprintf($renew->getUrl(), $renew->getUuid())); $renew->setUuid(''); - $this->putJSON($renew); + return $this->putJSON($renew); } } \ No newline at end of file diff --git a/src/Snapshot.php b/src/Snapshot.php index 490818e..0828f15 100644 --- a/src/Snapshot.php +++ b/src/Snapshot.php @@ -7,26 +7,29 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\SnapshotInterface; use EasySwoole\Consul\Request\Snapshot as snap; -class Snapshot extends BaseFunc +class Snapshot extends BaseFunc implements SnapshotInterface { /** * Generate Snapshot * @param snap $snapshot + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function generate(snap $snapshot) { - $this->getJson($snapshot); + return $this->getJson($snapshot); } /** * Restore Snapshot * @param snap $snapshot + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function restore(snap $snapshot) { - $this->putJSON($snapshot); + return $this->putJSON($snapshot); } } \ No newline at end of file diff --git a/src/Status.php b/src/Status.php index c4a7b3d..0fcd7e3 100644 --- a/src/Status.php +++ b/src/Status.php @@ -7,28 +7,31 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\StatusInterface; use EasySwoole\Consul\Request\Status\Leader; use EasySwoole\Consul\Request\Status\Peers; -class Status extends BaseFunc +class Status extends BaseFunc implements StatusInterface { /** * Get Raft Leader * @param Leader $leader + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function leader(Leader $leader) { - $this->getJson($leader); + return $this->getJson($leader); } /** * List Raft Peers * @param Peers $peers + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function peers(Peers $peers) { - $this->getJson($peers); + return $this->getJson($peers); } } \ No newline at end of file diff --git a/src/Transaction.php b/src/Transaction.php index 3ce9dec..7b5ec50 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -7,17 +7,19 @@ */ namespace EasySwoole\Consul; +use EasySwoole\Consul\ConsulInterface\TransactionInterface; use EasySwoole\Consul\Request\Txn; -class Transaction extends BaseFunc +class Transaction extends BaseFunc implements TransactionInterface { /** * Create Transaction * @param Txn $txn + * @return mixed * @throws \EasySwoole\HttpClient\Exception\InvalidUrl */ public function create(Txn $txn) { - $this->putJSON($txn); + return $this->putJSON($txn); } } \ No newline at end of file diff --git a/tests/StatusTest.php b/tests/StatusTest.php index ce85cc1..83d218f 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -28,7 +28,7 @@ function __construct($name = null, array $data = [], $dataName = '') function testLeader() { $leader = new Leader(); - $this->consul->status()->leader($leader); + var_dump($this->consul->status()->leader($leader)); $this->assertEquals('x','x'); } @@ -37,7 +37,7 @@ function testPeers() $peers = new Peers([ 'dc' => 'dc1', ]); - $this->consul->status()->peers($peers); + var_dump($this->consul->status()->peers($peers)); $this->assertEquals('x','x'); }