Text_Plain_Binarytoip.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Handles the binary to IPv4/IPv6 transformation for text plain
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Output;
  7. use PhpMyAdmin\FieldMetadata;
  8. use PhpMyAdmin\Plugins\TransformationsPlugin;
  9. use PhpMyAdmin\Utils\FormatConverter;
  10. use function __;
  11. /**
  12. * Handles the binary to IPv4/IPv6 transformation for text plain
  13. */
  14. class Text_Plain_Binarytoip extends TransformationsPlugin
  15. {
  16. /**
  17. * Gets the transformation description of the plugin
  18. *
  19. * @return string
  20. */
  21. public static function getInfo()
  22. {
  23. return __(
  24. 'Converts an Internet network address stored as a binary string'
  25. . ' into a string in Internet standard (IPv4/IPv6) format.'
  26. );
  27. }
  28. /**
  29. * Does the actual work of each specific transformations plugin.
  30. *
  31. * @param string $buffer text to be transformed. a binary string containing
  32. * an IP address, as returned from MySQL's INET6_ATON
  33. * function
  34. * @param array $options transformation options
  35. * @param FieldMetadata|null $meta meta information
  36. *
  37. * @return string IP address
  38. */
  39. public function applyTransformation($buffer, array $options = [], ?FieldMetadata $meta = null)
  40. {
  41. $isBinary = ($meta !== null && $meta->isBinary);
  42. return FormatConverter::binaryToIp($buffer, $isBinary);
  43. }
  44. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  45. /**
  46. * Gets the transformation name of the plugin
  47. *
  48. * @return string
  49. */
  50. public static function getName()
  51. {
  52. return 'Binary To IPv4/IPv6';
  53. }
  54. /**
  55. * Gets the plugin`s MIME type
  56. *
  57. * @return string
  58. */
  59. public static function getMIMEType()
  60. {
  61. return 'Text';
  62. }
  63. /**
  64. * Gets the plugin`s MIME subtype
  65. *
  66. * @return string
  67. */
  68. public static function getMIMESubtype()
  69. {
  70. return 'Plain';
  71. }
  72. }