- Work done to allow more flexibility on based on whatever custom attributes were provided.
This commit is contained in:
		
							parent
							
								
									b3e792e20f
								
							
						
					
					
						commit
						bea01badb7
					
				@ -39,7 +39,7 @@ class Rest implements AdapterInterface
 | 
			
		||||
 | 
			
		||||
    public function setup(array $configuration): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->auth = AuthenticationEnum::from($configuration['auth'] ?: AuthenticationEnum::Basic->value);
 | 
			
		||||
        $this->auth = AuthenticationEnum::from($configuration['auth'] ?? AuthenticationEnum::Basic->value);
 | 
			
		||||
        $this->url = rtrim($configuration['url'], '/');
 | 
			
		||||
 | 
			
		||||
        foreach([ 'username', 'password', 'token', 'headers', 'options' ] as $conf) {
 | 
			
		||||
 | 
			
		||||
@ -58,11 +58,19 @@ class ApiRepository extends \Ulmus\Repository
 | 
			
		||||
    {
 | 
			
		||||
        $attribute = $this->getApiAttribute($attributeClass);
 | 
			
		||||
 | 
			
		||||
        if ($attribute === null) {
 | 
			
		||||
            throw new \RuntimeException(sprintf("Could not find attribute class '%s' for class '%s'", $attributeClass, $this->entityClass));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $request = $this->prepareRequest($this->buildRequestUrl($attribute->url), $attribute->method, $data);
 | 
			
		||||
 | 
			
		||||
        $request = $this->callApiRequestCallback($request, $attribute);
 | 
			
		||||
 | 
			
		||||
        $this->lastResponse = $response = $this->adapter->adapter()->connect()->fromRequest($request);
 | 
			
		||||
        $rest = $this->adapter->adapter()->connect();
 | 
			
		||||
 | 
			
		||||
        $rest->timeout = $attribute->timeout;
 | 
			
		||||
 | 
			
		||||
        $this->lastResponse = $response = $rest->fromRequest($request);
 | 
			
		||||
 | 
			
		||||
        $response = $this->callApiResponseCallback($response, $attribute);
 | 
			
		||||
 | 
			
		||||
@ -126,7 +134,7 @@ class ApiRepository extends \Ulmus\Repository
 | 
			
		||||
        return new JsonRequest($uri, $method, $body === null ? Stream::fromTemp() : JsonStream::fromContent($body), $headers);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getApiAttribute(string $type) : object
 | 
			
		||||
    public function getApiAttribute(string $type) : ? object
 | 
			
		||||
    {
 | 
			
		||||
        return $this->entityClass::resolveEntity()->getAttributeImplementing($type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -10,5 +10,6 @@ abstract class ApiAction
 | 
			
		||||
    public function __construct(
 | 
			
		||||
        public string $url,
 | 
			
		||||
        public MethodEnum $method,
 | 
			
		||||
        public int $timeout = 5,
 | 
			
		||||
    ) {}
 | 
			
		||||
}
 | 
			
		||||
@ -10,5 +10,4 @@ class CurlClient extends CurlTransport
 | 
			
		||||
 | 
			
		||||
    # Handle file uploading here
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -10,7 +10,11 @@ use Ulmus\Api\Response\{ Response, JsonResponse };
 | 
			
		||||
 | 
			
		||||
abstract class CurlTransport {
 | 
			
		||||
 | 
			
		||||
    public int $timeout = 5;
 | 
			
		||||
    # Seconds
 | 
			
		||||
    public int $timeout = 30;
 | 
			
		||||
 | 
			
		||||
    # Seconds
 | 
			
		||||
    public int $connectTimeout = 300;
 | 
			
		||||
 | 
			
		||||
    public int $maximumRedirections = 10;
 | 
			
		||||
 | 
			
		||||
@ -81,7 +85,8 @@ abstract class CurlTransport {
 | 
			
		||||
            CURLOPT_URL => $url,
 | 
			
		||||
            CURLOPT_HTTPHEADER => HttpHeaderEnum::compileHeaders($headers),
 | 
			
		||||
            CURLOPT_MAXREDIRS => $this->maximumRedirections,
 | 
			
		||||
            CURLOPT_TIMEOUT_MS => $this->timeout * 1000,
 | 
			
		||||
            CURLOPT_TIMEOUT => $this->timeout * 1000,
 | 
			
		||||
            CURLOPT_CONNECTTIMEOUT => $this->connectTimeout,
 | 
			
		||||
            CURLOPT_SSL_VERIFYPEER => false,
 | 
			
		||||
            CURLOPT_SSL_VERIFYHOST => false,
 | 
			
		||||
            CURLOPT_RETURNTRANSFER => true,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user