- Added some more functionnality to API's connector
This commit is contained in:
		
							parent
							
								
									98c608dfba
								
							
						
					
					
						commit
						6d7701cfe5
					
				@ -5,7 +5,6 @@ namespace Ulmus\Api;
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Psr\Http\Message\ServerRequestInterface;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Ulmus\Api\Attribute\Obj\Api\ApiAction;
 | 
			
		||||
use Ulmus\Api\Common\MethodEnum;
 | 
			
		||||
@ -15,7 +14,6 @@ use Ulmus\Api\SearchRequest\ApiSearchRequest;
 | 
			
		||||
use Ulmus\Api\Stream\JsonStream;
 | 
			
		||||
use Ulmus\Api\Stream\Stream;
 | 
			
		||||
use Ulmus\Api\Request\JsonRequest;
 | 
			
		||||
use Ulmus\Api\Request\Request;
 | 
			
		||||
use Ulmus\Api\Transport\CurlClient;
 | 
			
		||||
use Ulmus\Api\Transport\CurlTransport;
 | 
			
		||||
use Ulmus\EntityCollection;
 | 
			
		||||
@ -213,7 +211,7 @@ class ApiRepository extends \Ulmus\Repository
 | 
			
		||||
            $this->adapter->apiHandler->debugResponse($transport, $this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    public function collectionFromQuery(? string $entityClass = null) : EntityCollection
 | 
			
		||||
    {
 | 
			
		||||
        $entityClass ??= $this->entityClass;
 | 
			
		||||
@ -229,10 +227,10 @@ class ApiRepository extends \Ulmus\Repository
 | 
			
		||||
            $entityCollection->append( $entity->resetVirtualProperties()->entityFillFromDataset($entityData) );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->eventExecute(\Ulmus\Event\Repository\CollectionFromQueryInterface::class, $entityCollection);
 | 
			
		||||
        $this->eventExecute(\Ulmus\Event\Repository\CollectionFromQueryInterface::class, $this, $entityCollection);
 | 
			
		||||
 | 
			
		||||
        return $entityCollection;
 | 
			
		||||
    }
 | 
			
		||||
    }*/
 | 
			
		||||
 | 
			
		||||
    public function filterServerRequest(SearchRequestInterface $searchRequest, bool $count = true) : \Ulmus\Repository
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ namespace Ulmus\Api;
 | 
			
		||||
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Psr\SimpleCache\CacheInterface;
 | 
			
		||||
use Ulmus\Adapter\AdapterInterface;
 | 
			
		||||
use Ulmus\Api\Request\JsonRequest;
 | 
			
		||||
use Ulmus\Api\Response\JsonResponse;
 | 
			
		||||
@ -12,24 +13,20 @@ use Ulmus\Ulmus;
 | 
			
		||||
 | 
			
		||||
class ConnectionAdapter extends \Ulmus\ConnectionAdapter
 | 
			
		||||
{
 | 
			
		||||
    public string $name;
 | 
			
		||||
 | 
			
		||||
    public array $configuration;
 | 
			
		||||
 | 
			
		||||
    protected AdapterInterface $adapter;
 | 
			
		||||
 | 
			
		||||
    private array $connection;
 | 
			
		||||
 | 
			
		||||
    public readonly ApiHandlerInterface $apiHandler;
 | 
			
		||||
 | 
			
		||||
    public function __construct(ApiHandlerInterface $apiHandler, $name = "default", array $configuration = [], bool $default = false)
 | 
			
		||||
    {
 | 
			
		||||
    public function __construct(
 | 
			
		||||
        public readonly ApiHandlerInterface $apiHandler,
 | 
			
		||||
        public string $name = "default",
 | 
			
		||||
        protected array $configuration = [],
 | 
			
		||||
        public bool $default = false,
 | 
			
		||||
        public ? CacheInterface $cacheObject = null
 | 
			
		||||
    ) {
 | 
			
		||||
        parent::__construct($name, $configuration, $default);
 | 
			
		||||
 | 
			
		||||
        $this->apiHandler = $apiHandler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function resolveConfiguration(): void
 | 
			
		||||
    {
 | 
			
		||||
        $connection = $this->configuration['connections'][$this->name] ?? [];
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,12 @@ class RequestBuilder implements Ulmus\QueryBuilder\QueryBuilderInterface
 | 
			
		||||
 | 
			
		||||
    protected array $queryParamStack = [];
 | 
			
		||||
 | 
			
		||||
    protected ? string $limitQueryField = "limit";
 | 
			
		||||
 | 
			
		||||
    protected ? string $offsetQueryField = "offset";
 | 
			
		||||
 | 
			
		||||
    protected ? string $pageQueryField = "page";
 | 
			
		||||
 | 
			
		||||
    public function values(array $dataset) : self
 | 
			
		||||
    {
 | 
			
		||||
        $this->addValues(array_values($dataset));
 | 
			
		||||
@ -23,7 +29,7 @@ class RequestBuilder implements Ulmus\QueryBuilder\QueryBuilderInterface
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function where(\Stringable|string $field, mixed $value,) : self
 | 
			
		||||
    public function filter(\Stringable|string $field, mixed $value,) : self
 | 
			
		||||
    {
 | 
			
		||||
        if ( empty($this->filters) && ! $this->getFragment(RequestBuilder\Filter::class) ) {
 | 
			
		||||
            $this->filters = new RequestBuilder\Filter();
 | 
			
		||||
@ -35,6 +41,11 @@ class RequestBuilder implements Ulmus\QueryBuilder\QueryBuilderInterface
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function where(\Stringable|string $field, mixed $value,) : self
 | 
			
		||||
    {
 | 
			
		||||
        return $this->filter($field, $value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function bindUrl(\Stringable|string $field, mixed $value,) : self
 | 
			
		||||
    {
 | 
			
		||||
        if ( empty($this->urlParameters) && ! $this->getFragment(RequestBuilder\UrlParameter::class) ) {
 | 
			
		||||
@ -47,39 +58,25 @@ class RequestBuilder implements Ulmus\QueryBuilder\QueryBuilderInterface
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*public function notWhere($field, mixed $value) : self
 | 
			
		||||
    {
 | 
			
		||||
        return $this->filters($field, $value);
 | 
			
		||||
    }*/
 | 
			
		||||
 | 
			
		||||
    public function limit(int $value) : self
 | 
			
		||||
    {
 | 
			
		||||
        /*if ( null === $limit = $this->getFragment(Ulmus\Query\Limit::class) ) {
 | 
			
		||||
            $limit = new Query\Limit();
 | 
			
		||||
            $this->push($limit);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $limit->set($value);
 | 
			
		||||
*/
 | 
			
		||||
        return $this;
 | 
			
		||||
        return is_null($this->limitQueryField) ? $this : $this->filter($this->limitQueryField, $value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function offset(int $value) : self
 | 
			
		||||
    {
 | 
			
		||||
       /*if ( null === $offset = $this->getFragment(Ulmus\Query\Offset::class) ) {
 | 
			
		||||
            $offset = new Ulmus\Query\Offset();
 | 
			
		||||
            $this->push($offset);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $offset->set($value);*/
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
        return is_null($this->offsetQueryField) ? $this : $this->filter($this->offsetQueryField, $value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function page(int $value) : self
 | 
			
		||||
    {
 | 
			
		||||
        return is_null($this->pageQueryField) ? $this : $this->filter($this->pageQueryField, $value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function orderBy(string $field, ? string $direction = null) : self
 | 
			
		||||
    {
 | 
			
		||||
        return $this;
 | 
			
		||||
        return $this->where($field, $direction);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function push(QueryFragmentInterface $queryFragment) : self
 | 
			
		||||
@ -136,4 +133,9 @@ class RequestBuilder implements Ulmus\QueryBuilder\QueryBuilderInterface
 | 
			
		||||
    {
 | 
			
		||||
        return $this->render();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function hashSerializedQuery(): string
 | 
			
		||||
    {
 | 
			
		||||
        return "UNSUPPORTED";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user