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
17 changes: 17 additions & 0 deletions src/Classes/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ public static function getModulesDirName(): string
return self::$modulesDir;
}

public static function getMmlcVersion(): string
{
$path = self::getRoot() . '/config/version.json';
if (!file_exists($path)) {
return '';
}

$json = file_get_contents($path);
$version = json_decode($json);

if (!$version) {
return ''; // Better throw an exception
}

return $version->version;
}

public static function start(): void
{
$serverRequest = self::getServerRequest();
Expand Down
24 changes: 24 additions & 0 deletions src/Classes/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ public function isCompatible(): bool
return false;
}

if (!$this->isCompatibleWithMmlc()) {
return false;
}

return true;
}

Expand Down Expand Up @@ -486,6 +490,26 @@ public function isCompatibleWithPhp(): bool
return $comparator->satisfiesOr($phpVersionInstalled, $phpVersionContraint);
}

/**
* Version 1.20.0 is the last version without isCompatibleWithMmlc()
*/
public function isCompatibleWithMmlc(): bool
{
$mmlcVersionInstalled = App::getMmlcVersion();
if (!$mmlcVersionInstalled) {
return false;
}

$mmlc = $this->getMmlc();
$mmlcVersionContraint = $mmlc['version'] ?? '^1.20.0';
if (!$mmlcVersionContraint) {
return true;
}

$comparator = new Comparator(new Parser());
return $comparator->satisfiesOr($mmlcVersionInstalled, $mmlcVersionContraint);
}

public function getTemplateFiles($file): array
{
$files = [];
Expand Down
3 changes: 2 additions & 1 deletion src/Classes/ModuleConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static function convertToArray(Module $module): array
'price' => $module->getPrice(),
'autoload' => $module->getAutoload(),
'tags' => $module->getTags(),
'php' => $module->getPhp()
'php' => $module->getPhp(),
'mmlc' => $module->getMmlc()
];

$moduleArray = [
Expand Down
1 change: 1 addition & 0 deletions src/Classes/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static function createFromArray(array $array): Module
$module->setAutoload($autoload);
$module->setTags($array['tags'] ?? '');
$module->setPhp($array['php'] ?? []);
$module->setMmlc($array['mmlc'] ?? []);

// Module
$module->setLocalRootPath($array['localRootPath'] ?? '');
Expand Down
22 changes: 21 additions & 1 deletion src/Classes/ModuleInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,23 @@ class ModuleInfo
* Mit welchen Version von PHP ist das Modul kompatible.
*
* Beispiel: [
* 'version' => '^7.4 || ^8.0'
* 'version' => '^7.4.0 || ^8.0.0'
* ]
*
* @var array
*/
protected $php;

/**
* Mit welchen Version von PHP ist das Modul kompatible.
*
* Beispiel: [
* 'version' => '^1.20.0'
* ]
*
* @var array
*/
protected $mmlc;

public function getName(): string
{
Expand Down Expand Up @@ -372,4 +382,14 @@ public function setPhp(array $value): void
{
$this->php = $value;
}

public function getMmlc(): array
{
return $this->mmlc;
}

public function setMmlc(array $value): void
{
$this->mmlc = $value;
}
}
8 changes: 7 additions & 1 deletion src/Classes/ViewModels/ModuleViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace RobinTheHood\ModifiedModuleLoaderClient\ViewModels;

use RobinTheHood\ModifiedModuleLoaderClient\App;
use RobinTheHood\ModifiedModuleLoaderClient\Module;
use RobinTheHood\ModifiedModuleLoaderClient\ModuleStatus;
use RobinTheHood\ModifiedModuleLoaderClient\ShopInfo;
Expand Down Expand Up @@ -203,7 +204,12 @@ public function getCompatibleStrings(): array

if (!$this->module->isCompatibleWithPhp()) {
$version = phpversion();
$array[] = "Dieses Modul wurde noch nicht mit deiner PHP Version getestet. Du hast PHP Version <strong>$version</strong> installiert.";
$array[] = "Dieses Modul wurde noch nicht mit deiner PHP Version getestet. Du verwendest die PHP Version <strong>$version</strong>.";
}

if (!$this->module->isCompatibleWithMmlc()) {
$version = App::getMmlcVersion();
$array[] = "Dieses Modul wurde noch nicht mit deiner MMLC Version getestet. Du verwendest die MMLC Version <strong>$version</strong>.";
}

return $array;
Expand Down
13 changes: 13 additions & 0 deletions src/Templates/ModuleInfo.tmpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@
</td>
</tr>

<tr>
<td>Kompatibel mit MMLC</td>
<td>
<?php if (true || $module->getMmlc()) { ?>
<?php foreach (explode('||', $module->getMmlc()['version'] ?? '^1.20.0') as $version) { ?>
<span class="badge badge-secondary"><?= trim($version); ?></span>
<?php } ?>
<?php } else { ?>
unbekannt
<?php } ?>
</td>
</tr>

<?php if ($module->getTags()) { ?>
<tr>
<td>Tags</td>
Expand Down