Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9711e44feb | ||
|
|
99c0148a20 | ||
|
|
f3a21a811b | ||
|
|
ac44ef4989 | ||
|
|
3ddd8a399a | ||
|
|
0f3af39564 |
No files matched your search
+3
-3
@@ -11,12 +11,12 @@
|
||||
],
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"mcnd/ulmus": "dev-master"
|
||||
"mcnd/ulmus": "^1.0 || ^2.0"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://git.mcnd.ca/mcNdave/ulmus.git"
|
||||
"type": "composer",
|
||||
"url": "https://git.mcnd.ca/api/packages/mcndave/composer"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
|
||||
@@ -10,4 +10,5 @@ interface ApiHandlerInterface
|
||||
{
|
||||
public function handleRequest(RequestInterface $request, ApiAction $attribute) : RequestInterface;
|
||||
public function handleResponse(ResponseInterface $response, ApiAction $attribute) : ResponseInterface;
|
||||
# public function debugResponse(\Ulmus\Api\Transport\CurlTransport $transport, ApiRepository $repository) : void;
|
||||
}
|
||||
+26
-3
@@ -6,6 +6,7 @@ use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Ulmus\Api\Attribute\Property\Bind;
|
||||
use Ulmus\Api\Common\MethodEnum;
|
||||
use Ulmus\Api\RequestBuilder\Filter;
|
||||
use Ulmus\Api\RequestBuilder\UrlParameter;
|
||||
@@ -60,7 +61,13 @@ class ApiRepository extends \Ulmus\Repository
|
||||
return $this->loadAllFromAttribute(Attribute\Obj\Api\Search::class);
|
||||
}
|
||||
|
||||
#[\Deprecated]
|
||||
public function save(object|array $entity, ?array $fieldsAndValue = null, bool $replace = false): bool
|
||||
{
|
||||
return $this->create($entity, $replace);
|
||||
}
|
||||
|
||||
public function create(object|array $entity, bool $replace = false): bool
|
||||
{
|
||||
$response = $this->executeRequest(Attribute\Obj\Api\Create::class, $entity->entityGetDataset());
|
||||
|
||||
@@ -71,6 +78,17 @@ class ApiRepository extends \Ulmus\Repository
|
||||
return $response->getStatusCode() === 200;
|
||||
}
|
||||
|
||||
public function update(object|array $entity): bool
|
||||
{
|
||||
foreach($this->entityResolver->searchPropertyAttributeList(Bind::class) as $field => $attribute) {
|
||||
$this->bindUrl($attribute[0]->name ?? $field, $entity->$field);
|
||||
}
|
||||
|
||||
$response = $this->executeRequest(Attribute\Obj\Api\Update::class, $this->generateWritableDataset($entity));
|
||||
|
||||
return $response->getStatusCode() === 200;
|
||||
}
|
||||
|
||||
public function destroy(object $entity) : bool
|
||||
{
|
||||
if ( ! $this->matchEntity($entity) ) {
|
||||
@@ -135,6 +153,7 @@ class ApiRepository extends \Ulmus\Repository
|
||||
$search = [];
|
||||
|
||||
foreach($matches as $item) {
|
||||
unset($value);
|
||||
$default = null;
|
||||
|
||||
$variable = $item[1];
|
||||
@@ -153,12 +172,16 @@ class ApiRepository extends \Ulmus\Repository
|
||||
if ($default ?? false) {
|
||||
$value = $default;
|
||||
}
|
||||
elseif ( strpos($route, "[{$matches[0][0]}]") !== false && $this->enforceExistingArguments) {
|
||||
throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments ( %s ) from %s::%s", $route, $variable, json_encode($arguments), $routeParam['class'], $routeParam['classMethod']));
|
||||
else {
|
||||
throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments %s", $route, $variable, json_encode($arguments)));
|
||||
}
|
||||
}
|
||||
|
||||
$search[$item[0]] = rawurlencode($value ?? "");
|
||||
if (is_object($value) && enum_exists($value::class)) {
|
||||
$value = $value->value;
|
||||
}
|
||||
|
||||
$search[$item[0]] = rawurlencode($value);
|
||||
}
|
||||
|
||||
$route = str_replace(array_keys($search), array_values($search), $route);
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Ulmus\Api\Attribute\Obj\Api;
|
||||
use Ulmus\Api\Common\MethodEnum;
|
||||
|
||||
#[\Attribute]
|
||||
abstract class ApiAction
|
||||
class ApiAction
|
||||
{
|
||||
public function __construct(
|
||||
public string $url,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Api\Attribute\Property;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class Bind {
|
||||
public function __construct(
|
||||
public ? string $name = null,
|
||||
) {}
|
||||
}
|
||||
+14
-14
@@ -53,7 +53,7 @@ class Uri implements UriInterface
|
||||
$this->setFragment($parts['fragment'] ?? null);
|
||||
}
|
||||
|
||||
public function getScheme()
|
||||
public function getScheme(): string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class Uri implements UriInterface
|
||||
return ( $info = $this->getUserInfo() ) ? "{$info}@" : "";
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPort()
|
||||
public function getPort(): ?int
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class Uri implements UriInterface
|
||||
return $port && ! in_array($port, $ignore) ? ":{$port}" : "";
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
$path = implode('/', array_map('rawurlencode', explode('/', $this->path)));
|
||||
|
||||
@@ -130,7 +130,7 @@ class Uri implements UriInterface
|
||||
return $this->getPath();
|
||||
}
|
||||
|
||||
public function getQuery()
|
||||
public function getQuery(): string
|
||||
{
|
||||
return http_build_query($this->query, "", null, PHP_QUERY_RFC3986);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ class Uri implements UriInterface
|
||||
return $query ? "?{$query}" : "";
|
||||
}
|
||||
|
||||
public function getFragment()
|
||||
public function getFragment() : string
|
||||
{
|
||||
return rawurlencode($this->fragment ? "#{$this->fragment}" : "");
|
||||
}
|
||||
@@ -152,12 +152,12 @@ class Uri implements UriInterface
|
||||
return $this->getFragment();
|
||||
}
|
||||
|
||||
public function withScheme($scheme)
|
||||
public function withScheme($scheme) : UriInterface
|
||||
{
|
||||
return (clone $this)->setScheme($scheme);
|
||||
}
|
||||
|
||||
public function withUserInfo($user, $password = null)
|
||||
public function withUserInfo($user, $password = null) : UriInterface
|
||||
{
|
||||
return (clone $this)->setUserInfo($user, $password);
|
||||
}
|
||||
@@ -170,12 +170,12 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withHost($host)
|
||||
public function withHost($host) : UriInterface
|
||||
{
|
||||
return (clone $this)->setHost($host);
|
||||
}
|
||||
|
||||
public function withPort($port)
|
||||
public function withPort($port) : UriInterface
|
||||
{
|
||||
return (clone $this)->setPort($port);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPath($path)
|
||||
public function withPath($path) : UriInterface
|
||||
{
|
||||
return (clone $this)->setPath($path);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withQuery($query)
|
||||
public function withQuery(null|array|string $query) : UriInterface
|
||||
{
|
||||
return $this->setQuery($query);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withFragment($fragment)
|
||||
public function withFragment($fragment) : UriInterface
|
||||
{
|
||||
return (clone $this)->setFragment($fragment);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class Uri implements UriInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class Request extends Message implements ServerRequestInterface
|
||||
return $target ?: '/';
|
||||
}
|
||||
|
||||
public function withRequestTarget($requestTarget)
|
||||
public function withRequestTarget($requestTarget) : RequestInterface
|
||||
{
|
||||
return (clone $this)->setRequestTarget($requestTarget);
|
||||
}
|
||||
@@ -57,12 +57,12 @@ class Request extends Message implements ServerRequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->method->value;
|
||||
}
|
||||
|
||||
public function withMethod($method)
|
||||
public function withMethod($method) : RequestInterface
|
||||
{
|
||||
return (clone $this)->setMethod($method);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class Request extends Message implements ServerRequestInterface
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function withUri(UriInterface $uri, $preserveHost = false)
|
||||
public function withUri(UriInterface $uri, $preserveHost = false) : RequestInterface
|
||||
{
|
||||
return (clone $this)->setUri($uri, $preserveHost);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class Request extends Message implements ServerRequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function renderHostHeader(UriInterface $fromUri = null) : string
|
||||
protected function renderHostHeader(? UriInterface $fromUri = null) : string
|
||||
{
|
||||
$fromUri ??= $this->uri;
|
||||
|
||||
|
||||
@@ -20,17 +20,17 @@ class Response extends Message implements ResponseInterface
|
||||
$this->setHeaders($headers);
|
||||
}
|
||||
|
||||
public function getStatusCode() /* : int */
|
||||
public function getStatusCode() : int
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function withStatus($code, $reasonPhrase = null)/* : ResponseInterface*/
|
||||
public function withStatus($code, $reasonPhrase = null) : ResponseInterface
|
||||
{
|
||||
return (clone $this)->setStatusCode($code, $reasonPhrase);
|
||||
}
|
||||
|
||||
public function getReasonPhrase() /* : string */
|
||||
public function getReasonPhrase() : string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user