ricardosierra /
translation
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Translation\Loaders; |
||
| 4 | |||
| 5 | class MixedLoader extends Loader |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The default locale. |
||
| 9 | * |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | protected $defaultLocale; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The file loader. |
||
| 16 | * |
||
| 17 | * @var \Translation\Loaders\Loader |
||
| 18 | */ |
||
| 19 | protected $primaryLoader; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The database loader. |
||
| 23 | * |
||
| 24 | * @var \Translation\Loaders\Loader |
||
| 25 | */ |
||
| 26 | protected $secondaryLoader; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Create a new mixed loader instance. |
||
| 30 | * |
||
| 31 | * @param string $defaultLocale |
||
| 32 | * @param Loader $primaryLoader |
||
| 33 | * @param Loader $secondaryLoader |
||
| 34 | */ |
||
| 35 | public function __construct($defaultLocale, Loader $primaryLoader, Loader $secondaryLoader) |
||
| 36 | { |
||
| 37 | parent::__construct($defaultLocale); |
||
| 38 | $this->primaryLoader = $primaryLoader; |
||
| 39 | $this->secondaryLoader = $secondaryLoader; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Load the messages strictly for the given locale. |
||
| 44 | * |
||
| 45 | * @param string $locale |
||
| 46 | * @param string $group |
||
| 47 | * @param string $namespace |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | public function loadSource($locale, $group, $namespace = '*') |
||
| 51 | { |
||
| 52 | return array_replace_recursive( |
||
| 53 | $this->secondaryLoader->loadSource($locale, $group, $namespace), |
||
| 54 | $this->primaryLoader->loadSource($locale, $group, $namespace) |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Add a new namespace to the loader. |
||
| 60 | * |
||
| 61 | * @param string $namespace |
||
| 62 | * @param string $hint |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | public function addNamespace($namespace, $hint) |
||
| 66 | { |
||
| 67 | $this->hints[$namespace] = $hint; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 68 | $this->primaryLoader->addNamespace($namespace, $hint); |
||
| 69 | $this->secondaryLoader->addNamespace($namespace, $hint); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Add a new JSON path to the loader. |
||
| 74 | * |
||
| 75 | * @param string $path |
||
| 76 | * @return void |
||
| 77 | */ |
||
| 78 | public function addJsonPath($path) |
||
| 79 | { |
||
| 80 | // |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Get an array of all the registered namespaces. |
||
| 85 | * |
||
| 86 | * @return array |
||
| 87 | */ |
||
| 88 | public function namespaces() |
||
| 89 | { |
||
| 90 | return $this->hints; |
||
| 91 | } |
||
| 92 | } |
||
| 93 |