You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.2 KiB

3 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Generator;
  11. /**
  12. * ConfigurableRequirementsInterface must be implemented by URL generators that
  13. * can be configured whether an exception should be generated when the parameters
  14. * do not match the requirements. It is also possible to disable the requirements
  15. * check for URL generation completely.
  16. *
  17. * The possible configurations and use-cases:
  18. * - setStrictRequirements(true): Throw an exception for mismatching requirements. This
  19. * is mostly useful in development environment.
  20. * - setStrictRequirements(false): Don't throw an exception but return an empty string as URL for
  21. * mismatching requirements and log the problem. Useful when you cannot control all
  22. * params because they come from third party libs but don't want to have a 404 in
  23. * production environment. It should log the mismatch so one can review it.
  24. * - setStrictRequirements(null): Return the URL with the given parameters without
  25. * checking the requirements at all. When generating a URL you should either trust
  26. * your params or you validated them beforehand because otherwise it would break your
  27. * link anyway. So in production environment you should know that params always pass
  28. * the requirements. Thus this option allows to disable the check on URL generation for
  29. * performance reasons (saving a preg_match for each requirement every time a URL is
  30. * generated).
  31. *
  32. * @author Fabien Potencier <fabien@symfony.com>
  33. * @author Tobias Schultze <http://tobion.de>
  34. */
  35. interface ConfigurableRequirementsInterface
  36. {
  37. /**
  38. * Enables or disables the exception on incorrect parameters.
  39. * Passing null will deactivate the requirements check completely.
  40. */
  41. public function setStrictRequirements(?bool $enabled);
  42. /**
  43. * Returns whether to throw an exception on incorrect parameters.
  44. * Null means the requirements check is deactivated completely.
  45. *
  46. * @return bool|null
  47. */
  48. public function isStrictRequirements();
  49. }