Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9711e44feb |
No files matched your search
@@ -10,4 +10,5 @@ interface ApiHandlerInterface
|
|||||||
{
|
{
|
||||||
public function handleRequest(RequestInterface $request, ApiAction $attribute) : RequestInterface;
|
public function handleRequest(RequestInterface $request, ApiAction $attribute) : RequestInterface;
|
||||||
public function handleResponse(ResponseInterface $response, ApiAction $attribute) : ResponseInterface;
|
public function handleResponse(ResponseInterface $response, ApiAction $attribute) : ResponseInterface;
|
||||||
|
# public function debugResponse(\Ulmus\Api\Transport\CurlTransport $transport, ApiRepository $repository) : void;
|
||||||
}
|
}
|
||||||
+22
-3
@@ -6,6 +6,7 @@ use Psr\Http\Message\RequestInterface;
|
|||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
|
use Ulmus\Api\Attribute\Property\Bind;
|
||||||
use Ulmus\Api\Common\MethodEnum;
|
use Ulmus\Api\Common\MethodEnum;
|
||||||
use Ulmus\Api\RequestBuilder\Filter;
|
use Ulmus\Api\RequestBuilder\Filter;
|
||||||
use Ulmus\Api\RequestBuilder\UrlParameter;
|
use Ulmus\Api\RequestBuilder\UrlParameter;
|
||||||
@@ -60,7 +61,13 @@ class ApiRepository extends \Ulmus\Repository
|
|||||||
return $this->loadAllFromAttribute(Attribute\Obj\Api\Search::class);
|
return $this->loadAllFromAttribute(Attribute\Obj\Api\Search::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[\Deprecated]
|
||||||
public function save(object|array $entity, ?array $fieldsAndValue = null, bool $replace = false): bool
|
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());
|
$response = $this->executeRequest(Attribute\Obj\Api\Create::class, $entity->entityGetDataset());
|
||||||
|
|
||||||
@@ -71,6 +78,17 @@ class ApiRepository extends \Ulmus\Repository
|
|||||||
return $response->getStatusCode() === 200;
|
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
|
public function destroy(object $entity) : bool
|
||||||
{
|
{
|
||||||
if ( ! $this->matchEntity($entity) ) {
|
if ( ! $this->matchEntity($entity) ) {
|
||||||
@@ -135,6 +153,7 @@ class ApiRepository extends \Ulmus\Repository
|
|||||||
$search = [];
|
$search = [];
|
||||||
|
|
||||||
foreach($matches as $item) {
|
foreach($matches as $item) {
|
||||||
|
unset($value);
|
||||||
$default = null;
|
$default = null;
|
||||||
|
|
||||||
$variable = $item[1];
|
$variable = $item[1];
|
||||||
@@ -153,8 +172,8 @@ class ApiRepository extends \Ulmus\Repository
|
|||||||
if ($default ?? false) {
|
if ($default ?? false) {
|
||||||
$value = $default;
|
$value = $default;
|
||||||
}
|
}
|
||||||
elseif ( strpos($route, "[{$matches[0][0]}]") !== false && $this->enforceExistingArguments) {
|
else {
|
||||||
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']));
|
throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments %s", $route, $variable, json_encode($arguments)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +181,7 @@ class ApiRepository extends \Ulmus\Repository
|
|||||||
$value = $value->value;
|
$value = $value->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$search[$item[0]] = rawurlencode($value ?? "");
|
$search[$item[0]] = rawurlencode($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = str_replace(array_keys($search), array_values($search), $route);
|
$route = str_replace(array_keys($search), array_values($search), $route);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Ulmus\Api\Attribute\Property;
|
||||||
|
|
||||||
|
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||||
|
class Bind {
|
||||||
|
public function __construct(
|
||||||
|
public ? string $name = null,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
+1
-1
@@ -199,7 +199,7 @@ class Uri implements UriInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withQuery($query) : UriInterface
|
public function withQuery(null|array|string $query) : UriInterface
|
||||||
{
|
{
|
||||||
return $this->setQuery($query);
|
return $this->setQuery($query);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user