Skip to content
Merged
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
33 changes: 33 additions & 0 deletions src/Classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace RobinTheHood\ModifiedModuleLoaderClient;

use RobinTheHood\ModifiedModuleLoaderClient\App;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Comparator;

class Config
{
Expand Down Expand Up @@ -428,4 +429,36 @@ public static function getLogging(): bool

return $logging === 'true';
}


/**
* Set exceptionMonitorMail in config.
*
* @param string $newExceptionMonitorMail.
*/
public static function setDependencyMode(string $dependencyMode): void
{
self::writeConfiguration(['dependencyMode' => $dependencyMode]);
}

/**
* Get dependencyMode from config.
*
* @return int Returns logging from config or null.
*/
public static function getDependenyMode(): int
{
/**
* Expect a string or null
* depending if the user specified an email address.
* You will not receive an empty string.
*/
$dependencyMode = self::getOption('dependencyMode');

if ($dependencyMode === 'strict') {
return Comparator::CARET_MODE_STRICT;
}

return Comparator::CARET_MODE_LAX;
}
}
7 changes: 3 additions & 4 deletions src/Classes/DependencyManager/CombinationSatisfyer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace RobinTheHood\ModifiedModuleLoaderClient\DependencyManager;

use RobinTheHood\ModifiedModuleLoaderClient\Semver\Comparator;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Parser;
use RobinTheHood\ModifiedModuleLoaderClient\SemverComparatorFactory;

class CombinationSatisfyer
{
Expand All @@ -23,7 +23,7 @@ class CombinationSatisfyer

public function __construct()
{
$this->comparator = new Comparator(new Parser());
$this->comparator = SemverComparatorFactory::createComparator();
}

/**
Expand Down Expand Up @@ -117,9 +117,8 @@ public function satisfiesCominationsFromModuleWithIterator(
ModuleTree $moduleTree,
CombinationIterator $combinationIterator
): CombinationSatisfyerResult {
$foundCombination = new Combination();

while (true) {
$foundCombination = new Combination();
$failLog = new FailLog();
$testCombination = $combinationIterator->current();
$result = $this->satisfiesCominationFromModuleTree(
Expand Down
5 changes: 3 additions & 2 deletions src/Classes/DependencyManager/DependencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
use RobinTheHood\ModifiedModuleLoaderClient\Logger\LogLevel;
use RobinTheHood\ModifiedModuleLoaderClient\Logger\StaticLogger;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Comparator;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Parser;
use RobinTheHood\ModifiedModuleLoaderClient\SemverComparatorFactory;

class DependencyManager
{
/** @var Comparator */
protected $comparator;

public function __construct()
{
$this->comparator = new Comparator(new Parser());
$this->comparator = SemverComparatorFactory::createComparator();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Classes/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ public function invokeSettings()
Config::setInstallMode($parsedBody['installMode']);
}

if (isset($parsedBody['dependencyMode'])) {
Config::setDependencyMode($parsedBody['dependencyMode']);
}

Notification::pushFlashMessage([
'text' => 'Einstellungen erfolgreich gespeichert.',
'type' => 'success'
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/MmlcVersionInfoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MmlcVersionInfoLoader
public static function createLoader(): MmlcVersionInfoLoader
{
$parser = new Parser();
$comparator = new Comparator($parser);
$comparator = new Comparator($parser, Comparator::CARET_MODE_STRICT);
$sorter = new Sorter($comparator);
$filter = new Filter($parser, $comparator, $sorter);

Expand Down
4 changes: 2 additions & 2 deletions src/Classes/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public function isCompatibleWithPhp(): bool
}

$phpVersionInstalled = phpversion();
$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
return $comparator->satisfies($phpVersionInstalled, $phpVersionContraint);
}

Expand All @@ -532,7 +532,7 @@ public function isCompatibleWithMmlc(): bool
return true;
}

$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
return $comparator->satisfies($mmlcVersionInstalled, $mmlcVersionContraint);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Classes/ModuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function filterNewestVersion(array $modules): array
continue;
}

$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if ($comparator->lessThan($module->getVersion(), $filteredModule->getVersion())) {
$insertOrReplace = false;
break;
Expand Down Expand Up @@ -162,7 +162,7 @@ public static function filterNewestOrInstalledVersion($modules): array
break;
}

$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if ($comparator->lessThan($module->getVersion(), $filteredModule->getVersion())) {
$insertOrReplace = false;
break;
Expand Down Expand Up @@ -215,7 +215,7 @@ public static function filterByVersionConstrain(array $modules, string $constrai
{
$filteredModules = [];
foreach ($modules as $module) {
$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if ($comparator->satisfies($module->getVersion(), $constrain)) {
$filteredModules[] = $module;
}
Expand All @@ -230,7 +230,7 @@ public static function getLatestVersion(array $modules): ?Module
{
$selectedModule = null;
foreach ($modules as $module) {
$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if (!$selectedModule || $comparator->greaterThan($module->getVersion(), $selectedModule->getVersion())) {
$selectedModule = $module;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/ModuleSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function sortByCategory($modules): array
public static function sortByVersion(array $modules): array
{
usort($modules, function (Module $moduleA, Module $moduleB): int {
$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if ($comparator->lessThan($moduleA->getVersion(), $moduleB->getVersion())) {
return 1;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/ModuleStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function isUpdatable(Module $module): bool
return false;
}

$comparator = new Comparator(new Parser());
$comparator = SemverComparatorFactory::createComparator();
if (!$comparator->greaterThan($newestVersion->getVersion(), $installedVersion->getVersion())) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/SelfUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(MmlcVersionInfoLoader $mmlcVersionInfoLoader)
$this->appRoot = App::getRoot();
$this->mmlcVersionInfoLoader = $mmlcVersionInfoLoader;
$this->remoteUpdateServer = $this->getRomteUpdateServer();
$this->comparator = new Comparator(new Parser());
$this->comparator = new Comparator(new Parser(), Comparator::CARET_MODE_STRICT);
$this->parser = new Parser();
$this->filter = new Filter($this->parser, $this->comparator, new Sorter($this->comparator));
}
Expand Down
29 changes: 26 additions & 3 deletions src/Classes/Semver/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@

class Comparator
{
public const CARET_MODE_LAX = 0;
public const CARET_MODE_STRICT = 1;

/** @var Parser */
protected $parser;

public function __construct(Parser $parser)
/** @var int */
private $mode = self::CARET_MODE_STRICT;

public function __construct(Parser $parser, int $mode = self::CARET_MODE_STRICT)
{
$this->parser = $parser;
}
Expand Down Expand Up @@ -156,8 +163,24 @@ public function isCompatible(string $versionString1, string $versionString2): bo
$version1 = $this->parser->parse($versionString1);
$version2 = $this->parser->parse($versionString2);

if ($version1->getMajor() != $version2->getMajor()) {
return false;
$majorCheck = $version1->getMajor() == $version2->getMajor();
$minorCheck = $version1->getMinor() == $version2->getMinor();
$patchCheck = $version1->getPatch() == $version2->getPatch();

$strict = $this->mode === self::CARET_MODE_STRICT;

if ($version1->getMajor() >= 1) { // ^1.0.0
if (!$majorCheck) {
return false;
}
} elseif ($strict && $version1->getMajor() == 0 && $version1->getMinor() >= 1) { // ^0.1.0
if (!$majorCheck || !$minorCheck) {
return false;
}
} elseif ($strict && $version1->getMajor() == 0 && $version1->getMinor() == 0) { // ^0.0.0
if (!$majorCheck || !$minorCheck || !$patchCheck) {
return false;
}
}

return $this->greaterThanOrEqualTo($versionString1, $versionString2);
Expand Down
29 changes: 29 additions & 0 deletions src/Classes/SemverComparatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/*
* This file is part of MMLC - ModifiedModuleLoaderClient.
*
* (c) Robin Wieschendorf <mail@robinwieschendorf.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RobinTheHood\ModifiedModuleLoaderClient;

use RobinTheHood\ModifiedModuleLoaderClient\Semver\Comparator;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Parser;

class SemverComparatorFactory
{
/**
* @return Comparator
*/
public static function createComparator()
{
$comparator = new Comparator(new Parser(), Config::getDependenyMode());
return $comparator;
}
}
17 changes: 17 additions & 0 deletions src/Templates/Settings.tmpl.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php

/**
* @phpcs:disable PSR1.Files.SideEffects
* @phpcs:disable Generic.Files.LineLength.TooLong
*/

defined('LOADED_FROM_INDEX') && LOADED_FROM_INDEX ?? die('Access denied.');

use RobinTheHood\ModifiedModuleLoaderClient\Config;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\Comparator;
use RobinTheHood\ModifiedModuleLoaderClient\ViewModels\NotificationViewModel;

$notificationView = new NotificationViewModel();
Expand Down Expand Up @@ -104,6 +110,17 @@ function viewIsSelected(bool $value): string
<p>In diesem Ordner werden Module für den MMLC heruntergeladen.</p>
</div>

<!-- installMode -->
<div class="form-group">
<label for="inputDependencyMode">Abhängigkeitsmodus</label>
<select name="dependencyMode" class="form-control" id="dependencyMode" size="1">
<option <?= viewIsSelected(Config::getDependenyMode() === Comparator::CARET_MODE_STRICT) ?> value="strict">strict</option>
<option <?= viewIsSelected(Config::getDependenyMode() === Comparator::CARET_MODE_LAX) ?> value="lax">lax</option>
</select>

<p>Du kannst zwischen <code>strict</code> und <code>lax</code> wählen. Mit <code>strict</code> werden die Abhänigkeiten von Modulen mit einer Version kleiner als 1.0.0 genauer kontrolliert. Wenn sich einige Module nicht installieren lassen, kannst du es mit <code>lax</code> versuchen. Beachte, dass im Lex-Modus die Wahrscheinlichkeit größer ist, dass verschiedene Module nicht miteinander harmonieren.</p>
</div>

<!-- installMode -->
<div class="form-group">
<label for="inputInstallMode">Installationsmodus</label>
Expand Down
62 changes: 57 additions & 5 deletions tests/unit/DependencyManager/DependencyBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
namespace RobinTheHood\ModifiedModuleLoaderClient\Tests\Unit\DependencyManager;

use PHPUnit\Framework\TestCase;
use RobinTheHood\ModifiedModuleLoaderClient\DependencyManager\CombinationSatisfyerResult;
use RobinTheHood\ModifiedModuleLoaderClient\DependencyManager\DependencyBuilder;
use RobinTheHood\ModifiedModuleLoaderClient\DependencyManager\SystemSet;

class DependencyBuilderTest extends TestCase
{
public function testSatisfies()
public function testSatisfies1()
{
$dependencyBuilder = new DependencyBuilder();
$systemSet = new SystemSet();
Expand Down Expand Up @@ -47,26 +48,77 @@ public function testSatisfies()
"robinthehood/modified-orm" => '1.8.1',
"robinthehood/modified-ui" => '0.1.0',
"robinthehood/pdf-bill" => '0.17.0',
"robinthehood/tfpdf" => '0.3.0',
'firstweb/multi-order' => '1.13.3',
'firstweb/multi-order' => '1.0.3',
"foo/bar" => '1.2.3'
],
$combinationSatisfyerResult->testCombination->getAll()
);


$this->assertEqualsCanonicalizing(
[
"modified" => '2.0.4.2',
"composer/autoload" => '1.3.0',
'firstweb/multi-order' => '1.0.3',
],
$combinationSatisfyerResult->foundCombination->getAll()
);

$this->assertEquals(
CombinationSatisfyerResult::RESULT_COMBINATION_FOUND,
$combinationSatisfyerResult->result
);
}

public function testSatisfies2()
{
$dependencyBuilder = new DependencyBuilder();
$systemSet = new SystemSet();

$systemSet->set([
"modified" => '2.0.4.2',
"php" => '7.4.0',
"mmlc" => '1.20.0-beta.1',
"composer/autoload" => '1.3.0',
"robinthehood/modified-std-module" => '0.9.0',
"robinthehood/modified-orm" => '1.8.1',
"robinthehood/pdf-bill" => '0.17.0',
"foo/bar" => '1.2.3'
]);

$combinationSatisfyerResult = $dependencyBuilder->satisfies('firstweb/multi-order', '^1.10.0', $systemSet);

$this->assertEqualsCanonicalizing(
[
"modified" => '2.0.4.2',
"php" => '7.4.0',
"mmlc" => '1.20.0-beta.1',
"composer/autoload" => '1.3.0',
"robinthehood/modified-std-module" => '0.9.0',
"robinthehood/modified-orm" => '1.8.1',
"robinthehood/modified-ui" => '0.1.0',
"robinthehood/pdf-bill" => '0.17.0',
"robinthehood/tfpdf" => '0.3.0',
'firstweb/multi-order' => '1.13.3',
'firstweb/multi-order' => '1.10.0',
"foo/bar" => '1.2.3'
],
$combinationSatisfyerResult->testCombination->getAll()
);


$this->assertEqualsCanonicalizing(
[
"modified" => '2.0.4.2',
"composer/autoload" => '1.3.0',
'firstweb/multi-order' => '1.10.0',
"robinthehood/modified-orm" => '1.8.1',
],
$combinationSatisfyerResult->foundCombination->getAll()
);

$this->assertEquals(
CombinationSatisfyerResult::RESULT_COMBINATION_NOT_FOUND,
$combinationSatisfyerResult->result
);
}

public function atestInvokeDependency()
Expand Down
Loading