Bool2TextTransformationsPlugin.php 1.7 KB

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