vendor/sylius/resource-bundle/src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ResourceBundle\ExpressionLanguage;
  12. use Symfony\Component\ExpressionLanguage\ExpressionFunction;
  13. use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. final class NotNullExpressionFunctionProvider implements ExpressionFunctionProviderInterface
  16. {
  17. public function getFunctions(): array
  18. {
  19. return [
  20. new ExpressionFunction(
  21. 'notFoundOnNull',
  22. /**
  23. * @param mixed $result
  24. */
  25. function ($result): string {
  26. return sprintf('(null !== %1$s) ? %1$s : throw new NotFoundHttpException(\'Requested page is invalid.\')', $result);
  27. },
  28. /**
  29. * @param mixed $arguments
  30. * @param mixed $result
  31. *
  32. * @return mixed
  33. */
  34. function ($arguments, $result) {
  35. if (null === $result) {
  36. throw new NotFoundHttpException('Requested page is invalid.');
  37. }
  38. return $result;
  39. },
  40. ),
  41. ];
  42. }
  43. }