LongToIPv4TransformationsPlugin.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Abstract class for the long to IPv4 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 PhpMyAdmin\Utils\FormatConverter;
  10. use function __;
  11. use function htmlspecialchars;
  12. /**
  13. * Provides common methods for all of the long to IPv4 transformations plugins.
  14. */
  15. abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin
  16. {
  17. /**
  18. * Gets the transformation description of the specific plugin
  19. *
  20. * @return string
  21. */
  22. public static function getInfo()
  23. {
  24. return __(
  25. 'Converts an (IPv4) Internet network address stored as a BIGINT'
  26. . ' into a string in Internet standard dotted format.'
  27. );
  28. }
  29. /**
  30. * Does the actual work of each specific transformations plugin.
  31. *
  32. * @param string $buffer text to be transformed
  33. * @param array $options transformation options
  34. * @param FieldMetadata|null $meta meta information
  35. *
  36. * @return string
  37. */
  38. public function applyTransformation($buffer, array $options = [], ?FieldMetadata $meta = null)
  39. {
  40. return htmlspecialchars(FormatConverter::longToIp($buffer));
  41. }
  42. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  43. /**
  44. * Gets the transformation name of the specific plugin
  45. *
  46. * @return string
  47. */
  48. public static function getName()
  49. {
  50. return 'Long To IPv4';
  51. }
  52. }