Skip to content
Open
Show file tree
Hide file tree
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
36 changes: 16 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,35 @@
"role": "Founder"
}],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"jms/serializer": "*",
Comment on lines 14 to 16
Comment on lines 14 to 16
Comment on lines 14 to 16
"hassankhan/config": "^3.0",
"monolog/monolog": "*",
"symfony/finder": "*",
"symfony/event-dispatcher": "*",
"doctrine/collections": "^1.4",
"doctrine/annotations": "^1.10",
"doctrine/cache": "^1.10",
"monolog/monolog": "^3.0",
"symfony/finder": "^8.0",
"symfony/event-dispatcher": "^8.0",
"doctrine/collections": "^3.0",
"ext-json": "*",
"ext-sqlite3": "*",
"ext-zip": "*",
"php-di/php-di": "^6.0",
"php-di/php-di": "^7.0",
"jawira/case-converter": "^3.4",
"symfony/http-foundation": "^4.0|^5.0",
"symfony/filesystem": "^4.0|^5.0",
"symfony/console": "^4.3|^5.1",
"symfony/http-foundation": "^8.0",
"symfony/filesystem": "^8.0",
"symfony/console": "^8.0",
"fakerphp/faker": "^1.13",
"whitecube/lingua": "^1.1",
"ext-fileinfo": "*",
"doctrine/dbal": "^2.5",
"doctrine/dbal": "^4.0",
"ext-pdo": "*"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9.5",
"jtl/connector-cq": "*",
"phpstan/phpstan": "^1.11",
"squizlabs/php_codesniffer": "^3.10",
"micheh/phpcs-gitlab": "^1.1",
"slevomat/coding-standard": "^8.15",
"mockery/mockery": "^1.4",
"jtl/unit-test": "^0.1.3"
"phpunit/phpunit": "^11.0",
"jtl/connector-cq": "^2.0",
"phpstan/phpstan": "^2.0",
"squizlabs/php_codesniffer": "^4.0",
"micheh/phpcs-gitlab": "^2.0",
"slevomat/coding-standard": "^8.29"
},
"provide": {
"jtl/connector-mapping-tables": "4.0.8",
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
<testsuites>
<testsuite name="tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<!--<php>
<env name="XDEBUG_MODE" value="off"/>
</php>-->
</phpunit>
99 changes: 57 additions & 42 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use DI\Definition\Exception\InvalidDefinition;
use DI\DependencyException;
use DI\NotFoundException;
use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Jawira\CaseConverter\CaseConverterException;
use JMS\Serializer\Exception\LogicException;
use JMS\Serializer\Exception\NotAcceptableException;
Expand Down Expand Up @@ -113,8 +111,8 @@

class Application
{
public const PROTOCOL_VERSION = 7;
public const MIN_PHP_VERSION = '7.4';
public const int PROTOCOL_VERSION = 7;
public const string MIN_PHP_VERSION = '8.2';
/** @var array<string, string> */
protected static array $mimeTypeToExtensionMappings = [
'image/bmp' => 'bmp',
Expand Down Expand Up @@ -165,18 +163,17 @@ class Application
* @throws ApplicationException
* @throws ConfigException
* @throws DependencyException
* @throws EmptyDirectoryException
* @throws InvalidArgumentException
* @throws LoggerException
* @throws ReflectionException
* @throws RuntimeException
* @throws InvalidDefinition
* @throws AnnotationException
* @throws \InvalidArgumentException
* @throws InvalidDefinition
* @throws \JMS\Serializer\Exception\InvalidArgumentException
* @throws LogicException
* @throws \JMS\Serializer\Exception\RuntimeException
* @throws LoggerException
* @throws LogicException
* @throws \LogicException
* @throws EmptyDirectoryException
* @throws ReflectionException
* @throws RuntimeException
* @throws \TypeError
* @throws \UnexpectedValueException
*/
Expand All @@ -188,8 +185,6 @@ public function __construct(
if (!\is_dir($connectorDir)) {
throw ApplicationException::connectorDirNotExists($connectorDir);
}
AnnotationRegistry::registerLoader('class_exists');

if ($configSchema !== null && $config !== null) {
if ($config instanceof ConfigSchemaConfigInterface) {
$config->setConfigSchema($configSchema);
Expand All @@ -204,8 +199,7 @@ public function __construct(

$serializerCacheDir = null;
if (
$config instanceof CoreConfigInterface
&& $config->getBool(ConfigSchema::DEBUG, false) === false
$config->getBool(ConfigSchema::DEBUG, false) === false
&& $config->getBool(ConfigSchema::SERIALIZER_ENABLE_CACHE, true) === true
) {
$serializerCacheDir = $config->getString(ConfigSchema::CACHE_DIR);
Expand All @@ -215,7 +209,6 @@ public function __construct(
$this->config = $config;
$this->configSchema = $configSchema;
$this->container = (new ContainerBuilder())
->useAnnotations(true)
->useAutowiring(true)
->build();

Expand Down Expand Up @@ -310,14 +303,14 @@ public function registerController(string $controllerName, object $instance): se
* @throws DependencyException
* @throws FileNotFoundException
* @throws NotFoundException
* @throws \ReflectionException
* @throws RpcException
* @throws SessionException
* @throws Throwable
* @throws \ReflectionException
*/
public function run(ConnectorInterface $connector): void
{
$jtlrpc = Validate::string($this->httpRequest->get('jtlrpc', ''));
$jtlrpc = Validate::string($this->httpRequest->request->get('jtlrpc', ''));
$this->httpResponse->setLogger($this->loggerService->get(LoggerService::CHANNEL_RPC));
$this->eventDispatcher->addSubscriber(new RequestParamsTransformSubscriber());
$this->eventDispatcher->addSubscriber(new FeaturesSubscriber());
Expand Down Expand Up @@ -413,17 +406,17 @@ public function run(ConnectorInterface $connector): void
*
*
* @return void
* @throws BadRequestException
* @throws DatabaseException
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
* @throws RuntimeException
* @throws SessionException
* @throws \InvalidArgumentException
* @throws BadRequestException
* @throws \UnexpectedValueException
*/
protected function startSession(string $rpcMethod): void
{
$sessionId = $this->httpRequest->get('jtlauth');
$sessionId = $this->httpRequest->query->get('jtlauth');
$sessionName = 'JtlConnector';

if ($sessionId === null && $rpcMethod !== RpcMethod::AUTH) {
Expand Down Expand Up @@ -454,9 +447,9 @@ protected function startSession(string $rpcMethod): void
* @return SessionHandlerInterface
* @throws DatabaseException
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
* @throws RuntimeException
* @throws SessionException
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function getSessionHandler(): SessionHandlerInterface
Expand Down Expand Up @@ -506,9 +499,7 @@ protected function initSyncErrorCollector(): void
$sqlite->connect(['location' => $dbLocation]);

$collector = new SqliteSyncErrorCollector($sqlite);
if ($collector instanceof LoggerAwareInterface) {
$collector->setLogger($this->loggerService->get(LoggerService::CHANNEL_GLOBAL));
}
$collector->setLogger($this->loggerService->get(LoggerService::CHANNEL_GLOBAL));

$this->container->set(SyncErrorCollectorInterface::class, $collector);

Expand All @@ -527,10 +518,10 @@ protected function initSyncErrorCollector(): void
* @return void
* @throws DatabaseException
* @throws InvalidArgumentException
* @throws RuntimeException
* @throws SessionException
* @throws \InvalidArgumentException
* @throws \LogicException
* @throws RuntimeException
* @throws SessionException
* @throws \UnexpectedValueException
*/
protected function prepareContainer(ConnectorInterface $connector): void
Expand Down Expand Up @@ -623,13 +614,13 @@ protected function loadPlugins(
* @throws DefinitionException
* @throws DependencyException
* @throws FileNotFoundException
* @throws \InvalidArgumentException
* @throws LinkerException
* @throws NotFoundException
* @throws ReflectionException
* @throws RpcException
* @throws RuntimeException
* @throws Throwable
* @throws \InvalidArgumentException
*/
protected function execute(
ConnectorInterface $connector,
Expand Down Expand Up @@ -722,6 +713,9 @@ protected function execute(
case Action::CLEAR:
case Action::FINISH:
case Action::INIT:
if (!\is_bool($result)) {
throw new \RuntimeException('$result must be a bool.');
}
$eventArg = new BoolEvent($result);
break;
case Action::IDENTIFY:
Expand Down Expand Up @@ -756,13 +750,13 @@ protected function execute(
* @throws DefinitionException
* @throws DependencyException
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
* @throws \JMS\Serializer\Exception\RuntimeException
* @throws LinkerException
* @throws LogicException
* @throws NotAcceptableException
* @throws NotFoundException
* @throws ReflectionException
* @throws \InvalidArgumentException
* @throws NotAcceptableException
* @throws \JMS\Serializer\Exception\RuntimeException
* @throws UnsupportedFormatException
*/
protected function createHandleRequest(
Expand Down Expand Up @@ -814,10 +808,16 @@ protected function createHandleRequest(
$eventArg = null;
switch ($action) {
case Action::ACK:
if (!$param instanceof Ack) {
throw new \RuntimeException('$param must be instance of Ack.');
}
$eventArg = new AckEvent($param);
break;
case Action::PUSH:
case Action::DELETE:
if (!$param instanceof AbstractModel) {
throw new \RuntimeException('$param must be instance of AbstractModel.');
}
/** @var IdentityLinker $identityLinker */
$identityLinker = $this->container->get(IdentityLinker::class);
$identityLinker->linkModel($param);
Expand All @@ -828,10 +828,19 @@ protected function createHandleRequest(
break;
case Action::PULL:
case Action::STATISTIC:
if (!$param instanceof QueryFilter) {
throw new \RuntimeException('$param must be instance of QueryFilter.');
}
$eventArg = new QueryFilterEvent($param);
break;
case Action::CLEAR:
if (!$param instanceof Identities) {
throw new \RuntimeException('$param must be instance of Identities.');
}
foreach ($param->getIdentities() as $relationType => $identities) {
if ($identities === null) {
continue;
}
foreach ($identities as $identity) {
/** @var IdentityLinker $identityLinker */
$identityLinker = $this->container->get(IdentityLinker::class);
Expand Down Expand Up @@ -879,8 +888,8 @@ protected function createModelEventClassName(string $controllerName): string
* @throws ApplicationException
* @throws CompressionException
* @throws DefinitionException
* @throws FileNotFoundException
* @throws \Exception
* @throws FileNotFoundException
*/
protected function handleImagePush(AbstractImage ...$images): void
{
Expand Down Expand Up @@ -1012,6 +1021,7 @@ public function handleRequest(ConnectorInterface $connector, Request $request):
}

$controller = $this->container->get($controllerName);
\assert(\is_object($controller));
if ($controller instanceof LoggerAwareInterface) {
/** @var LoggerInterface $loggerInterface */
$loggerInterface = $this->container->get(LoggerInterface::class);
Expand All @@ -1036,17 +1046,17 @@ public function handleRequest(ConnectorInterface $connector, Request $request):
}

try {
\assert(\method_exists($controller, $action));
/** @var AbstractModel[] $dataModels */
$dataModels = $controller->$action(...$params);

foreach ($dataModels as $dataModel) {
if ($dataModel instanceof AbstractModel) {
/** @var IdentityLinker $identityLinker */
$identityLinker = $this->container->get(IdentityLinker::class);
$identityLinker->linkModel($dataModel, ($request->getAction() === Action::DELETE));
/** @var ChecksumLinker $checksumLinker */
$checksumLinker = $this->container->get(ChecksumLinker::class);
$checksumLinker->link($dataModel);
}
/** @var IdentityLinker $identityLinker */
$identityLinker = $this->container->get(IdentityLinker::class);
$identityLinker->linkModel($dataModel, ($request->getAction() === Action::DELETE));
/** @var ChecksumLinker $checksumLinker */
$checksumLinker = $this->container->get(ChecksumLinker::class);
$checksumLinker->link($dataModel);
$result[] = $dataModel;
}

Expand Down Expand Up @@ -1088,18 +1098,23 @@ public function handleRequest(ConnectorInterface $connector, Request $request):
}
break;
case Action::IDENTIFY:
\assert(\method_exists($controller, $action));
/** @var ConnectorIdentification $result */
$result = $controller->$action($connector);
break;
default:
\assert(\method_exists($controller, $action));
$param = \count($params) > 0 ? \reset($params) : null;
$result = $controller->$action($param);
break;
}

if ($action === Action::STATISTIC && $controller instanceof StatisticInterface) {
$result = (new Statistic())
/** @var int $statisticCount */
$statisticCount = $result;
$result = (new Statistic())
->setControllerName($controllerName)
->setAvailable((int)$result);
->setAvailable($statisticCount);
}

if (!$result instanceof Response) {
Expand Down
2 changes: 1 addition & 1 deletion src/Config/CoreConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface CoreConfigInterface extends ConfigInterface
* @param bool|null $default
*
* @return bool|null
* @throws \TypeError
* @throws ConfigException
* @throws \TypeError
*/
public function getBool(string $valueName, ?bool $default = null): ?bool;

Expand Down
Loading