Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -9,98 +9,90 @@
namespace App\Plugin;
use App\Constants;
class PluginMetadata
{
/**
* @var string
*/
private $version;
/**
* @var string
*/
private $kimaiVersion;
/**
* @var string
*/
private $homepage;
/**
* @var string
*/
private $description;
private ?string $version = null;
private ?int $kimaiVersion = null;
private ?string $homepage = null;
private ?string $description = null;
private ?string $name = null;
/**
* @return string
* @param string $path
* @return PluginMetadata
* @throws \Exception
*/
public static function loadFromComposer(string $path): PluginMetadata
{
if (!is_dir($path) || !is_readable($path)) {
throw new \Exception(sprintf('Bundle directory "%s" cannot be accessed.', $path));
}
$pluginName = basename($path);
$composer = $path . '/composer.json';
if (!file_exists($composer) || !is_readable($composer)) {
throw new \Exception(sprintf('Bundle "%s" does not ship composer.json, which is required since 2.0.', $pluginName));
}
$json = json_decode(file_get_contents($composer), true);
if (!\array_key_exists('extra', $json)) {
throw new \Exception(sprintf('Bundle "%s" does not define an "extra" node in composer.json, which is required since 2.0.', $pluginName));
}
if (!\array_key_exists('kimai', $json['extra'])) {
throw new \Exception(sprintf('Bundle "%s" does not define the "extra.kimai" node in composer.json, which is required since 2.0.', $pluginName));
}
if (!\array_key_exists('require', $json['extra']['kimai'])) {
throw new \Exception(sprintf('Bundle "%s" does not define the minimum Kimai version in "extra.kimai.required" in composer.json, which is required since 2.0.', $pluginName));
}
if (!\array_key_exists('name', $json['extra']['kimai'])) {
throw new \Exception(sprintf('Bundle "%s" does not define its name in "extra.kimai.name" in composer.json, which is required since 2.0.', $pluginName));
}
if (!\is_int($json['extra']['kimai']['require'])) {
throw new \Exception(sprintf('Bundle "%s" defines an invalid Kimai minimum version in extra.kimai.require. Please provide an integer as in Constants::VERSION_ID.', $pluginName));
}
$meta = new self();
$meta->description = $json['description'] ?? '';
$meta->homepage = $json['homepage'] ?? Constants::HOMEPAGE . '/store/';
$meta->name = $json['extra']['kimai']['name'];
$meta->kimaiVersion = $json['extra']['kimai']['require'];
// the version field is required if we use composer to install a plugin via var/packages/
$meta->version = $json['extra']['kimai']['version'] ?? ($json['version'] ?? 'unknown');
return $meta;
}
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string $description
* @return PluginMetadata
*/
public function setDescription(string $description)
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getVersion(): ?string
{
return $this->version;
}
/**
* @param string $version
* @return PluginMetadata
*/
public function setVersion(string $version)
{
$this->version = $version;
return $this;
}
/**
* @return string
*/
public function getKimaiVersion(): ?string
public function getKimaiVersion(): ?int
{
return $this->kimaiVersion;
}
/**
* @param string $kimaiVersion
* @return PluginMetadata
*/
public function setKimaiVersion(string $kimaiVersion)
{
$this->kimaiVersion = $kimaiVersion;
return $this;
}
/**
* @return string
*/
public function getHomepage(): ?string
{
return $this->homepage;
}
/**
* @param string $homepage
* @return PluginMetadata
*/
public function setHomepage(string $homepage)
public function getName(): ?string
{
$this->homepage = $homepage;
return $this;
return $this->name;
}
}