Beispiel #1
0
 /**
  * Writes a json file
  *
  * @param $path
  *
  * @param $contents
  *
  * @return mixed|null
  */
 public static function WriteFile($path, $contents)
 {
     /**
      * Gets the correct path of this file
      */
     $corrected_path = Path::Get($path);
     /**
      * If this file exists, return null ( use above function )
      */
     if (file_exists($path)) {
         return null;
     }
     /**
      * Else, Lets first create directories
      */
     JsonWriter::CreateDirectories($path);
     /**
      * Then, lets write to file
      */
     JsonWriter::PutContents($corrected_path, $contents);
     /**
      * Then lets return this written file
      */
     return JsonReader::ReadFile($corrected_path);
 }
Beispiel #2
0
 /**
  * Writes JSON to a file
  *
  * @param $file
  *
  * @param $contents
  *
  * @return null
  */
 public static function Write($file, $contents)
 {
     /**
      * Does this file exist?
      */
     if (JsonWriter::FileExists($file)) {
         /**
          * Don't overwrite
          */
         return null;
     }
     /**
      * Does this directory exist?
      */
     if (!JsonWriter::DirectoryExists(JsonWriter::GetDirectories($file))) {
         JsonWriter::MakeDirectory(JsonWriter::GetDirectories($file));
     }
     /**
      * Writes this data to file.
      */
     JsonWriter::WriteData($file, json_encode($contents, JSON_PRETTY_PRINT));
     /**
      * Returns the file on a successful completion
      */
     return JsonReader::ReadFile($file);
 }
 /**
  * Reads the saved path.
  *
  * @param $correct_path
  *
  * @return mixed|null
  */
 private static function ReadSavedPath($correct_path)
 {
     if (FileMethods::FileExists($correct_path . "Json/resource/filepath.json")) {
         return JsonReader::ReadFile($correct_path . "Json/resource/filepath.json");
     }
     return null;
 }
 /**
  * Reads the default parser needles
  *
  * @return mixed|null
  */
 public static function ReadDefaults()
 {
     return JsonReader::ReadFile(PathFinder::RealPath("Json/misc/default_parser_needles.json"));
 }