vendor/api-platform/core/src/Core/DataPersister/ChainDataPersister.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@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. declare(strict_types=1);
  11. namespace ApiPlatform\Core\DataPersister;
  12. /**
  13.  * Chained data persisters.
  14.  *
  15.  * @author Baptiste Meyer <baptiste.meyer@gmail.com>
  16.  */
  17. final class ChainDataPersister implements ContextAwareDataPersisterInterface
  18. {
  19.     /**
  20.      * @var iterable<DataPersisterInterface>
  21.      *
  22.      * @internal
  23.      */
  24.     public $persisters;
  25.     /**
  26.      * @param DataPersisterInterface[] $persisters
  27.      */
  28.     public function __construct(iterable $persisters)
  29.     {
  30.         $this->persisters $persisters;
  31.     }
  32.     public function supports($data, array $context = []): bool
  33.     {
  34.         foreach ($this->persisters as $persister) {
  35.             if ($persister->supports($data$context)) {
  36.                 return true;
  37.             }
  38.         }
  39.         return false;
  40.     }
  41.     public function persist($data, array $context = [])
  42.     {
  43.         foreach ($this->persisters as $persister) {
  44.             if ($persister->supports($data$context)) {
  45.                 $data $persister->persist($data$context);
  46.                 if ($persister instanceof ResumableDataPersisterInterface && $persister->resumable($context)) {
  47.                     continue;
  48.                 }
  49.                 return $data;
  50.             }
  51.         }
  52.         return $data;
  53.     }
  54.     public function remove($data, array $context = [])
  55.     {
  56.         foreach ($this->persisters as $persister) {
  57.             if ($persister->supports($data$context)) {
  58.                 $persister->remove($data$context);
  59.                 if ($persister instanceof ResumableDataPersisterInterface && $persister->resumable($context)) {
  60.                     continue;
  61.                 }
  62.                 return;
  63.             }
  64.         }
  65.     }
  66. }