diff --git a/file/php/Recording.php b/file/php/Recording.php index 046a5d4..6290f76 100644 --- a/file/php/Recording.php +++ b/file/php/Recording.php @@ -1,5 +1,7 @@ file_name = $file; } + /** + * Generates a geoJSON representation + * + * @return geoJSON representation of path + */ public function geoJSON() { $geoJSON = [ @@ -39,7 +46,7 @@ class Recording return array($segment["longitude"], $segment["latitude"]); }, $segments); - return $geoJSON; + return json_encode($geoJSON); } /** @@ -92,7 +99,7 @@ class Recording private function read_segment_1($file) { if (false === is_resource($file)) { - throw new InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file))); + throw new \InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file))); } $data = fread($file, 24); if ($data) { @@ -114,19 +121,16 @@ class Recording private function read_header($file) { if (false === is_resource($file)) { - throw new InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file))); + throw new \InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file))); } $header = unpack(Recording::header_unpack, fread($file, 6)); if ($header["ident"] !== Recording::ident) { throw - new UnexpectedValueException(sprintf("Ident mismatch. Got %s, expected %s", $header["ident"], Recording::ident)); + new \UnexpectedValueException(sprintf("Ident mismatch. Got %s, expected %s", $header["ident"], Recording::ident)); } return $header["version"]; } } - -$r = new Recording("/mnt/f/X-Plane 11/Resources/plugins/GAConnector/flight.rec"); -print_r(json_encode($r->geoJSON())); diff --git a/file/php/testRecording.php b/file/php/testRecording.php new file mode 100644 index 0000000..b2d994f --- /dev/null +++ b/file/php/testRecording.php @@ -0,0 +1,6 @@ +geoJSON());