ExpressionCacheWarmer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Bundle\SecurityBundle\CacheWarmer;
  11. use Symfony\Component\ExpressionLanguage\Expression;
  12. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  13. use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
  14. class ExpressionCacheWarmer implements CacheWarmerInterface
  15. {
  16. private $expressions;
  17. private $expressionLanguage;
  18. /**
  19. * @param iterable|Expression[] $expressions
  20. */
  21. public function __construct(iterable $expressions, ExpressionLanguage $expressionLanguage)
  22. {
  23. $this->expressions = $expressions;
  24. $this->expressionLanguage = $expressionLanguage;
  25. }
  26. public function isOptional()
  27. {
  28. return true;
  29. }
  30. /**
  31. * @return string[]
  32. */
  33. public function warmUp(string $cacheDir)
  34. {
  35. foreach ($this->expressions as $expression) {
  36. $this->expressionLanguage->parse($expression, ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']);
  37. }
  38. return [];
  39. }
  40. }