1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,65 +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 |
- |
|
12 |
-namespace Symfony\Component\Translation\Loader; |
|
13 |
- |
|
14 |
-use Symfony\Component\Config\Resource\FileResource; |
|
15 |
-use Symfony\Component\Translation\Exception\InvalidResourceException; |
|
16 |
-use Symfony\Component\Translation\Exception\NotFoundResourceException; |
|
17 |
- |
|
18 |
-/** |
|
19 |
- * @author Abdellatif Ait boudad <a.aitboudad@gmail.com> |
|
20 |
- */ |
|
21 |
-abstract class FileLoader extends ArrayLoader |
|
22 |
-{ |
|
23 |
- /** |
|
24 |
- * {@inheritdoc} |
|
25 |
- */ |
|
26 |
- public function load($resource, $locale, $domain = 'messages') |
|
27 |
- { |
|
28 |
- if (!stream_is_local($resource)) { |
|
29 |
- throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); |
|
30 |
- } |
|
31 |
- |
|
32 |
- if (!file_exists($resource)) { |
|
33 |
- throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); |
|
34 |
- } |
|
35 |
- |
|
36 |
- $messages = $this->loadResource($resource); |
|
37 |
- |
|
38 |
- // empty resource |
|
39 |
- if (null === $messages) { |
|
40 |
- $messages = []; |
|
41 |
- } |
|
42 |
- |
|
43 |
- // not an array |
|
44 |
- if (!\is_array($messages)) { |
|
45 |
- throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource)); |
|
46 |
- } |
|
47 |
- |
|
48 |
- $catalogue = parent::load($messages, $locale, $domain); |
|
49 |
- |
|
50 |
- if (class_exists('Symfony\Component\Config\Resource\FileResource')) { |
|
51 |
- $catalogue->addResource(new FileResource($resource)); |
|
52 |
- } |
|
53 |
- |
|
54 |
- return $catalogue; |
|
55 |
- } |
|
56 |
- |
|
57 |
- /** |
|
58 |
- * @param string $resource |
|
59 |
- * |
|
60 |
- * @return array |
|
61 |
- * |
|
62 |
- * @throws InvalidResourceException if stream content has an invalid format |
|
63 |
- */ |
|
64 |
- abstract protected function loadResource($resource); |
|
65 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,65 @@ |
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 |
+ |
|
12 |
+namespace Symfony\Component\Translation\Loader; |
|
13 |
+ |
|
14 |
+use Symfony\Component\Config\Resource\FileResource; |
|
15 |
+use Symfony\Component\Translation\Exception\InvalidResourceException; |
|
16 |
+use Symfony\Component\Translation\Exception\NotFoundResourceException; |
|
17 |
+ |
|
18 |
+/** |
|
19 |
+ * @author Abdellatif Ait boudad <a.aitboudad@gmail.com> |
|
20 |
+ */ |
|
21 |
+abstract class FileLoader extends ArrayLoader |
|
22 |
+{ |
|
23 |
+ /** |
|
24 |
+ * {@inheritdoc} |
|
25 |
+ */ |
|
26 |
+ public function load($resource, $locale, $domain = 'messages') |
|
27 |
+ { |
|
28 |
+ if (!stream_is_local($resource)) { |
|
29 |
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ if (!file_exists($resource)) { |
|
33 |
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); |
|
34 |
+ } |
|
35 |
+ |
|
36 |
+ $messages = $this->loadResource($resource); |
|
37 |
+ |
|
38 |
+ // empty resource |
|
39 |
+ if (null === $messages) { |
|
40 |
+ $messages = []; |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ // not an array |
|
44 |
+ if (!\is_array($messages)) { |
|
45 |
+ throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource)); |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ $catalogue = parent::load($messages, $locale, $domain); |
|
49 |
+ |
|
50 |
+ if (class_exists('Symfony\Component\Config\Resource\FileResource')) { |
|
51 |
+ $catalogue->addResource(new FileResource($resource)); |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ return $catalogue; |
|
55 |
+ } |
|
56 |
+ |
|
57 |
+ /** |
|
58 |
+ * @param string $resource |
|
59 |
+ * |
|
60 |
+ * @return array |
|
61 |
+ * |
|
62 |
+ * @throws InvalidResourceException if stream content has an invalid format |
|
63 |
+ */ |
|
64 |
+ abstract protected function loadResource($resource); |
|
65 |
+} |