LongToIPv4TransformationsPlugin.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the long to IPv4 transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage LongToIPv4
  8. */
  9. declare(strict_types=1);
  10. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  11. use PhpMyAdmin\Plugins\TransformationsPlugin;
  12. use PhpMyAdmin\Util;
  13. use stdClass;
  14. /**
  15. * Provides common methods for all of the long to IPv4 transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class LongToIPv4TransformationsPlugin 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. 'Converts an (IPv4) Internet network address stored as a BIGINT'
  30. . ' into a string in Internet standard dotted format.'
  31. );
  32. }
  33. /**
  34. * Does the actual work of each specific transformations plugin.
  35. *
  36. * @param string $buffer text to be transformed
  37. * @param array $options transformation options
  38. * @param stdClass|null $meta meta information
  39. *
  40. * @return string
  41. */
  42. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  43. {
  44. if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
  45. return htmlspecialchars($buffer);
  46. }
  47. return long2ip((int) $buffer);
  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 "Long To IPv4";
  58. }
  59. }