public function testExtend() { $this->dictionary->extend('de'); $result = $this->dictionary->get('example'); $this->assertEquals('Was ist los?', $result['no_english_version']); }
/** * Load files and variables * * @param string $name * @param string $path * @param string $type * @param array|Dictionary[] $items * @param string $language * @param string $storage * @param array $extend * * @return array */ private static function load($name, $path, $type, array $items, $language, $storage, array $extend = null) { $newItems = []; $dirPath = self::getDirPath($storage, $path, $language); if (null !== $extend) { foreach ($extend as $extendLanguage) { $newItems = array_merge($newItems, self::load($name, $path, $type, [], $extendLanguage, $storage)); } } if (is_dir($dirPath)) { // Scan dir foreach (scandir($dirPath) as $file) { if ($file !== '.' && $file !== '..') { $item = null; if (substr($file, -4) === '.php') { $file = substr($file, 0, -4); $item = new Dictionary($language, $storage, $file, $path, false, Php::TYPE); $item->extend($extend); } elseif (substr($file, -5) === '.json') { $file = substr($file, 0, -5); $item = new Dictionary($language, $storage, $file, $path, false, Json::TYPE); $item->extend($extend); } elseif (substr($file, -5) === '.html') { $file = substr($file, 0, -5); $item = new Dictionary($language, $storage, $file, $path, false, Html::TYPE); $item->extend($extend); } elseif (is_dir($dirPath . DIRECTORY_SEPARATOR . $file)) { $item = new Dictionary($language, $storage, $file, $path, false); $item->extend($extend); } if (null !== $item) { if (isset($items[$file])) { $newItems[$file] = $items[$file]->merge($item); } else { $newItems[$file] = $item; } } } } } if (!empty($name)) { // Import file if ($type === Php::TYPE) { $variables = (require $dirPath . "." . Php::TYPE); if (is_array($variables)) { $newItems = array_merge($newItems, $variables); } } elseif ($type === Json::TYPE) { $content = file_get_contents($dirPath . "." . Json::TYPE); $variables = json_decode($content, true); if (is_array($variables)) { $newItems = array_merge($newItems, $variables); } } } return $newItems; }