You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
|
|
|
|
namespace Gitlab\Api;
|
|
|
|
|
|
use Gitlab\Http\QueryString;
|
|
use Http\Client\HttpAsyncClient;
|
|
use Http\Message\MessageFactory;
|
|
use Http\Promise\Promise;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
|
|
abstract class Base
|
|
{
|
|
private $client;
|
|
private $messageFactory;
|
|
|
|
public function __construct(
|
|
HttpAsyncClient $client,
|
|
MessageFactory $messageFactory
|
|
)
|
|
{
|
|
$this->client = $client;
|
|
$this->messageFactory = $messageFactory;
|
|
}
|
|
|
|
protected function getClient() : HttpAsyncClient
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
protected function createOptionsResolver() : OptionsResolver
|
|
{
|
|
$resolver = new OptionsResolver();
|
|
|
|
// Every query can have page and per_page
|
|
$resolver->setDefined('page')
|
|
->setAllowedTypes('page', 'int')
|
|
->setAllowedValues('page', function ($value) {
|
|
return $value > 0;
|
|
})
|
|
->setDefined('per_page')
|
|
->setAllowedTypes('per_page', 'int')
|
|
->setAllowedValues('per_page', function ($value) {
|
|
return $value > 0 && $value <= 100;
|
|
});
|
|
|
|
return $resolver;
|
|
}
|
|
|
|
protected function getBooleanNormaliser() : callable
|
|
{
|
|
return function ($value) {
|
|
return $value === true ? 'true' : 'false';
|
|
};
|
|
}
|
|
|
|
protected function encodeObjectPath(string $path) : string
|
|
{
|
|
return str_replace('.', '%2E', rawurlencode($path));
|
|
}
|
|
|
|
/**
|
|
* @param string $path
|
|
* @param array $parameters
|
|
* @return Promise
|
|
* @throws \Exception
|
|
*/
|
|
protected function post(string $path, array $parameters) : Promise
|
|
{
|
|
$uri = $path;
|
|
|
|
$request = $this->messageFactory->createRequest(
|
|
'POST',
|
|
$uri,
|
|
[],
|
|
QueryString::build($parameters));
|
|
|
|
return $this->getClient()->sendAsyncRequest($request);
|
|
}
|
|
} |