Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions Http/Statement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* A statement that prepare a request and execute them.
* The statement contains request, response and errors
Expand All @@ -7,26 +8,28 @@
* Date: 29/05/15
* Time: 14:21
*/
namespace evaisse\SimpleHttpBundle\Http;

namespace evaisse\SimpleHttpBundle\Http;

use evaisse\SimpleHttpBundle\Http\Exception\RequestNotSentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use React\Promise\Deferred;
use React\Promise\Promise;

use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Throwable;

class Statement
class Statement implements LoggerAwareInterface
{
use LoggerAwareTrait;

/** @var Kernel */
protected $httpKernel;

/**
* $request : Service Request
*
Expand All @@ -38,7 +41,7 @@ class Statement
/**
* $error : Error
*
* @var Error
* @var HttpException
* @access protected
*/
protected $error;
Expand Down Expand Up @@ -122,7 +125,7 @@ public function setHttpKernel(Kernel $httpKernel): void
{
$this->httpKernel = $httpKernel;
}

/**
*
* @param Request $request An http request object to send
Expand All @@ -134,6 +137,12 @@ public function __construct(Request $request, EventDispatcherInterface $eventDis
$this->promise = $this->deferred->promise();
$this->eventDispatcher = $eventDispatcher;
$this->httpKernel = $httpKernel;

if (function_exists('\React\Promise\set_rejection_handler')) {
\React\Promise\set_rejection_handler(fn(Throwable $e) => $this->logger?->warning(
'Unhandled promise rejection with ' . $e->getMessage(),
));
}
}


Expand Down Expand Up @@ -259,7 +268,6 @@ public function json($json = null)
$json = (string) $json;
} else {
$json = json_encode(null);

}
$this->request->setContent($json);
}
Expand Down Expand Up @@ -374,7 +382,8 @@ public function attachFile($key, $filepath, $mimetype = null, $clientName = null
$file->getRealPath(),
$clientName,
$file->getMimeType(),
0);
0
);

$this->getRequest()->files->set($key, $file);
}
Expand Down Expand Up @@ -447,9 +456,9 @@ public function authorizeOAuth($consumerKey, $consumerSecret)
}

/**
* @param string $key The key
* @param string|array $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
* @param string $key The key
* @param string|array $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
*
* @return self
*/
Expand All @@ -458,5 +467,4 @@ public function setHeader($key, $values, $replace = true)
$this->request->headers->set($key, $values, $replace);
return $this;
}

}
}