vendor/netzmacht/contao-toolkit/src/Component/ToolkitComponentFactory.php line 72

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Netzmacht\Contao\Toolkit\Component;
  4. use Contao\Database\Result;
  5. use Contao\Model;
  6. use Netzmacht\Contao\Toolkit\Component\Exception\ComponentNotFound;
  7. /**
  8.  * @deprecated Since 3.5.0 and get removed in 4.0.0
  9.  *
  10.  * @psalm-suppress DeprecatedInterface
  11.  */
  12. final class ToolkitComponentFactory implements ComponentFactory
  13. {
  14.     // phpcs:disable SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup
  15.     /**
  16.      * List of Component factories.
  17.      *
  18.      * @psalm-suppress DeprecatedClass
  19.      * @psalm-suppress DeprecatedInterface
  20.      *
  21.      * @var ComponentFactory[]
  22.      */
  23.     private $factories;
  24.     // phpcs:enable SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup
  25.     // phpcs:disable SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectOrderOfAnnotationsGroup
  26.     /**
  27.      * @psalm-suppress DeprecatedClass
  28.      *
  29.      * @param array|ComponentFactory[] $factories Component factories.
  30.      */
  31.     public function __construct(array $factories)
  32.     {
  33.         $this->factories $factories;
  34.     }
  35.     // phpcs:enable SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectOrderOfAnnotationsGroup
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function supports($model): bool
  40.     {
  41.         foreach ($this->factories as $factory) {
  42.             if ($factory->supports($model)) {
  43.                 return true;
  44.             }
  45.         }
  46.         return false;
  47.     }
  48.     /**
  49.      * Create a new component.
  50.      *
  51.      * @param Model|Result $model  Component model.
  52.      * @param string       $column Column in which the model is generated.
  53.      *
  54.      * @throws ComponentNotFound When no component factory is registered.
  55.      *
  56.      * @psalm-suppress DeprecatedClass
  57.      */
  58.     public function create($modelstring $column): Component
  59.     {
  60.         foreach ($this->factories as $factory) {
  61.             if ($factory->supports($model)) {
  62.                 return $factory->create($model$column);
  63.             }
  64.         }
  65.         /** @psalm-suppress DeprecatedClass */
  66.         throw ComponentNotFound::forModel($model);
  67.     }
  68. }