/** * 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); }
/** * Returns a streamed response depending on the format required : calls a different writer for each format * * @param \Doctrine\ORM\EntityManager $em * @param string $format * @param string $filename * @param string $entityClass * @param array $listFields * * @throws \RuntimeException * * @return \Symfony\Component\HttpFoundation\StreamedResponse */ public static function getResponse($em, $format = 'csv', $filename = null, $entityClass, $listFields) { if ($filename === null) { $filename = 'export'; } switch ($format) { case 'csv': $writer = new CsvWriter($em, $entityClass, $listFields); $contentType = 'text/csv'; break; case 'json': $writer = new JsonWriter($em, $entityClass, $listFields); $contentType = 'application/json'; break; default: throw new \RuntimeException('File format unknown'); } $response = $writer->export(); $response->headers->set('Content-Type', $contentType); $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '.' . $format . '"'); return $response; }
/** * Make that directory * * @param $file */ public static function MakeDirectory($file) { if (!JsonWriter::DirectoryExists($file)) { mkdir($file); } }
/** * Saves our found path to file * * @param $built_path */ private static function SavePath($built_path) { $array = ['path' => $built_path]; JsonWriter::Write($array['path'] . "Json/resource/filepath.json", $array); }
/** * Writes our tor access points */ public static function WriteTorExitPoints() { $content = Address::GetTorExitPoints(); if ($content != null) { JsonWriter::PathWrite('Json/resources/tor_exit_points.json', $content); } }
/** * @test * @covers Plum\PlumJson\JsonWriter::prepare() */ public function prepareDoesNothing() { $writer = new JsonWriter(); $writer->prepare(); }