Transport\Entity\Coordinate::createFromXml PHP Method

createFromXml() public static method

Factory method to create an instance of Coordinate and extract the data from the given xml.
public static createFromXml ( SimpleXMLElement $xml ) : Coordinate
$xml SimpleXMLElement The item xml
return Coordinate The created instance
    public static function createFromXml(\SimpleXMLElement $xml)
    {
        $coordinate = new self();
        $coordinate->type = (string) $xml['type'];
        $x = self::intToFloat((string) $xml['x']);
        $y = self::intToFloat((string) $xml['y']);
        $coordinate = self::setHAFAScoordinates($coordinate, $x, $y);
        return $coordinate;
    }

Usage Example

Example #1
0
 /**
  * Factory method to create an instance and extract the data from the given xml
  *
  * @param   \SimpleXMLElement   $xml    The item xml
  * @param   Location            $obj    An object or null to create it
  * @return  Location            The created instance
  */
 public static function createFromXml(\SimpleXMLElement $xml, Location $obj = null)
 {
     if (!is_object($obj)) {
         throw new \InvalidArgumentException('Argument must be an object');
     }
     if ($xml['name']) {
         $obj->name = (string) $xml['name'];
     }
     if ($xml['score']) {
         $obj->score = (string) $xml['score'];
     }
     $obj->coordinate = Coordinate::createFromXml($xml);
     return $obj;
 }