RegexValidationTransformationsPlugin.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the regex validation input transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage RegexValidation
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\IOTransformationsPlugin;
  11. /**
  12. * Provides common methods for all of the regex validation
  13. * input transformations plugins.
  14. *
  15. * @package PhpMyAdmin-Transformations
  16. * @subpackage RegexValidation
  17. */
  18. abstract class RegexValidationTransformationsPlugin extends IOTransformationsPlugin
  19. {
  20. /**
  21. * Gets the transformation description of the specific plugin
  22. *
  23. * @return string
  24. */
  25. public static function getInfo()
  26. {
  27. return __(
  28. 'Validates the string using regular expression '
  29. . 'and performs insert only if string matches it. '
  30. . 'The first option is the Regular Expression.'
  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 string $meta meta information
  39. *
  40. * @return string
  41. */
  42. public function applyTransformation($buffer, array $options = array(), $meta = '')
  43. {
  44. // reset properties of object
  45. $this->reset();
  46. if (!empty($options[0]) && !preg_match($options[0], $buffer)) {
  47. $this->success = false;
  48. $this->error = sprintf(
  49. __('Validation failed for the input string %s.'),
  50. htmlspecialchars($buffer)
  51. );
  52. }
  53. return $buffer;
  54. }
  55. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  56. /**
  57. * Gets the transformation name of the specific plugin
  58. *
  59. * @return string
  60. */
  61. public static function getName()
  62. {
  63. return "Regex Validation";
  64. }
  65. }