vendor/symfony/intl/Data/Bundle/Reader/BufferedBundleReader.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Intl\Data\Bundle\Reader;
  11. use Symfony\Component\Intl\Data\Util\RingBuffer;
  12. /**
  13.  * @author Bernhard Schussek <bschussek@gmail.com>
  14.  *
  15.  * @internal
  16.  */
  17. class BufferedBundleReader implements BundleReaderInterface
  18. {
  19.     private $reader;
  20.     /** @var RingBuffer<string, mixed> */
  21.     private $buffer;
  22.     /**
  23.      * Buffers a given reader.
  24.      *
  25.      * @param int $bufferSize The number of entries to store in the buffer
  26.      */
  27.     public function __construct(BundleReaderInterface $readerint $bufferSize)
  28.     {
  29.         $this->reader $reader;
  30.         $this->buffer = new RingBuffer($bufferSize);
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function read(string $pathstring $locale)
  36.     {
  37.         $hash $path.'//'.$locale;
  38.         if (!isset($this->buffer[$hash])) {
  39.             $this->buffer[$hash] = $this->reader->read($path$locale);
  40.         }
  41.         return $this->buffer[$hash];
  42.     }
  43. }