aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader')
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php42
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php51
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php62
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php40
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php61
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php113
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php50
7 files changed, 0 insertions, 419 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php
deleted file mode 100644
index c30693ac..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php
+++ /dev/null
@@ -1,42 +0,0 @@
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
14/**
15 * Base class for {@link BundleReaderInterface} implementations.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19abstract class AbstractBundleReader implements BundleReaderInterface
20{
21 /**
22 * {@inheritdoc}
23 */
24 public function getLocales($path)
25 {
26 $extension = '.' . $this->getFileExtension();
27 $locales = glob($path . '/*' . $extension);
28
29 // Remove file extension and sort
30 array_walk($locales, function (&$locale) use ($extension) { $locale = basename($locale, $extension); });
31 sort($locales);
32
33 return $locales;
34 }
35
36 /**
37 * Returns the extension of locale files in this bundle.
38 *
39 * @return string The file extension (without leading dot).
40 */
41 abstract protected function getFileExtension();
42}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php
deleted file mode 100644
index 56cef806..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php
+++ /dev/null
@@ -1,51 +0,0 @@
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\Exception\RuntimeException;
15use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle;
16
17/**
18 * Reads binary .res resource bundles.
19 *
20 * @author Bernhard Schussek <bschussek@gmail.com>
21 */
22class BinaryBundleReader extends AbstractBundleReader implements BundleReaderInterface
23{
24 /**
25 * {@inheritdoc}
26 */
27 public function read($path, $locale)
28 {
29 // Point for future extension: Modify this class so that it works also
30 // if the \ResourceBundle class is not available.
31 $bundle = new \ResourceBundle($locale, $path);
32
33 if (null === $bundle) {
34 throw new RuntimeException(sprintf(
35 'Could not load the resource bundle "%s/%s.res".',
36 $path,
37 $locale
38 ));
39 }
40
41 return new ArrayAccessibleResourceBundle($bundle);
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 protected function getFileExtension()
48 {
49 return 'res';
50 }
51}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php
deleted file mode 100644
index e44074b1..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php
+++ /dev/null
@@ -1,62 +0,0 @@
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}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php
deleted file mode 100644
index bc485cd5..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php
+++ /dev/null
@@ -1,40 +0,0 @@
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
14/**
15 * Reads resource bundle files.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19interface BundleReaderInterface
20{
21 /**
22 * Reads a resource bundle.
23 *
24 * @param string $path The path to the resource bundle.
25 * @param string $locale The locale to read.
26 *
27 * @return mixed Returns an array or {@link \ArrayAccess} instance for
28 * complex data, a scalar value otherwise.
29 */
30 public function read($path, $locale);
31
32 /**
33 * Reads the available locales of a resource bundle.
34 *
35 * @param string $path The path to the resource bundle.
36 *
37 * @return string[] A list of supported locale codes.
38 */
39 public function getLocales($path);
40}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php
deleted file mode 100644
index 663bcc9d..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php
+++ /dev/null
@@ -1,61 +0,0 @@
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\Exception\InvalidArgumentException;
15use Symfony\Component\Intl\Exception\RuntimeException;
16
17/**
18 * Reads .php resource bundles.
19 *
20 * @author Bernhard Schussek <bschussek@gmail.com>
21 */
22class PhpBundleReader extends AbstractBundleReader implements BundleReaderInterface
23{
24 /**
25 * {@inheritdoc}
26 */
27 public function read($path, $locale)
28 {
29 if ('en' !== $locale) {
30 throw new InvalidArgumentException('Only the locale "en" is supported.');
31 }
32
33 $fileName = $path . '/' . $locale . '.php';
34
35 if (!file_exists($fileName)) {
36 throw new RuntimeException(sprintf(
37 'The resource bundle "%s/%s.php" does not exist.',
38 $path,
39 $locale
40 ));
41 }
42
43 if (!is_file($fileName)) {
44 throw new RuntimeException(sprintf(
45 'The resource bundle "%s/%s.php" is not a file.',
46 $path,
47 $locale
48 ));
49 }
50
51 return include $fileName;
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 protected function getFileExtension()
58 {
59 return 'php';
60 }
61}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php
deleted file mode 100644
index e3656fe2..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php
+++ /dev/null
@@ -1,113 +0,0 @@
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\RecursiveArrayAccess;
15
16/**
17 * A structured reader wrapping an existing resource bundle reader.
18 *
19 * @author Bernhard Schussek <bschussek@gmail.com>
20 *
21 * @see StructuredResourceBundleBundleReaderInterface
22 */
23class StructuredBundleReader implements StructuredBundleReaderInterface
24{
25 /**
26 * @var BundleReaderInterface
27 */
28 private $reader;
29
30 /**
31 * Creates an entry reader based on the given resource bundle reader.
32 *
33 * @param BundleReaderInterface $reader A resource bundle reader to use.
34 */
35 public function __construct(BundleReaderInterface $reader)
36 {
37 $this->reader = $reader;
38 }
39
40 /**
41 * {@inheritdoc}
42 */
43 public function read($path, $locale)
44 {
45 return $this->reader->read($path, $locale);
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 public function getLocales($path)
52 {
53 return $this->reader->getLocales($path);
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function readEntry($path, $locale, array $indices, $fallback = true)
60 {
61 $data = $this->reader->read($path, $locale);
62
63 $entry = RecursiveArrayAccess::get($data, $indices);
64 $multivalued = is_array($entry) || $entry instanceof \Traversable;
65
66 if (!($fallback && (null === $entry || $multivalued))) {
67 return $entry;
68 }
69
70 if (null !== ($fallbackLocale = $this->getFallbackLocale($locale))) {
71 $parentEntry = $this->readEntry($path, $fallbackLocale, $indices, true);
72
73 if ($entry || $parentEntry) {
74 $multivalued = $multivalued || is_array($parentEntry) || $parentEntry instanceof \Traversable;
75
76 if ($multivalued) {
77 if ($entry instanceof \Traversable) {
78 $entry = iterator_to_array($entry);
79 }
80
81 if ($parentEntry instanceof \Traversable) {
82 $parentEntry = iterator_to_array($parentEntry);
83 }
84
85 $entry = array_merge(
86 $parentEntry ?: array(),
87 $entry ?: array()
88 );
89 } else {
90 $entry = null === $entry ? $parentEntry : $entry;
91 }
92 }
93 }
94
95 return $entry;
96 }
97
98 /**
99 * Returns the fallback locale for a given locale, if any
100 *
101 * @param string $locale The locale to find the fallback for.
102 *
103 * @return string|null The fallback locale, or null if no parent exists
104 */
105 private function getFallbackLocale($locale)
106 {
107 if (false === $pos = strrpos($locale, '_')) {
108 return null;
109 }
110
111 return substr($locale, 0, $pos);
112 }
113}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php
deleted file mode 100644
index c22ad93b..00000000
--- a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php
+++ /dev/null
@@ -1,50 +0,0 @@
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
14/**
15 * Reads individual entries of a resource file.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19interface StructuredBundleReaderInterface extends BundleReaderInterface
20{
21 /**
22 * Reads an entry from a resource bundle.
23 *
24 * An entry can be selected from the resource bundle by passing the path
25 * to that entry in the bundle. For example, if the bundle is structured
26 * like this:
27 *
28 * TopLevel
29 * NestedLevel
30 * Entry: Value
31 *
32 * Then the value can be read by calling:
33 *
34 * $reader->readEntry('...', 'en', array('TopLevel', 'NestedLevel', 'Entry'));
35 *
36 * @param string $path The path to the resource bundle.
37 * @param string $locale The locale to read.
38 * @param string[] $indices The indices to read from the bundle.
39 * @param Boolean $fallback Whether to merge the value with the value from
40 * the fallback locale (e.g. "en" for "en_GB").
41 * Only applicable if the result is multivalued
42 * (i.e. array or \ArrayAccess) or cannot be found
43 * in the requested locale.
44 *
45 * @return mixed Returns an array or {@link \ArrayAccess} instance for
46 * complex data, a scalar value for simple data and NULL
47 * if the given path could not be accessed.
48 */
49 public function readEntry($path, $locale, array $indices, $fallback = true);
50}