Skip to content

Commit

Permalink
Merge pull request #5 from unikorp/feat/documents
Browse files Browse the repository at this point in the history
Feat/documents
  • Loading branch information
VEBERArnaud committed Aug 9, 2017
2 parents 2b04902 + d25ab2c commit beaba18
Show file tree
Hide file tree
Showing 12 changed files with 1,492 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/AbstractDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the KongAdminApi package.
*
* (c) Unikorp <https://github.com/unikorp>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Unikorp\KongAdminApi;

/**
* abstract document
*
* @author VEBER Arnaud <https://github.com/VEBERArnaud>
*/
abstract class AbstractDocument implements DocumentInterface
{
/**
* get fields
*
* @return array
*/
abstract protected function getFields(): array;

/**
* to json
*
* @return string
*/
public function toJson(): string
{
$document = [];

foreach ($this->getFields() as $field) {
$value = $this->$field;

if (is_null($value)) {
continue;
}

if (is_array($value)) {
foreach (array_keys($value) as $key) {
$document[sprintf('%1$s.%2$s', $field, $key)] = $value[$key];
}

continue;
}

$document[$this->toSnakeCase($field)] = $this->$field;
}

return json_encode($document);
}

/**
* to snake case
*
* @param string $string
*
* @return string
*/
private function toSnakeCase(string $string): string
{
return mb_strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $string));
}
}
219 changes: 219 additions & 0 deletions src/Document/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<?php

/*
* This file is part of the KongAdminApi package.
*
* (c) Unikorp <https://github.com/unikorp>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Unikorp\KongAdminApi\Document;

use Unikorp\KongAdminApi\AbstractDocument;

/**
* api
*
* @author VEBER Arnaud <https://github.com/VEBERArnaud>
*/
class Api extends AbstractDocument
{
/**
* name
* @var string $name
*/
protected $name = null;

/**
* request host
* @var string $requestHost
*/
protected $requestHost = null;

/**
* request path
* @var string $requestPath
*/
protected $requestPath = null;

/**
* strip request path
* @var bool $stripRequestPath
*/
protected $stripRequestPath = false;

/**
* preserve host
* @var bool $preserveHost
*/
protected $preserveHost = false;

/**
* upstream url
* @var string $upstreamUrl
*/
protected $upstreamUrl = null;

/**
* set name
*
* @param string $name
*
* @return this
*/
public function setName(string $name): self
{
$this->name = $name;

return $this;
}

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

/**
* set request host
*
* @param string $requestHost
*
* @return this
*/
public function setRequestHost(string $requestHost): self
{
$this->requestHost = $requestHost;

return $this;
}

/**
* get request host
*
* @return string
*/
public function getRequestHost(): string
{
return $this->requestHost;
}

/**
* set request path
*
* @param string $requestPath
*
* @return this
*/
public function setRequestPath(string $requestPath): self
{
$this->requestPath = $requestPath;

return $this;
}

/**
* get request path
*
* @return string
*/
public function getRequestPath(): string
{
return $this->requestPath;
}

/**
* set strip request path
*
* @param bool $stripRequestPath
*
* @return this
*/
public function setStripRequestPath(bool $stripRequestPath): self
{
$this->stripRequestPath = $stripRequestPath;

return $this;
}

/**
* get strip request path
*
* @return bool
*/
public function getStripRequestPath(): bool
{
return $this->stripRequestPath;
}

/**
* set preserve host
*
* @param bool $preserveHost
*
* @return this
*/
public function setPreserveHost(bool $preserveHost): self
{
$this->preserveHost = $preserveHost;

return $this;
}

/**
* get preserve host
*
* @return bool
*/
public function getPreserveHost(): bool
{
return $this->preserveHost;
}

/**
* set upstream url
*
* @param string $upstreamUrl
*
* @return this
*/
public function setUpstreamUrl(string $upstreamUrl): self
{
$this->upstreamUrl = $upstreamUrl;

return $this;
}

/**
* get upstream url
*
* @return string
*/
public function getUpstreamUrl(): string
{
return $this->upstreamUrl;
}

/**
* get fields
*
* @return array
*/
protected function getFields(): array
{
return [
'name',
'requestHost',
'requestPath',
'stripRequestPath',
'preserveHost',
'upstreamUrl',
];
}
}
64 changes: 64 additions & 0 deletions src/Document/Cluster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the KongAdminApi package.
*
* (c) Unikorp <https://github.com/unikorp>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Unikorp\KongAdminApi\Document;

use Unikorp\KongAdminApi\AbstractDocument;

/**
* cluster
*
* @author VEBER Arnaud <https://github.com/VEBERArnaud>
*/
class Cluster extends AbstractDocument
{
/**
* name
* @var string $name
*/
protected $name = null;

/**
* set name
*
* @param string $name
*
* @return this
*/
public function setName(string $name): self
{
$this->name = $name;

return $this;
}

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

/**
* get fields
*
* @return array
*/
protected function getFields(): array
{
return [
'name',
];
}
}

0 comments on commit beaba18

Please sign in to comment.