Mark Plugins\Plugin::isAvailable as static method
Allows for checking the availability before creating a new instance. - Fixes https://github.com/phpmyadmin/phpmyadmin/issues/17519 Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
520cb4c150
commit
43cfe7d256
@ -5,6 +5,7 @@ phpMyAdmin - ChangeLog
|
||||
- issue #17522 Fix case where the routes cache file is invalid
|
||||
- issue #17506 Fix error when configuring 2FA without XMLWriter or Imagick
|
||||
- issue Fix blank page when some error occurs
|
||||
- issue #17519 Fix Export pages not working in certain conditions
|
||||
|
||||
5.2.0 (2022-05-10)
|
||||
- issue #16521 Upgrade Bootstrap to version 5
|
||||
|
||||
@ -29,6 +29,7 @@ use function class_exists;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function htmlspecialchars;
|
||||
use function is_subclass_of;
|
||||
use function mb_strpos;
|
||||
use function mb_strtolower;
|
||||
use function mb_strtoupper;
|
||||
@ -111,8 +112,9 @@ class Plugins
|
||||
* Reads all plugin information
|
||||
*
|
||||
* @param string $type the type of the plugin (import, export, etc)
|
||||
* @psalm-param 'Export'|'Import'|'Schema' $type
|
||||
*
|
||||
* @return array list of plugin instances
|
||||
* @return Plugin[] list of plugin instances
|
||||
*/
|
||||
private static function getPlugins(string $type): array
|
||||
{
|
||||
@ -135,16 +137,11 @@ class Plugins
|
||||
}
|
||||
|
||||
$class = sprintf('PhpMyAdmin\\Plugins\\%s\\%s', $type, $fileInfo->getBasename('.php'));
|
||||
if (! class_exists($class)) {
|
||||
if (! class_exists($class) || ! is_subclass_of($class, Plugin::class) || ! $class::isAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugin = new $class();
|
||||
if (! ($plugin instanceof Plugin) || ! $plugin->isAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugins[] = $plugin;
|
||||
$plugins[] = new $class();
|
||||
}
|
||||
|
||||
usort($plugins, static function (Plugin $plugin1, Plugin $plugin2): int {
|
||||
|
||||
@ -321,7 +321,7 @@ class ExportPdf extends ExportPlugin
|
||||
$this->pdf = $pdf;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return class_exists(TCPDF::class);
|
||||
}
|
||||
|
||||
@ -543,7 +543,7 @@ class ExportXml extends ExportPlugin
|
||||
$this->tables = $tables;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
||||
@ -372,7 +372,7 @@ abstract class ExportPlugin implements Plugin
|
||||
return $relation;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ class ImportLdi extends AbstractImportCsv
|
||||
$importPluginProperties->setText('CSV using LOAD DATA');
|
||||
$importPluginProperties->setExtension('ldi');
|
||||
|
||||
if (! $this->isAvailable()) {
|
||||
if (! self::isAvailable()) {
|
||||
return $importPluginProperties;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ class ImportLdi extends AbstractImportCsv
|
||||
$finished = true;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
global $plugin_param;
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ abstract class ImportPlugin implements Plugin
|
||||
];
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -15,5 +15,5 @@ interface Plugin
|
||||
|
||||
public function getProperties(): PluginPropertyItem;
|
||||
|
||||
public function isAvailable(): bool;
|
||||
public static function isAvailable(): bool;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ class SchemaPdf extends SchemaPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return class_exists(TCPDF::class);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ abstract class SchemaPlugin implements Plugin
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -5706,7 +5706,17 @@ parameters:
|
||||
path: libraries/classes/Plugins.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\:\\:getPlugins\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\:\\:getExport\\(\\) should return array\\<PhpMyAdmin\\\\Plugins\\\\ExportPlugin\\> but returns array\\<PhpMyAdmin\\\\Plugins\\\\Plugin\\>\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Plugins.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\:\\:getImport\\(\\) should return array\\<PhpMyAdmin\\\\Plugins\\\\ImportPlugin\\> but returns array\\<PhpMyAdmin\\\\Plugins\\\\Plugin\\>\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Plugins.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\:\\:getSchema\\(\\) should return array\\<PhpMyAdmin\\\\Plugins\\\\SchemaPlugin\\> but returns array\\<PhpMyAdmin\\\\Plugins\\\\Plugin\\>\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Plugins.php
|
||||
|
||||
|
||||
@ -8932,6 +8932,11 @@
|
||||
<InvalidReturnType occurrences="1">
|
||||
<code>string</code>
|
||||
</InvalidReturnType>
|
||||
<LessSpecificReturnStatement occurrences="3">
|
||||
<code>self::getPlugins('Export')</code>
|
||||
<code>self::getPlugins('Import')</code>
|
||||
<code>self::getPlugins('Schema')</code>
|
||||
</LessSpecificReturnStatement>
|
||||
<MixedArgument occurrences="14">
|
||||
<code>$_GET[$opt]</code>
|
||||
<code>$_REQUEST[$opt]</code>
|
||||
@ -8963,20 +8968,16 @@
|
||||
<code>$val</code>
|
||||
<code>$val</code>
|
||||
</MixedAssignment>
|
||||
<MixedMethodCall occurrences="4">
|
||||
<MixedMethodCall occurrences="3">
|
||||
<code>getProperties</code>
|
||||
<code>new $class()</code>
|
||||
<code>new $class()</code>
|
||||
<code>new $class()</code>
|
||||
</MixedMethodCall>
|
||||
<MixedReturnTypeCoercion occurrences="6">
|
||||
<MoreSpecificReturnType occurrences="3">
|
||||
<code>ExportPlugin[]</code>
|
||||
<code>ImportPlugin[]</code>
|
||||
<code>SchemaPlugin[]</code>
|
||||
<code>self::getPlugins('Export')</code>
|
||||
<code>self::getPlugins('Import')</code>
|
||||
<code>self::getPlugins('Schema')</code>
|
||||
</MixedReturnTypeCoercion>
|
||||
</MoreSpecificReturnType>
|
||||
<PossiblyInvalidArgument occurrences="2">
|
||||
<code>$val</code>
|
||||
<code>$val</code>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user