Plugins.php 2.0 KB

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