type fixes
This commit is contained in:
@@ -75,10 +75,7 @@ class Pusher implements WampServerInterface
|
||||
*/
|
||||
protected $topicHash = [];
|
||||
|
||||
/**
|
||||
* @var ?string
|
||||
*/
|
||||
private $phpExecutablePath;
|
||||
private string $phpExecutablePath;
|
||||
|
||||
/**
|
||||
* @param array<string,array<string,mixed>> $categoriesData
|
||||
@@ -91,7 +88,19 @@ class Pusher implements WampServerInterface
|
||||
$this->categoryList = array_keys($categoriesData);
|
||||
$this->categoriesData = $categoriesData;
|
||||
|
||||
$this->phpExecutablePath = $phpExecutablePath ?: (new PhpExecutableFinder)->find();
|
||||
if (!$phpExecutablePath) {
|
||||
$phpExecutablePath = (new PhpExecutableFinder)->find() ?: null;
|
||||
}
|
||||
|
||||
if (!$phpExecutablePath) {
|
||||
if ($isDebugMode) {
|
||||
$this->log("Error: No php-executable-path.");
|
||||
}
|
||||
|
||||
throw new Exception("No php-executable-path.");
|
||||
}
|
||||
|
||||
$this->phpExecutablePath = $phpExecutablePath;
|
||||
$this->isDebugMode = $isDebugMode;
|
||||
}
|
||||
|
||||
@@ -111,6 +120,7 @@ class Pusher implements WampServerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
/** @phpstan-ignore-next-line */
|
||||
$connectionId = $connection->resourceId;
|
||||
|
||||
@@ -169,6 +179,7 @@ class Pusher implements WampServerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
/** @phpstan-ignore-next-line */
|
||||
$connectionId = $connection->resourceId;
|
||||
|
||||
@@ -230,6 +241,7 @@ class Pusher implements WampServerInterface
|
||||
|
||||
if (array_key_exists('paramList', $data)) {
|
||||
foreach ($data['paramList'] as $i => $item) {
|
||||
/** @var string $item */
|
||||
if (isset($arr[$i + 1])) {
|
||||
$params[$item] = $arr[$i + 1];
|
||||
}
|
||||
@@ -328,6 +340,7 @@ class Pusher implements WampServerInterface
|
||||
*/
|
||||
protected function subscribeUser(ConnectionInterface $connection, $userId)
|
||||
{
|
||||
/** @var string */
|
||||
/** @phpstan-ignore-next-line */
|
||||
$resourceId = $connection->resourceId;
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class SenderFactory implements Factory
|
||||
{
|
||||
$messager = $this->config->get('webSocketMessager') ?? self::DEFAULT_MESSAGER;
|
||||
|
||||
/** @var ?class-string */
|
||||
/** @var ?class-string<Sender> */
|
||||
$className = $this->metadata->get(['app', 'webSocket', 'messagers', $messager, 'senderClassName']);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Core\WebSocket;
|
||||
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Json;
|
||||
|
||||
use stdClass;
|
||||
use Throwable;
|
||||
@@ -61,7 +62,7 @@ class Submission
|
||||
|
||||
$data->topicId = $topic;
|
||||
|
||||
$message = json_encode($data);
|
||||
$message = Json::encode($data);
|
||||
|
||||
try {
|
||||
$this->sender->send($message);
|
||||
|
||||
@@ -56,7 +56,7 @@ class SubscriberFactory implements Factory
|
||||
{
|
||||
$messager = $this->config->get('webSocketMessager') ?? self::DEFAULT_MESSAGER;
|
||||
|
||||
/** @var ?class-string */
|
||||
/** @var ?class-string<Subscriber> */
|
||||
$className = $this->metadata->get(['app', 'webSocket', 'messagers', $messager, 'subscriberClassName']);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
@@ -48,10 +48,7 @@ use Espo\Entities\{
|
||||
*/
|
||||
class Manager
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheKey = 'webhooks';
|
||||
private string $cacheKey = 'webhooks';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
@@ -63,15 +60,15 @@ class Manager
|
||||
*/
|
||||
private $data = null;
|
||||
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
private $dataCache;
|
||||
private DataCache $dataCache;
|
||||
|
||||
private $entityManager;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
private $fieldUtil;
|
||||
private FieldUtil $fieldUtil;
|
||||
|
||||
private $log;
|
||||
private Log $log;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
@@ -91,10 +88,16 @@ class Manager
|
||||
|
||||
private function loadData(): void
|
||||
{
|
||||
if ($this->config->get('useCache')) {
|
||||
if ($this->dataCache->has($this->cacheKey)) {
|
||||
$this->data = $this->dataCache->get($this->cacheKey);
|
||||
if ($this->config->get('useCache') && $this->dataCache->has($this->cacheKey)) {
|
||||
$data = $this->dataCache->get($this->cacheKey);
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
/** @var ?array<string,bool> $data */
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
if (is_null($this->data)) {
|
||||
@@ -128,8 +131,11 @@ class Manager
|
||||
])
|
||||
->find();
|
||||
|
||||
foreach ($list as $e) {
|
||||
$data[$e->get('event')] = true;
|
||||
foreach ($list as $webhook) {
|
||||
/** @var string */
|
||||
$event = $webhook->getEvent();
|
||||
|
||||
$data[$event] = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -29,11 +29,12 @@
|
||||
|
||||
namespace Espo\Core\Webhook;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Entities\Webhook;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Config,
|
||||
};
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Json;
|
||||
|
||||
/**
|
||||
* Sends a portion.
|
||||
@@ -53,14 +54,15 @@ class Sender
|
||||
|
||||
/**
|
||||
* @param array<int,mixed> $dataList
|
||||
* @throws Error
|
||||
*/
|
||||
public function send(Webhook $webhook, array $dataList): int
|
||||
{
|
||||
$payload = json_encode($dataList);
|
||||
$payload = Json::encode($dataList);
|
||||
|
||||
$signature = null;
|
||||
|
||||
$secretKey = $webhook->get('secretKey');
|
||||
$secretKey = $webhook->getSecretKey();
|
||||
|
||||
if ($secretKey) {
|
||||
$signature = $this->buildSignature($webhook, $payload, $secretKey);
|
||||
@@ -78,7 +80,17 @@ class Sender
|
||||
$headerList[] = 'X-Signature: ' . $signature;
|
||||
}
|
||||
|
||||
$handler = curl_init($webhook->get('url'));
|
||||
$url = $webhook->getUrl();
|
||||
|
||||
if (!$url) {
|
||||
throw new Error("Webhook does not have URL.");
|
||||
}
|
||||
|
||||
$handler = curl_init($url);
|
||||
|
||||
if ($handler === false) {
|
||||
throw new Error("Could not init CURL for URL {$url}.");
|
||||
}
|
||||
|
||||
curl_setopt($handler, \CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handler, \CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
@@ -32,4 +32,19 @@ namespace Espo\Entities;
|
||||
class Webhook extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
public const ENTITY_TYPE = 'Webhook';
|
||||
|
||||
public function getEvent(): ?string
|
||||
{
|
||||
return $this->get('event');
|
||||
}
|
||||
|
||||
public function getSecretKey(): ?string
|
||||
{
|
||||
return $this->get('secretKey');
|
||||
}
|
||||
|
||||
public function getUrl(): ?string
|
||||
{
|
||||
return $this->get('url');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user