Skip to content

Commit

Permalink
Cleanup and extraneous code removal
Browse files Browse the repository at this point in the history
- Removing "Collection" concept entirely
- Removing "AbstractCollection" class
- Removing "AbstractOptions" class
- Removing "ConsulHttpParamContainerTrait" trait
- Removing "Logger" system, wasn't used and we bubble up errors anyway
- "Request::headers" and "Request::params" are now instances of "Values"
- "Values" closely mimics go's URI.Query property, albeit without any encoding options.
  • Loading branch information
dcarbone committed Apr 10, 2017
1 parent 0f20497 commit 2eff055
Show file tree
Hide file tree
Showing 66 changed files with 1,480 additions and 2,547 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"require": {
"php": ">=5.6.0",
"psr/log": "1.0.*",
"guzzlehttp/psr7": "1.4.*",
"php-http/client-implementation": "@stable"
},
Expand Down
57 changes: 29 additions & 28 deletions src/ACL/ACLClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* Class ACLClient
* @package DCarbone\PHPConsulAPI\ACL
*/
class ACLClient extends AbstractClient
{
class ACLClient extends AbstractClient {
/**
* @param \DCarbone\PHPConsulAPI\ACL\ACLEntry $acl
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions
Expand All @@ -36,21 +35,22 @@ class ACLClient extends AbstractClient
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function create(ACLEntry $acl, WriteOptions $writeOptions = null)
{
public function create(ACLEntry $acl, WriteOptions $writeOptions = null) {
$r = new Request('put', 'v1/acl/create', $this->c, $acl);
$r->setWriteOptions($writeOptions);

/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err)
if (null !== $err) {
return ['', null, $err];
}

$wm = $this->buildWriteMeta($duration);

list($data, $err) = $this->decodeBody($response->getBody());
if (null !== $err)
if (null !== $err) {
return ['', $wm, $err];
}

return [$data, $wm, null];
}
Expand All @@ -63,15 +63,15 @@ public function create(ACLEntry $acl, WriteOptions $writeOptions = null)
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function update(ACLEntry $acl, WriteOptions $writeOptions = null)
{
public function update(ACLEntry $acl, WriteOptions $writeOptions = null) {
$r = new Request('PUT', 'v1/acl/update', $this->c, $acl);
$r->setWriteOptions($writeOptions);

list($duration, $_, $err) = $this->requireOK($this->doRequest($r));

if (null !== $err)
if (null !== $err) {
return [null, $err];
}

return [$this->buildWriteMeta($duration), null];
}
Expand All @@ -84,15 +84,15 @@ public function update(ACLEntry $acl, WriteOptions $writeOptions = null)
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function destroy($id, WriteOptions $writeOptions = null)
{
public function destroy($id, WriteOptions $writeOptions = null) {
$r = new Request('PUT', sprintf('v1/acl/destroy/%s', $id), $this->c);
$r->setWriteOptions($writeOptions);

list($duration, $_, $err) = $this->requireOK($this->doRequest($r));

if (null !== $err)
if (null !== $err) {
return [null, $err];
}

return [$this->buildWriteMeta($duration), null];
}
Expand All @@ -106,21 +106,22 @@ public function destroy($id, WriteOptions $writeOptions = null)
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function cloneACL($id, WriteOptions $writeOptions = null)
{
public function cloneACL($id, WriteOptions $writeOptions = null) {
$r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->c);
$r->setWriteOptions($writeOptions);

/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err)
if (null !== $err) {
return ['', null, $err];
}

$wm = $this->buildWriteMeta($duration);

list($data, $err) = $this->decodeBody($response->getBody());
if (null !== $err)
if (null !== $err) {
return ['', $wm, $err];
}

return [$data, $wm, null];
}
Expand All @@ -134,25 +135,25 @@ public function cloneACL($id, WriteOptions $writeOptions = null)
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function info($id, QueryOptions $queryOptions = null)
{
public function info($id, QueryOptions $queryOptions = null) {
$r = new Request('GET', sprintf('v1/acl/info/%s', $id), $this->c);
$r->setQueryOptions($queryOptions);

/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err)
if (null !== $err) {
return [null, null, $err];
}

$qm = $this->buildQueryMeta($duration, $response, $r->getUri());

list($data, $err) = $this->decodeBody($response->getBody());
if (null !== $err)
if (null !== $err) {
return [null, $qm, $err];
}

$entries = [];
foreach($data as $entry)
{
foreach ($data as $entry) {
$entries[] = new ACLEntry($entry);
}

Expand All @@ -167,26 +168,26 @@ public function info($id, QueryOptions $queryOptions = null)
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
*/
public function listACLs(QueryOptions $queryOptions = null)
{
public function listACLs(QueryOptions $queryOptions = null) {
$r = new Request('GET', 'v1/acl/list', $this->c);
$r->setQueryOptions($queryOptions);

/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err)
if (null !== $err) {
return [null, null, $err];
}

$qm = $this->buildQueryMeta($duration, $response, $r->getUri());


list($data, $err) = $this->decodeBody($response->getBody());
if (null !== $err)
if (null !== $err) {
return [null, $qm, $err];
}

$entries = [];
foreach($data as $entry)
{
foreach ($data as $entry) {
$entries[] = new ACLEntry($entry);
}

Expand Down
39 changes: 13 additions & 26 deletions src/ACL/ACLEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* Class ACLEntry
* @package DCarbone\PHPConsulAPI\ACL
*/
class ACLEntry extends AbstractModel
{
class ACLEntry extends AbstractModel {
/** @var int */
public $CreateIndex = 0;
/** @var int */
Expand All @@ -40,96 +39,84 @@ class ACLEntry extends AbstractModel
/**
* @return int
*/
public function getCreateIndex()
{
public function getCreateIndex() {
return $this->CreateIndex;
}

/**
* @param int $CreateIndex
*/
public function setCreateIndex($CreateIndex)
{
public function setCreateIndex($CreateIndex) {
$this->CreateIndex = $CreateIndex;
}

/**
* @return int
*/
public function getModifyIndex()
{
public function getModifyIndex() {
return $this->ModifyIndex;
}

/**
* @param int $ModifyIndex
*/
public function setModifyIndex($ModifyIndex)
{
public function setModifyIndex($ModifyIndex) {
$this->ModifyIndex = $ModifyIndex;
}

/**
* @return string
*/
public function getID()
{
public function getID() {
return $this->ID;
}

/**
* @param string $ID
*/
public function setID($ID)
{
public function setID($ID) {
$this->ID = $ID;
}

/**
* @return string
*/
public function getName()
{
public function getName() {
return $this->Name;
}

/**
* @param string $Name
*/
public function setName($Name)
{
public function setName($Name) {
$this->Name = $Name;
}

/**
* @return string
*/
public function getType()
{
public function getType() {
return $this->Type;
}

/**
* @param string $Type
*/
public function setType($Type)
{
public function setType($Type) {
$this->Type = $Type;
}

/**
* @return string
*/
public function getRules()
{
public function getRules() {
return $this->Rules;
}

/**
* @param string $Rules
*/
public function setRules($Rules)
{
public function setRules($Rules) {
$this->Rules = $Rules;
}
}
Loading

0 comments on commit 2eff055

Please sign in to comment.