HexTransformationsPlugin.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the hex transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage Hex
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. /**
  12. * Provides common methods for all of the hex transformations plugins.
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. abstract class HexTransformationsPlugin extends TransformationsPlugin
  17. {
  18. /**
  19. * Gets the transformation description of the specific plugin
  20. *
  21. * @return string
  22. */
  23. public static function getInfo()
  24. {
  25. return __(
  26. 'Displays hexadecimal representation of data. Optional first'
  27. . ' parameter specifies how often space will be added (defaults'
  28. . ' to 2 nibbles).'
  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. // possibly use a global transform and feed it with special options
  43. $cfg = $GLOBALS['cfg'];
  44. $options = $this->getOptions($options, $cfg['DefaultTransformations']['Hex']);
  45. $options[0] = intval($options[0]);
  46. if ($options[0] < 1) {
  47. return bin2hex($buffer);
  48. } else {
  49. return chunk_split(bin2hex($buffer), $options[0], ' ');
  50. }
  51. }
  52. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  53. /**
  54. * Gets the transformation name of the specific plugin
  55. *
  56. * @return string
  57. */
  58. public static function getName()
  59. {
  60. return "Hex";
  61. }
  62. }