getLastJsonError() public static méthode

Returns an empty string in case there was no error.
public static getLastJsonError ( ) : string
Résultat string
 private function loadFile($filename)
 {
     $data = file_get_contents($filename);
     $translations = json_decode($data, true);
     if (is_null($translations) && Common::hasJsonErrorOccurred()) {
         throw new \Exception(sprintf('Not able to load translation file %s: %s', $filename, Common::getLastJsonError()));
     }
     if (!is_array($translations)) {
         return array();
     }
     return $translations;
 }
Exemple #2
0
 /**
  * @param  string $pathToTranslationFile
  * @throws \Exception
  * @return mixed
  */
 private function getTranslationsFromFile($pathToTranslationFile)
 {
     $data = file_get_contents($pathToTranslationFile);
     $translations = json_decode($data, true);
     if (is_null($translations) && Common::hasJsonErrorOccurred()) {
         $jsonError = Common::getLastJsonError();
         $message = sprintf('Not able to load translation file %s: %s', $pathToTranslationFile, $jsonError);
         throw new \Exception($message);
     }
     return $translations;
 }