/** * Use this to pass a bunch of data at once to the object * * @param $data , can be an array or a file of the types yaml, json or ini, PHP will be executed! * @param bool $override , by default all existing data are replaced */ public static function init($data, $override = true) { $settingsObj = self::getInstance(); if (is_string($data)) { ob_start(); include $data; switch (FsUtils::getFileExtension($data)) { case 'yaml': case 'yml': $data = Yaml::parse(ob_get_clean()); break; case 'json': $data = json_decode(ob_get_clean(), 1); break; case 'ini': $data = parse_ini_string(ob_get_clean()); break; } } if ($override) { $settingsObj->data = $data; } else { $settingsObj->data = ArrayUtils::arrayMergeRecursiveDistinct($settingsObj->data, $data); } }
/** * Use native format if possible, generic json otherwise * * @param string $cacheFilePath * @return string class name */ public static function getClass($cacheFilePath) { $extension = strtolower(FsUtils::getFileExtension($cacheFilePath)); if ($extension === 'htm') { $extension = 'html'; } else { if ($extension === 'yml') { $extension = 'yaml'; } } $nativeFormatClassName = __NAMESPACE__ . '\\FileFormats\\' . ucfirst($extension) . 'Cache'; return class_exists($nativeFormatClassName) ? $nativeFormatClassName : __NAMESPACE__ . '\\FileFormats\\GenericCache'; }
/** * Short description of method getTranslationsInFile * * @access private * @author firstname and lastname of author, <*****@*****.**> * @param string $filePath */ private function getTranslationsInFile($filePath) { // File extension ? $extOk = in_array(\Jig\Utils\FsUtils::getFileExtension($filePath), $this->getFileTypes()); if ($extOk) { foreach ($this->getBannedFileType() as $bannedExt) { $extOk &= substr_compare($filePath, $bannedExt, strlen($filePath) - strlen($bannedExt), strlen($bannedExt)) !== 0; } } if ($extOk) { // We read the file. $lines = file($filePath); foreach ($lines as $line) { $strings = $this->getTranslationPhrases($line); //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string); //lookup for __('to translate') or __ 'to translate' // preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string); foreach ($strings as $s) { $tu = new tao_helpers_translation_TranslationUnit(); $tu->setSource(tao_helpers_translation_POUtils::sanitize($s)); $tus = $this->getTranslationUnits(); $found = false; // We must add the string as a new TranslationUnit only // if a similiar source does not exist. foreach ($tus as $t) { if ($tu->getSource() == $t->getSource()) { $found = true; break; } } if (!$found) { $tus[] = $tu; $this->setTranslationUnits($tus); } } } } }