ParamConverterInterface.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\ParamConverter;
  3. use Symfony\Component\Routing\Route;
  4. /**
  5. * Interface for parameter converters.
  6. *
  7. * Classes implementing this interface are responsible for converting a path
  8. * parameter to the object it represents.
  9. *
  10. * Here is an example path: /admin/structure/block/manage/{block}
  11. *
  12. * In this case, '{block}' would be the path parameter which should be turned
  13. * into a block object representing the block in question.
  14. *
  15. * ParamConverters are defined as services tagged with 'paramconverter', and are
  16. * managed by the 'paramconverter_manager' service.
  17. *
  18. * @see menu
  19. * @see \Drupal\Core\ParamConverter\ParamConverterManagerInterface
  20. * @see \Drupal\Core\ParamConverter\EntityConverter
  21. */
  22. interface ParamConverterInterface {
  23. /**
  24. * Converts path variables to their corresponding objects.
  25. *
  26. * @param mixed $value
  27. * The raw value.
  28. * @param mixed $definition
  29. * The parameter definition provided in the route options.
  30. * @param string $name
  31. * The name of the parameter.
  32. * @param array $defaults
  33. * The route defaults array.
  34. *
  35. * @return mixed|null
  36. * The converted parameter value.
  37. */
  38. public function convert($value, $definition, $name, array $defaults);
  39. /**
  40. * Determines if the converter applies to a specific route and variable.
  41. *
  42. * @param mixed $definition
  43. * The parameter definition provided in the route options.
  44. * @param string $name
  45. * The name of the parameter.
  46. * @param \Symfony\Component\Routing\Route $route
  47. * The route to consider attaching to.
  48. *
  49. * @return bool
  50. * TRUE if the converter applies to the passed route and parameter, FALSE
  51. * otherwise.
  52. */
  53. public function applies($definition, $name, Route $route);
  54. }