Beispiel #1
0
 public static function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Stop $obj = null)
 {
     if (!$obj) {
         $obj = new Stop();
     }
     $dateTime = null;
     $isArrival = false;
     $obj->station = Entity\Location\Station::createFromXml($xml->Station);
     // deprecated, use location instead
     foreach ($xml->children() as $location) {
         $location = Entity\LocationFactory::createFromXml($location);
         if ($location) {
             $obj->location = $location;
             break;
         }
     }
     if ($xml->Arr) {
         $isArrival = true;
         $dateTime = self::calculateDateTime((string) $xml->Arr->Time, $date);
         $obj->arrival = $dateTime->format(\DateTime::ISO8601);
         $obj->arrivalTimestamp = $dateTime->getTimestamp();
         $obj->platform = trim((string) $xml->Arr->Platform->Text);
     }
     if ($xml->Dep) {
         $dateTime = self::calculateDateTime((string) $xml->Dep->Time, $date);
         $obj->departure = $dateTime->format(\DateTime::ISO8601);
         $obj->departureTimestamp = $dateTime->getTimestamp();
         $obj->platform = trim((string) $xml->Dep->Platform->Text);
     }
     $obj->prognosis = Prognosis::createFromXml($xml->StopPrognosis, $dateTime, $isArrival);
     if ($obj->prognosis) {
         if ($obj->prognosis->arrival && $obj->arrival) {
             $obj->delay = (strtotime($obj->prognosis->arrival) - strtotime($obj->arrival)) / 60;
         }
         if ($obj->prognosis->departure && $obj->departure) {
             $obj->delay = (strtotime($obj->prognosis->departure) - strtotime($obj->departure)) / 60;
         }
     }
     return $obj;
 }
Beispiel #2
0
 public function testCreateFromXmlStation()
 {
     $xml = new \SimpleXMLElement('<Station name="Bern Felsenau" score="81" externalId="008508051#95" externalStationNr="008508051" type="WGS84" x="7444245" y="46968493"/>');
     $this->assertEquals($this->getStation(), Station::createFromXml($xml));
 }