vendor/symfony/webpack-encore-bundle/src/Asset/EntrypointLookupCollection.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony WebpackEncoreBundle package.
  4. * (c) Fabien Potencier <fabien@symfony.com>
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. namespace Symfony\WebpackEncoreBundle\Asset;
  9. use Psr\Container\ContainerInterface;
  10. use Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException;
  11. /**
  12. * Aggregate the different entry points configured in the container.
  13. *
  14. * Retrieve the EntrypointLookup instance from the given key.
  15. *
  16. * @final
  17. */
  18. class EntrypointLookupCollection implements EntrypointLookupCollectionInterface
  19. {
  20. private $buildEntrypoints;
  21. private $defaultBuildName;
  22. public function __construct(ContainerInterface $buildEntrypoints, string $defaultBuildName = null)
  23. {
  24. $this->buildEntrypoints = $buildEntrypoints;
  25. $this->defaultBuildName = $defaultBuildName;
  26. }
  27. public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface
  28. {
  29. if (null === $buildName) {
  30. if (null === $this->defaultBuildName) {
  31. throw new UndefinedBuildException('There is no default build configured: please pass an argument to getEntrypointLookup().');
  32. }
  33. $buildName = $this->defaultBuildName;
  34. }
  35. if (!$this->buildEntrypoints->has($buildName)) {
  36. throw new UndefinedBuildException(sprintf('The build "%s" is not configured', $buildName));
  37. }
  38. return $this->buildEntrypoints->get($buildName);
  39. }
  40. }