Bool2TextTransformationsPlugin.php 1.7 KB

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