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

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.     private $buffer;
  21.     /**
  22.      * Buffers a given reader.
  23.      *
  24.      * @param int $bufferSize The number of entries to store in the buffer
  25.      */
  26.     public function __construct(BundleReaderInterface $readerint $bufferSize)
  27.     {
  28.         $this->reader $reader;
  29.         $this->buffer = new RingBuffer($bufferSize);
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function read(string $pathstring $locale)
  35.     {
  36.         $hash $path.'//'.$locale;
  37.         if (!isset($this->buffer[$hash])) {
  38.             $this->buffer[$hash] = $this->reader->read($path$locale);
  39.         }
  40.         return $this->buffer[$hash];
  41.     }
  42. }