TransformationsPlugin.php 1.6 KB

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