]> git.immae.eu Git - github/wallabag/wallabag.git/blame - vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / ResourceBundle / Reader / BufferedBundleReader.php
CommitLineData
4f5b44bd
NL
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\ResourceBundle\Reader;
13
14use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer;
15
16/**
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19class BufferedBundleReader implements BundleReaderInterface
20{
21 /**
22 * @var BundleReaderInterface
23 */
24 private $reader;
25
26 private $buffer;
27
28 /**
29 * Buffers a given reader.
30 *
31 * @param BundleReaderInterface $reader The reader to buffer.
32 * @param integer $bufferSize The number of entries to store
33 * in the buffer.
34 */
35 public function __construct(BundleReaderInterface $reader, $bufferSize)
36 {
37 $this->reader = $reader;
38 $this->buffer = new RingBuffer($bufferSize);
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function read($path, $locale)
45 {
46 $hash = $path . '//' . $locale;
47
48 if (!isset($this->buffer[$hash])) {
49 $this->buffer[$hash] = $this->reader->read($path, $locale);
50 }
51
52 return $this->buffer[$hash];
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function getLocales($path)
59 {
60 return $this->reader->getLocales($path);
61 }
62}