-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
636db45
commit 9a6d79d
Showing
1 changed file
with
75 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |