Plugins.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Server;
  4. use PhpMyAdmin\DatabaseInterface;
  5. class Plugins
  6. {
  7. /** @var DatabaseInterface */
  8. private $dbi;
  9. /**
  10. * @param DatabaseInterface $dbi DatabaseInterface instance
  11. */
  12. public function __construct(DatabaseInterface $dbi)
  13. {
  14. $this->dbi = $dbi;
  15. }
  16. /**
  17. * @return Plugin[]
  18. */
  19. public function getAll(): array
  20. {
  21. global $cfg;
  22. $sql = 'SHOW PLUGINS';
  23. if (! $cfg['Server']['DisableIS']) {
  24. $sql = 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME';
  25. }
  26. $result = $this->dbi->query($sql);
  27. $plugins = [];
  28. while ($row = $this->dbi->fetchAssoc($result)) {
  29. $plugins[] = $this->mapRowToPlugin($row);
  30. }
  31. $this->dbi->freeResult($result);
  32. return $plugins;
  33. }
  34. /**
  35. * @param array $row Row fetched from database
  36. */
  37. private function mapRowToPlugin(array $row): Plugin
  38. {
  39. return Plugin::fromState([
  40. 'name' => $row['PLUGIN_NAME'] ?? $row['Name'],
  41. 'version' => $row['PLUGIN_VERSION'] ?? null,
  42. 'status' => $row['PLUGIN_STATUS'] ?? $row['Status'],
  43. 'type' => $row['PLUGIN_TYPE'] ?? $row['Type'],
  44. 'typeVersion' => $row['PLUGIN_TYPE_VERSION'] ?? null,
  45. 'library' => $row['PLUGIN_LIBRARY'] ?? $row['Library'] ?? null,
  46. 'libraryVersion' => $row['PLUGIN_LIBRARY_VERSION'] ?? null,
  47. 'author' => $row['PLUGIN_AUTHOR'] ?? null,
  48. 'description' => $row['PLUGIN_DESCRIPTION'] ?? null,
  49. 'license' => $row['PLUGIN_LICENSE'] ?? $row['License'],
  50. 'loadOption' => $row['LOAD_OPTION'] ?? null,
  51. 'maturity' => $row['PLUGIN_MATURITY'] ?? null,
  52. 'authVersion' => $row['PLUGIN_AUTH_VERSION'] ?? null,
  53. ]);
  54. }
  55. }