HexTransformationsPlugin.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the transformations interface */
  13. require_once 'libraries/plugins/TransformationsPlugin.class.php';
  14. /**
  15. * Provides common methods for all of the hex transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class HexTransformationsPlugin 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. 'Displays hexadecimal representation of data. Optional first'
  30. . ' parameter specifies how often space will be added (defaults'
  31. . ' to 2 nibbles).'
  32. );
  33. }
  34. /**
  35. * Does the actual work of each specific transformations plugin.
  36. *
  37. * @param string $buffer text to be transformed
  38. * @param array $options transformation options
  39. * @param string $meta meta information
  40. *
  41. * @return void
  42. */
  43. public function applyTransformation($buffer, $options = array(), $meta = '')
  44. {
  45. // possibly use a global transform and feed it with special options
  46. if (!isset($options[0])) {
  47. $options[0] = 2;
  48. } else {
  49. $options[0] = (int)$options[0];
  50. }
  51. if ($options[0] < 1) {
  52. return bin2hex($buffer);
  53. } else {
  54. return chunk_split(bin2hex($buffer), $options[0], ' ');
  55. }
  56. }
  57. /**
  58. * This method is called when any PluginManager to which the observer
  59. * is attached calls PluginManager::notify()
  60. *
  61. * @param SplSubject $subject The PluginManager notifying the observer
  62. * of an update.
  63. *
  64. * @todo implement
  65. * @return void
  66. */
  67. public function update (SplSubject $subject)
  68. {
  69. ;
  70. }
  71. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  72. /**
  73. * Gets the transformation name of the specific plugin
  74. *
  75. * @return string
  76. */
  77. public static function getName()
  78. {
  79. return "Hex";
  80. }
  81. }
  82. ?>