Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Cannonb4ll committed Apr 11, 2023
1 parent 636db45 commit 9a6d79d
Showing 1 changed file with 75 additions and 72 deletions.
147 changes: 75 additions & 72 deletions src/Ploi/Resources/DatabaseUser.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
<?php

namespace Ploi\Resources;

use Ploi\Http\Response;
use Ploi\Traits\HasPagination;

class DatabaseUser extends Resource
{

use HasPagination;

private $database;

public function __construct(Server $server, Database $database, int $id = null)
{
parent::__construct($server->getPloi(), $id);

$this->setDatabase($database);

$this->buildEndpoint();
}

public function buildEndpoint(): self
{
$this->setEndpoint($this->getDatabase()->getEndpoint() . '/users');

if ($this->getId()) {
$this->setEndpoint($this->getEndpoint() . '/' . $this->getId());
}

return $this;
}

public function get(int $id = null): Response
{
if ($id) {
$this->setId($id);
}

$this->buildEndpoint();

return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $user, string $password): Response
{
$this->setId(null);

$options = [
'body' => json_encode([
'user' => $user,
'password' => $password,
]),
];

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options);
}

public function delete(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete');
}
}
<?php

namespace Ploi\Resources;

use Ploi\Http\Response;
use Ploi\Traits\HasPagination;

class DatabaseUser extends Resource
{

use HasPagination;

private $database;

public function __construct(Server $server, Database $database, int $id = null)
{
parent::__construct($server->getPloi(), $id);

$this->setDatabase($database);

$this->buildEndpoint();
}

public function buildEndpoint(): self
{
$this->setEndpoint($this->getDatabase()->getEndpoint() . '/users');

if ($this->getId()) {
$this->setEndpoint($this->getEndpoint() . '/' . $this->getId());
}

return $this;
}

public function get(int $id = null): Response
{
if ($id) {
$this->setId($id);
}

$this->buildEndpoint();

return (is_null($this->getId()))
? $this->page()
: $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(string $user, string $password, bool $remote = false, string $remoteIp = '%', bool $readOnly = false): Response
{
$this->setId(null);

$options = [
'body' => json_encode([
'user' => $user,
'password' => $password,
'remote' => $remote,
'remote_ip' => $remoteIp,
'readonly' => $readOnly
]),
];

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options);
}

public function delete(?int $id = null): Response
{
$this->setIdOrFail($id);

$this->buildEndpoint();

return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete');
}
}

0 comments on commit 9a6d79d

Please sign in to comment.