|
@@ -7,6 +7,7 @@ use App\Entity\Film;
|
|
use App\Entity\User;
|
|
use App\Entity\User;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
+use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Envoi notifs mattermost
|
|
* Envoi notifs mattermost
|
|
@@ -17,44 +18,31 @@ class Mattermost
|
|
* Mattermost Manager
|
|
* Mattermost Manager
|
|
*/
|
|
*/
|
|
public function __construct(
|
|
public function __construct(
|
|
- protected string $url,
|
|
|
|
- protected string $token,
|
|
|
|
|
|
+ protected HttpClientInterface $mattermostClient,
|
|
protected string $channelId,
|
|
protected string $channelId,
|
|
protected string $channelIdAdmin,
|
|
protected string $channelIdAdmin,
|
|
protected UrlGeneratorInterface $router,
|
|
protected UrlGeneratorInterface $router,
|
|
- protected RequestStack $requestStack)
|
|
|
|
|
|
+ protected RequestStack $requestStack
|
|
|
|
+ )
|
|
{
|
|
{
|
|
- $this->url = $url . "/api/v4/posts";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- protected function SendNotif($message, $isChanAdmin = False) :void
|
|
|
|
|
|
+ protected function SendNotif(string $message, bool $isChanAdmin = False) :void
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
- if (function_exists("curl_init")) {
|
|
|
|
- // crée une nouvelle ressource cURL
|
|
|
|
- $ch = curl_init();
|
|
|
|
- } else {
|
|
|
|
- throw new \Exception("Curl n'est pas installé.", 500);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // fixe l'URL et les autres options appropriées
|
|
|
|
- $options = array(
|
|
|
|
- CURLOPT_URL => $this->url,
|
|
|
|
- CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Authorization: Bearer ' . $this->token),
|
|
|
|
- CURLOPT_POSTFIELDS => '{"channel_id": "' . ($isChanAdmin ? $this->channelIdAdmin : $this->channelId) . '", "message": "' . $message . '"}'
|
|
|
|
|
|
+ $response = $this->mattermostClient->request(
|
|
|
|
+ 'POST',
|
|
|
|
+ 'api/v4/posts', [
|
|
|
|
+ 'json' => [
|
|
|
|
+ "channel_id" => ($isChanAdmin ? $this->channelIdAdmin : $this->channelId),
|
|
|
|
+ "message" => $message
|
|
|
|
+ ]
|
|
|
|
+ ]
|
|
);
|
|
);
|
|
|
|
|
|
- curl_setopt_array($ch, $options);
|
|
|
|
-
|
|
|
|
- // attrape l'URL et la passe au navigateur
|
|
|
|
- curl_exec($ch);
|
|
|
|
-
|
|
|
|
- // ferme la ressource cURL et libère les ressources systèmes
|
|
|
|
- curl_close($ch);
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
- $this->requestStack->getSession()->getFlashBag->add('error', "L'envoi vers mattermost a échoué.");
|
|
|
|
|
|
+ $this->requestStack->getSession()->getFlashBag()->add('error', "L'envoi vers mattermost a échoué.");
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function sendNouveauFilm(Film $film) :void
|
|
public function sendNouveauFilm(Film $film) :void
|
|
@@ -86,7 +74,7 @@ class Mattermost
|
|
$this->SendNotif($message);
|
|
$this->SendNotif($message);
|
|
}
|
|
}
|
|
|
|
|
|
- public function sendNewUser($userName) : void
|
|
|
|
|
|
+ public function sendNewUser(string $userName) : void
|
|
{
|
|
{
|
|
$message =
|
|
$message =
|
|
":warning: Un utilisateur vient de s'enregistrer dans la [vidéothèque]("
|
|
":warning: Un utilisateur vient de s'enregistrer dans la [vidéothèque]("
|