hasJsonErrorOccurred() public static method

Detects whether an error occurred during the last json encode/decode.
public static hasJsonErrorOccurred ( ) : boolean
return boolean
Esempio n. 1
0
 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;
 }
Esempio n. 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;
 }