vendor/friendsofsymfony/elastica-bundle/src/Persister/PersisterRegistry.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSElasticaBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\ElasticaBundle\Persister;
  11. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  12. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  13. class PersisterRegistry implements ContainerAwareInterface
  14. {
  15.     use ContainerAwareTrait;
  16.     /** 
  17.      * @var array 
  18.      */
  19.     private $persisters = [];
  20.     /**
  21.      * @param array $persisters
  22.      */
  23.     public function __construct(array $persisters)
  24.     {
  25.         $this->persisters $persisters;
  26.     }
  27.     /**
  28.      * Gets the persister for an index and type.
  29.      *
  30.      * @param string $index
  31.      * @param string $type
  32.      *
  33.      * @return ObjectPersisterInterface
  34.      *
  35.      * @throws \InvalidArgumentException if no persister was registered for the index and type
  36.      */
  37.     public function getPersister($index$type)
  38.     {
  39.         if (!isset($this->persisters[$index][$type])) {
  40.             throw new \InvalidArgumentException(sprintf('No persister was registered for index "%s" and type "%s".'$index$type));
  41.         }
  42.         return $this->container->get($this->persisters[$index][$type]);
  43.     }
  44. }