chg: pkg: make a massive refactor to the backend and remove all unnecessary deps - and make small refactors for the frontend too #4
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2019 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Util\Interfaces;
|
||||
|
||||
/**
|
||||
* Interface RpcManagerInterface
|
||||
*/
|
||||
interface RpcManagerInterface
|
||||
{
|
||||
/**
|
||||
* Gets all connect informations
|
||||
*
|
||||
* @param $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectInformation($params): string;
|
||||
|
||||
/**
|
||||
* It saves the whole grid table to database
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function saveGrid($data): bool;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2019 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Util\Interfaces;
|
||||
|
||||
use Ratchet\ConnectionInterface;
|
||||
use Ratchet\Wamp\Topic;
|
||||
|
||||
/**
|
||||
* Interfaces TopicManagerInterface
|
||||
*/
|
||||
interface TopicManagerInterface
|
||||
{
|
||||
/**
|
||||
* It handles the subscribe to a topic
|
||||
*
|
||||
* @param Topic $topic
|
||||
* @param ConnectionInterface $connection
|
||||
*/
|
||||
public function subscribe(Topic $topic, ConnectionInterface $connection): void;
|
||||
|
||||
/**
|
||||
* It handles the unsibscribe from the topic
|
||||
*
|
||||
* @param Topic $topic
|
||||
* @param ConnectionInterface $connection
|
||||
*/
|
||||
public function unSubscribe(Topic $topic, ConnectionInterface $connection): void;
|
||||
|
||||
/**
|
||||
* It publishes events on the topic
|
||||
*
|
||||
* @param Topic $topic
|
||||
* @param ConnectionInterface $connection
|
||||
* @param $event
|
||||
*/
|
||||
public function publish(Topic $topic, ConnectionInterface $connection, $event): void;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2019 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Util\Interfaces;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Interfaces WebsocketManagerInterface
|
||||
*/
|
||||
interface WebsocketManagerInterface
|
||||
{
|
||||
/**
|
||||
* Handle prod MySQL timeout
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*
|
||||
* @return EntityManagerInterface|null
|
||||
*/
|
||||
public function reConnect(EntityManagerInterface $entityManager): ?EntityManagerInterface;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
@@ -13,9 +13,8 @@ namespace App\Util;
|
||||
use App\Entity\Grid;
|
||||
use App\Entity\GridRow;
|
||||
use App\Entity\PlayedGame;
|
||||
use App\Util\Interfaces\RpcManagerInterface;
|
||||
use App\Interfaces\RpcManagerInterface;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Exception;
|
||||
@@ -24,49 +23,34 @@ use Psr\Log\LoggerInterface;
|
||||
/**
|
||||
* Class RpcManager
|
||||
*
|
||||
* @package App\Utils
|
||||
* @author system7 <https://www.splendidbear.org>
|
||||
* @package App\Util
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 09.
|
||||
*/
|
||||
class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
protected $entityManager;
|
||||
|
||||
/** @var LoggerInterface $logger */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* MineseekerRpc constructor.
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entityManager, LoggerInterface $logger)
|
||||
{
|
||||
$this->entityManager = $this->reConnect($entityManager);
|
||||
$this->logger = $logger;
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConnectInformation($params): string
|
||||
{
|
||||
$gameAssoc = is_array($params) ? $params[0] : $params;
|
||||
$grid = $this->getGrid($gameAssoc);
|
||||
$users = null !== $grid ? $this->getUsers($gameAssoc) : null;
|
||||
|
||||
return base64_encode(json_encode(array(
|
||||
'grid' => $grid,
|
||||
'users' => $users
|
||||
), JSON_THROW_ON_ERROR, 512));
|
||||
return base64_encode(json_encode([
|
||||
'grid' => $grid,
|
||||
'users' => $users,
|
||||
], JSON_THROW_ON_ERROR, 512));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function saveGrid($data): bool
|
||||
{
|
||||
$playedGame = new PlayedGame();
|
||||
@@ -173,11 +157,11 @@ class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
*/
|
||||
private function getUserCollection(PlayedGame $playedGame): array
|
||||
{
|
||||
return array(
|
||||
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
||||
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
||||
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
||||
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : ''
|
||||
);
|
||||
return [
|
||||
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
||||
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
||||
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
||||
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
namespace App\Util;
|
||||
|
||||
use App\Application\Sonata\UserBundle\Entity\User;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Gamer;
|
||||
use App\Entity\PlayedGame;
|
||||
use App\Entity\Step;
|
||||
use App\Util\Interfaces\TopicManagerInterface;
|
||||
use App\Interfaces\TopicManagerInterface;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
@@ -28,49 +28,25 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
/**
|
||||
* Class TopicManager
|
||||
*
|
||||
* @package App\Util
|
||||
* @author system7 <https://www.splendidbear.org>
|
||||
* @package App\Util
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 09.
|
||||
*/
|
||||
class TopicManager extends WebsocketManager implements TopicManagerInterface
|
||||
{
|
||||
/** @var ClientManipulatorInterface $clientManipulator */
|
||||
protected $clientManipulator;
|
||||
|
||||
/** @var EntityManagerInterface $entityManager */
|
||||
protected $entityManager;
|
||||
|
||||
/** @var RequestStack $requestStack */
|
||||
protected $requestStack;
|
||||
|
||||
/** @var LoggerInterface $logger */
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* TopicManager constructor.
|
||||
*
|
||||
* @param ClientManipulatorInterface $clientManipulator
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param RequestStack $requestStack
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(
|
||||
ClientManipulatorInterface $clientManipulator,
|
||||
EntityManagerInterface $entityManager,
|
||||
RequestStack $requestStack,
|
||||
LoggerInterface $logger
|
||||
protected ClientManipulatorInterface $clientManipulator,
|
||||
protected EntityManagerInterface $entityManager,
|
||||
protected RequestStack $requestStack,
|
||||
protected LoggerInterface $logger
|
||||
)
|
||||
{
|
||||
$this->clientManipulator = $clientManipulator;
|
||||
$this->entityManager = $this->reConnect($entityManager);
|
||||
$this->requestStack = $requestStack;
|
||||
$this->logger = $logger;
|
||||
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function subscribe(Topic $topic, ConnectionInterface $connection): void
|
||||
{
|
||||
/** this will broadcast the message to ALL subscribers of this topic. */
|
||||
@@ -93,18 +69,12 @@ class TopicManager extends WebsocketManager implements TopicManagerInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function unSubscribe(Topic $topic, ConnectionInterface $connection): void
|
||||
{
|
||||
/** This will broadcasts the message to ALL subscribers of this topic. */
|
||||
$topic->broadcast(array('msg' => $connection->resourceId . ' has left ' . $topic->getId()));
|
||||
$topic->broadcast(['msg' => $connection->resourceId . ' has left ' . $topic->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function publish(Topic $topic, ConnectionInterface $connection, $event): void
|
||||
{
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
@@ -319,11 +289,11 @@ class TopicManager extends WebsocketManager implements TopicManagerInterface
|
||||
*/
|
||||
private function getUserCollection(PlayedGame $playedGame): array
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
||||
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
||||
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
||||
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : ''
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
@@ -10,35 +10,25 @@
|
||||
|
||||
namespace App\Util;
|
||||
|
||||
use App\Util\Interfaces\WebsocketManagerInterface;
|
||||
use Doctrine\DBAL\Driver\PDOException;
|
||||
use App\Interfaces\WebsocketManagerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class WebsocketManager
|
||||
*
|
||||
* @package App\Util
|
||||
* @author system7 <https://www.splendidbear.org>
|
||||
* @package App\Util
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 09.
|
||||
*/
|
||||
class WebsocketManager implements WebsocketManagerInterface
|
||||
{
|
||||
/** @var LoggerInterface $logger */
|
||||
private $logger;
|
||||
public function __construct(private LoggerInterface $logger) { }
|
||||
|
||||
/**
|
||||
* WebsocketManager constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reConnect(EntityManagerInterface $entityManager): ?EntityManagerInterface
|
||||
{
|
||||
try {
|
||||
@@ -48,7 +38,7 @@ class WebsocketManager implements WebsocketManagerInterface
|
||||
$connection->close();
|
||||
$connection->connect();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user