Skip to content

Commit

Permalink
making acl client uniform with other updated clients, adding object r…
Browse files Browse the repository at this point in the history
…esponses to agent client, and adding a few more agent client methods
  • Loading branch information
dcarbone committed Nov 25, 2020
1 parent 3ac34ec commit 11b5c1c
Show file tree
Hide file tree
Showing 22 changed files with 783 additions and 297 deletions.
16 changes: 8 additions & 8 deletions src/ACL/ACLClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ACLClient extends AbstractClient
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function bootstrap(): ValuedWriteStringResponse
public function Bootstrap(): ValuedWriteStringResponse
{
$r = new Request('PUT', 'v1/acl/bootstrap', $this->config);

Expand All @@ -61,7 +61,7 @@ public function bootstrap(): ValuedWriteStringResponse
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function create(ACLEntry $acl, WriteOptions $options = null): ValuedWriteStringResponse
public function Create(ACLEntry $acl, WriteOptions $options = null): ValuedWriteStringResponse
{
$r = new Request('PUT', 'v1/acl/create', $this->config, $acl);
$r->setWriteOptions($options);
Expand All @@ -88,7 +88,7 @@ public function create(ACLEntry $acl, WriteOptions $options = null): ValuedWrite
* @return \DCarbone\PHPConsulAPI\WriteResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function update(ACLEntry $acl, WriteOptions $options = null): WriteResponse
public function Update(ACLEntry $acl, WriteOptions $options = null): WriteResponse
{
$r = new Request('PUT', 'v1/acl/update', $this->config, $acl);
$r->setWriteOptions($options);
Expand All @@ -104,7 +104,7 @@ public function update(ACLEntry $acl, WriteOptions $options = null): WriteRespon
* @return \DCarbone\PHPConsulAPI\WriteResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function destroy(string $id, WriteOptions $options = null): WriteResponse
public function Destroy(string $id, WriteOptions $options = null): WriteResponse
{
$r = new Request('PUT', sprintf('v1/acl/destroy/%s', $id), $this->config);
$r->setWriteOptions($options);
Expand All @@ -120,7 +120,7 @@ public function destroy(string $id, WriteOptions $options = null): WriteResponse
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function clone(string $id, WriteOptions $options = null): ValuedWriteStringResponse
public function Clone(string $id, WriteOptions $options = null): ValuedWriteStringResponse
{
$r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->config);
$r->setWriteOptions($options);
Expand All @@ -147,7 +147,7 @@ public function clone(string $id, WriteOptions $options = null): ValuedWriteStri
* @return \DCarbone\PHPConsulAPI\ACL\ACLEntriesResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function info(string $id, QueryOptions $options = null): ACLEntriesResponse
public function Info(string $id, QueryOptions $options = null): ACLEntriesResponse
{
$r = new Request('GET', sprintf('v1/acl/info/%s', $id), $this->config);
$r->setQueryOptions($options);
Expand Down Expand Up @@ -178,7 +178,7 @@ public function info(string $id, QueryOptions $options = null): ACLEntriesRespon
* @return \DCarbone\PHPConsulAPI\ACL\ACLEntriesResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function list(QueryOptions $options = null): ACLEntriesResponse
public function List(QueryOptions $options = null): ACLEntriesResponse
{
$r = new Request('GET', 'v1/acl/list', $this->config);
$r->setQueryOptions($options);
Expand Down Expand Up @@ -209,7 +209,7 @@ public function list(QueryOptions $options = null): ACLEntriesResponse
* @return \DCarbone\PHPConsulAPI\ACL\ACLReplicationStatusResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function replication(QueryOptions $options = null): ACLReplicationStatusResponse
public function Replication(QueryOptions $options = null): ACLReplicationStatusResponse
{
$r = new Request('GET', '/v1/acl/replication', $this->config);
$r->setQueryOptions($options);
Expand Down
47 changes: 3 additions & 44 deletions src/AbstractValuedQueryResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
* Class AbstractValuedQueryResponse
* @package DCarbone\PHPConsulAPI
*/
abstract class AbstractValuedQueryResponse implements \ArrayAccess
abstract class AbstractValuedQueryResponse extends AbstractValuedResponse implements \ArrayAccess
{
/** @var \DCarbone\PHPConsulAPI\QueryMeta|null */
public $QueryMeta = null;
/** @var \DCarbone\PHPConsulAPI\Error|null */
public $Err = null;
use ResponseQueryMetaTrait;

/**
* AbstractValuedQueryResponse constructor.
Expand All @@ -37,28 +34,7 @@ abstract class AbstractValuedQueryResponse implements \ArrayAccess
public function __construct(?QueryMeta $qm, ?Error $err)
{
$this->QueryMeta = $qm;
$this->Err = $err;
}

/**
* @return mixed
*/
abstract public function getValue();

/**
* @return \DCarbone\PHPConsulAPI\QueryMeta|null
*/
public function getQueryMeta(): ?QueryMeta
{
return $this->QueryMeta;
}

/**
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function getErr(): ?Error
{
return $this->Err;
parent::__construct($err);
}

/**
Expand Down Expand Up @@ -86,21 +62,4 @@ public function offsetGet($offset)
throw new \OutOfBoundsException(sprintf('Offset %s does not exist', var_export($offset, true)));
}
}

/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, __CLASS__));
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, __CLASS__));
}
}
59 changes: 59 additions & 0 deletions src/AbstractValuedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);

namespace DCarbone\PHPConsulAPI;

/*
Copyright 2016-2020 Daniel Carbone ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
* Class AbstractValuedResponse
* @package DCarbone\PHPConsulAPI
*/
abstract class AbstractValuedResponse
{
use ResponseErrorTrait;

/**
* AbstractValuedResponse constructor.
* @param \DCarbone\PHPConsulAPI\Error|null $err
*/
public function __construct(?Error $err)
{
$this->Err = $err;
}

/**
* @return mixed
*/
abstract public function getValue();

/**
* @param $offset
* @param $value
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, get_called_class()));
}

/**
* @param $offset
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, get_called_class()));
}
}
48 changes: 4 additions & 44 deletions src/AbstractValuedWriteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
* Class AbstractValuedWriteResponse
* @package DCarbone\PHPConsulAPI
*/
abstract class AbstractValuedWriteResponse implements \ArrayAccess
abstract class AbstractValuedWriteResponse extends AbstractValuedResponse implements \ArrayAccess
{
/** @var \DCarbone\PHPConsulAPI\WriteMeta|null */
public $WriteMeta = null;
/** @var \DCarbone\PHPConsulAPI\Error|null */
public $Err = null;
use ResponseErrorTrait;
use ResponseWriteMetaTrait;

/**
* AbstractValuedWriteResponse constructor.
Expand All @@ -37,28 +35,7 @@ abstract class AbstractValuedWriteResponse implements \ArrayAccess
public function __construct(?WriteMeta $wm, ?Error $err)
{
$this->WriteMeta = $wm;
$this->Err = $err;
}

/**
* @return mixed
*/
abstract public function getValue();

/**
* @return \DCarbone\PHPConsulAPI\WriteMeta|null
*/
public function getWriteMeta(): ?WriteMeta
{
return $this->WriteMeta;
}

/**
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function getErr(): ?Error
{
return $this->Err;
parent::__construct($err);
}

/**
Expand Down Expand Up @@ -86,21 +63,4 @@ public function offsetGet($offset)
throw new \OutOfBoundsException(sprintf('Offset %s does not exist', var_export($offset, true)));
}
}

/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, __CLASS__));
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(sprintf('Cannot call %s on %s', __METHOD__, __CLASS__));
}
}
56 changes: 56 additions & 0 deletions src/Agent/AgentChecksResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types=1);

namespace DCarbone\PHPConsulAPI\Agent;

/*
Copyright 2016-2020 Daniel Carbone ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use DCarbone\PHPConsulAPI\AbstractValuedResponse;
use DCarbone\PHPConsulAPI\Error;

/**
* Class AgentChecksResponse
* @package DCarbone\PHPConsulAPI\Agent
*/
class AgentChecksResponse extends AbstractValuedResponse
{
/** @var \DCarbone\PHPConsulAPI\Agent\AgentCheck[]|null */
public $Checks = null;

/**
* AgentChecksResponse constructor.
* @param array|null $checks
* @param \DCarbone\PHPConsulAPI\Error|null $err
*/
public function __construct(?array $checks, ?Error $err)
{
if (null !== $checks) {
$this->Checks = [];
foreach ($checks as $k => $v) {
$this->Checks[$k] = new AgentCheck($v);
}
}
parent::__construct($err);
}

/**
* @return \DCarbone\PHPConsulAPI\Agent\AgentCheck[]|null
*/
public function getValue()
{
return $this->Checks;
}
}
Loading

0 comments on commit 11b5c1c

Please sign in to comment.