public function loadTranslations($locale) { if (in_array($locale, $this->loadedLocales)) { return true; } $this->cacheFiles(); if (!isset($this->files[$locale])) { return false; } $tr = []; foreach ($this->files[$locale] as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); $fileTr = []; if ($ext == 'php') { $fileTr = (require $file); if (!is_array($fileTr)) { throw new Exception\RuntimeException(sprintf("Translation file '%s' must return array", $file)); } } elseif ($ext == 'yml') { $fileTr = Yaml::readFile($file) ?: []; } # Ignore other extensions. if ($fileTr) { $tr = array_merge_recursive($tr, $fileTr); } } $this->loadedLocales[] = $locale; return $tr; }
/** * @param string $file * @param string $md5File */ protected function updateManifestIndex($file, $md5File) { $index = $this->getManifestIndex(); $index[$file] = $md5File; Rails\Yaml\Parser::writeFile($this->manifestIndexFile(), $index); }
/** * Loads locale file. * If not a full path (i.e. doesn't start with / or x:), it'd be * taken as relative path to locales path (i.e. config/locales). In this * case, the extension of the file must be omitted. * * $i18n->loadLocale("/home/www/foo/bar/es.yml"); * $i18n->loadLocale("es"); <- loads config/locales/es.php|yml * $i18n->loadLocale("subdir/es"); <- loads config/locales/subdir/es.php|yml * $i18n->loadLocale("/some/path/locales/%locale%.yml"); %locale% will be replaced with current locale */ public function loadLocale($locale = null) { !$locale && ($locale = $this->_locale); if (in_array($locale, $this->loaded_locales)) { return; } if (is_int($pos = strpos($locale, '%locale%'))) { $locale = substr_replace($locale, $this->locale(), $pos, 8); } if (substr($locale, 0, 1) == '/' || substr($locale, 1, 1) == ':') { $file = $locale; } else { $patt = $this->config()->path . '/' . $locale . '.{php,yml}'; $files = glob($patt, GLOB_BRACE); if ($files) { $file = $files[0]; } else { return false; } } $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext == 'yml') { $locale_data = Rails\Yaml\Parser::readFile($file); } else { $locale_data = (require $file); } $this->_tr = array_merge_recursive($this->_tr, $locale_data); $this->loaded_locales[] = $locale; return true; }
/** * Get database connections * Gets the configuration from the database file. * * @return array|bool */ protected function getDatabaseConnections() { $configFile = $this->findDatabaseFile(); if (!$configFile) { return false; } switch (substr($configFile, -3)) { case 'php': $connections = (require $configFile); break; case 'yml': $connections = Yaml::readFile($configFile); break; } return $connections; }
private function _load_active_record() { $basename = Rails::root() . '/config/database'; $database_file = $basename . '.yml'; $connections = []; /** * It's possible to not to have a database file if no database will be used. */ if (is_file($database_file)) { $connections = Rails\Yaml\Parser::readFile($database_file); } else { $database_file = Rails::root() . '/config/database.php'; if (is_file($database_file)) { $connections = (require $database_file); } } if ($connections) { foreach ($connections as $name => $config) { ActiveRecord::addConnection($config, $name); } # Set environment connection. ActiveRecord::set_environment_connection(Rails::env()); } }