TransformationsPlugin.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the transformations plugins
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Plugins;
  10. use stdClass;
  11. /**
  12. * Provides a common interface that will have to
  13. * be implemented by all of the transformations plugins.
  14. *
  15. * @package PhpMyAdmin
  16. */
  17. abstract class TransformationsPlugin implements TransformationsInterface
  18. {
  19. /**
  20. * Does the actual work of each specific transformations plugin.
  21. *
  22. * @param array $options transformation options
  23. *
  24. * @return void
  25. */
  26. public function applyTransformationNoWrap(array $options = [])
  27. {
  28. }
  29. /**
  30. * Does the actual work of each specific transformations plugin.
  31. *
  32. * @param string $buffer text to be transformed
  33. * @param array $options transformation options
  34. * @param stdClass|null $meta meta information
  35. *
  36. * @return string the transformed text
  37. */
  38. abstract public function applyTransformation(
  39. $buffer,
  40. array $options = [],
  41. ?stdClass $meta = null
  42. );
  43. /**
  44. * Returns passed options or default values if they were not set
  45. *
  46. * @param string[] $options List of passed options
  47. * @param string[] $defaults List of default values
  48. *
  49. * @return string[] List of options possibly filled in by defaults.
  50. */
  51. public function getOptions(array $options, array $defaults)
  52. {
  53. $result = [];
  54. foreach ($defaults as $key => $value) {
  55. if (isset($options[$key]) && $options[$key] !== '') {
  56. $result[$key] = $options[$key];
  57. } else {
  58. $result[$key] = $value;
  59. }
  60. }
  61. return $result;
  62. }
  63. }