PHP Namespacing und Test

This commit is contained in:
Kilian Hofmann 2022-09-07 20:32:14 +02:00
parent 25c4d8474d
commit 2bda541bce
2 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,7 @@
<?php
namespace germanairlinesva_recording;
class Recording
{
private const ident = "VGAR";
@ -15,6 +17,11 @@ class Recording
$this->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()));

View File

@ -0,0 +1,6 @@
<?php
require "Recording.php";
$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 11/Resources/plugins/GAConnector/flight.rec");
print_r($r->geoJSON());