Bool2TextTransformationsPlugin.php 1.8 KB

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