vendor/league/flysystem-bundle/src/Adapter/Builder/AbstractAdapterDefinitionBuilder.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the flysystem-bundle project.
  4. *
  5. * (c) Titouan Galopin <galopintitouan@gmail.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 League\FlysystemBundle\Adapter\Builder;
  11. use League\FlysystemBundle\Exception\MissingPackageException;
  12. use Symfony\Component\DependencyInjection\Definition;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. /**
  15. * @author Titouan Galopin <galopintitouan@gmail.com>
  16. *
  17. * @internal
  18. */
  19. abstract class AbstractAdapterDefinitionBuilder implements AdapterDefinitionBuilderInterface
  20. {
  21. final public function createDefinition(array $options): Definition
  22. {
  23. $this->ensureRequiredPackagesAvailable();
  24. $resolver = new OptionsResolver();
  25. $this->configureOptions($resolver);
  26. $definition = new Definition();
  27. $definition->setPublic(false);
  28. $this->configureDefinition($definition, $resolver->resolve($options));
  29. return $definition;
  30. }
  31. abstract protected function getRequiredPackages(): array;
  32. abstract protected function configureOptions(OptionsResolver $resolver);
  33. abstract protected function configureDefinition(Definition $definition, array $options);
  34. private function ensureRequiredPackagesAvailable()
  35. {
  36. $missingPackages = [];
  37. foreach ($this->getRequiredPackages() as $requiredClass => $packageName) {
  38. if (!class_exists($requiredClass)) {
  39. $missingPackages[] = $packageName;
  40. }
  41. }
  42. if (!$missingPackages) {
  43. return;
  44. }
  45. throw new MissingPackageException(sprintf("Missing package%s, to use the \"%s\" adapter, run:\n\ncomposer require %s", \count($missingPackages) > 1 ? 's' : '', $this->getName(), implode(' ', $missingPackages)));
  46. }
  47. }