ImportPlugin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Abstract class for the import plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins;
  7. use PhpMyAdmin\File;
  8. use PhpMyAdmin\Import;
  9. use PhpMyAdmin\Properties\Plugins\ImportPluginProperties;
  10. use function strlen;
  11. /**
  12. * Provides a common interface that will have to be implemented by all of the
  13. * import plugins.
  14. */
  15. abstract class ImportPlugin
  16. {
  17. /**
  18. * ImportPluginProperties object containing the import plugin properties
  19. *
  20. * @var ImportPluginProperties
  21. */
  22. protected $properties;
  23. /** @var Import */
  24. protected $import;
  25. public function __construct()
  26. {
  27. $this->import = new Import();
  28. }
  29. /**
  30. * Handles the whole import logic
  31. *
  32. * @param array $sql_data 2-element array with sql data
  33. *
  34. * @return void
  35. */
  36. abstract public function doImport(?File $importHandle = null, array &$sql_data = []);
  37. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  38. /**
  39. * Gets the import specific format plugin properties
  40. *
  41. * @return ImportPluginProperties
  42. */
  43. public function getProperties()
  44. {
  45. return $this->properties;
  46. }
  47. /**
  48. * Sets the export plugins properties and is implemented by each import
  49. * plugin
  50. *
  51. * @return void
  52. */
  53. abstract protected function setProperties();
  54. /**
  55. * Define DB name and options
  56. *
  57. * @param string $currentDb DB
  58. * @param string $defaultDb Default DB name
  59. *
  60. * @return array DB name and options (an associative array of options)
  61. */
  62. protected function getDbnameAndOptions($currentDb, $defaultDb)
  63. {
  64. if (strlen((string) $currentDb) > 0) {
  65. $db_name = $currentDb;
  66. $options = ['create_db' => false];
  67. } else {
  68. $db_name = $defaultDb;
  69. $options = null;
  70. }
  71. return [
  72. $db_name,
  73. $options,
  74. ];
  75. }
  76. }