Bool2TextTransformationsPlugin.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Abstract class for the Bool2Text transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\Plugins\TransformationsPlugin;
  8. use stdClass;
  9. /**
  10. * Provides common methods for all of the Bool2Text transformations plugins.
  11. */
  12. abstract class Bool2TextTransformationsPlugin extends TransformationsPlugin
  13. {
  14. /**
  15. * Gets the transformation description of the specific plugin
  16. *
  17. * @return string
  18. */
  19. public static function getInfo()
  20. {
  21. return __(
  22. 'Converts Boolean values to text (default \'T\' and \'F\').'
  23. . ' First option is for TRUE, second for FALSE. Nonzero=true.'
  24. );
  25. }
  26. /**
  27. * Does the actual work of each specific transformations plugin.
  28. *
  29. * @param string $buffer text to be transformed
  30. * @param array $options transformation options
  31. * @param stdClass|null $meta meta information
  32. *
  33. * @return string
  34. */
  35. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  36. {
  37. $cfg = $GLOBALS['cfg'];
  38. $options = $this->getOptions($options, $cfg['DefaultTransformations']['Bool2Text']);
  39. if ($buffer == '0') {
  40. return $options[1]; // return false label
  41. }
  42. return $options[0]; // or true one if nonzero
  43. }
  44. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  45. /**
  46. * Gets the transformation name of the specific plugin
  47. *
  48. * @return string
  49. */
  50. public static function getName()
  51. {
  52. return 'Bool2Text';
  53. }
  54. }