Component.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Defines a component that is later extended to parse specialized components or
  4. * keywords.
  5. *
  6. * There is a small difference between *Component and *Keyword classes: usually,
  7. * *Component parsers can be reused in multiple situations and *Keyword parsers
  8. * count on the *Component classes to do their job.
  9. */
  10. declare(strict_types=1);
  11. namespace PhpMyAdmin\SqlParser;
  12. use Exception;
  13. /**
  14. * A component (of a statement) is a part of a statement that is common to
  15. * multiple query types.
  16. */
  17. abstract class Component
  18. {
  19. /**
  20. * Parses the tokens contained in the given list in the context of the given
  21. * parser.
  22. *
  23. * @param Parser $parser the parser that serves as context
  24. * @param TokensList $list the list of tokens that are being parsed
  25. * @param array $options parameters for parsing
  26. *
  27. * @return mixed
  28. *
  29. * @throws Exception not implemented yet.
  30. */
  31. public static function parse(
  32. Parser $parser,
  33. TokensList $list,
  34. array $options = []
  35. ) {
  36. // This method should be abstract, but it can't be both static and
  37. // abstract.
  38. throw new Exception(Translator::gettext('Not implemented yet.'));
  39. }
  40. /**
  41. * Builds the string representation of a component of this type.
  42. *
  43. * In other words, this function represents the inverse function of
  44. * `static::parse`.
  45. *
  46. * @param mixed $component the component to be built
  47. * @param array $options parameters for building
  48. *
  49. * @return mixed
  50. *
  51. * @throws Exception not implemented yet.
  52. */
  53. public static function build($component, array $options = [])
  54. {
  55. // This method should be abstract, but it can't be both static and
  56. // abstract.
  57. throw new Exception(Translator::gettext('Not implemented yet.'));
  58. }
  59. /**
  60. * Builds the string representation of a component of this type.
  61. *
  62. * @see static::build
  63. *
  64. * @return string
  65. */
  66. public function __toString()
  67. {
  68. return static::build($this);
  69. }
  70. }