RegexValidationTransformationsPlugin.class.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the transformations class */
  13. require_once 'libraries/plugins/IOTransformationsPlugin.class.php';
  14. /**
  15. * Provides common methods for all of the regex validation
  16. * input transformations plugins.
  17. *
  18. * @package PhpMyAdmin-Transformations
  19. * @subpackage RegexValidation
  20. */
  21. abstract class RegexValidationTransformationsPlugin extends IOTransformationsPlugin
  22. {
  23. /**
  24. * Gets the transformation description of the specific plugin
  25. *
  26. * @return string
  27. */
  28. public static function getInfo()
  29. {
  30. return __(
  31. 'Validates the string using regular expression '
  32. . 'and performs insert only if string matches it. '
  33. . 'The first option is the Regular Expression.'
  34. );
  35. }
  36. /**
  37. * Does the actual work of each specific transformations plugin.
  38. *
  39. * @param string $buffer text to be transformed
  40. * @param array $options transformation options
  41. * @param string $meta meta information
  42. *
  43. * @return string
  44. */
  45. public function applyTransformation($buffer, $options = array(), $meta = '')
  46. {
  47. // reset properties of object
  48. $this->reset();
  49. if (!empty($options[0]) && !preg_match($options[0], $buffer)) {
  50. $this->success = false;
  51. $this->error = sprintf(
  52. __('Validation failed for the input string %s.'), $buffer
  53. );
  54. }
  55. return $buffer;
  56. }
  57. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  58. /**
  59. * Gets the transformation name of the specific plugin
  60. *
  61. * @return string
  62. */
  63. public static function getName()
  64. {
  65. return "Regex Validation";
  66. }
  67. }