Skip to content

Commit

Permalink
Add objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed Jan 5, 2022
1 parent 1cdb532 commit 99f40e2
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Objects/Channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Ben221199\Oxxa\API\Objects;

use SimpleXMLElement;

class Channel{

/**@var Order $order*/
private $order;

public function getOrder(){
return $this->order;
}

public static function fromXML(string $xml){
$simpleXML = new SimpleXMLElement($xml);

$channel = new static;
$channel->order = Order::fromXML($simpleXML->xpath('order')[0]->asXML());
return $channel;
}

}
27 changes: 27 additions & 0 deletions src/Objects/Details.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Ben221199\Oxxa\API\Objects;

use SimpleXMLElement;

class Details{

/**@var SimpleXMLElement $_simpleXML*/
private $_simpleXML;

public function getValue(){
return (string) $this->_simpleXML;
}

public function getElementsByName($name){
return $this->_simpleXML->xpath($name);
}

public static function fromXML(string $xml){
$simpleXML = new SimpleXMLElement($xml);

$details = new static;
$details->_simpleXML = $simpleXML;
return $details;
}

}
47 changes: 47 additions & 0 deletions src/Objects/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace Ben221199\Oxxa\API\Objects;

use SimpleXMLElement;

class Order{

/**@var int $order_id*/
private $order_id;

/**@var string $command*/
private $command;

/**@var string $status_code*/
private $status_code;

/**@var string $status_description*/
private $status_description;

/**@var float $price*/
private $price;

/**@var Details $details*/
private $details;

/**@var bool $order_complete*/
private $order_complete;

/**@var bool $done*/
private $done;

public static function fromXML(string $xml){
$simpleXML = new SimpleXMLElement($xml);

$order = new static;
$order->order_id = intval((string) $simpleXML->xpath('order_id')[0]);
$order->command = (string) $simpleXML->xpath('command')[0];
$order->status_code = (string) $simpleXML->xpath('status_code')[0];
$order->status_description = (string) $simpleXML->xpath('status_description')[0];
$order->price = floatval((string) $simpleXML->xpath('price')[0]);
$order->details = Details::fromXML($simpleXML->xpath('details')[0]->asXML());
$order->order_complete = boolval((string) $simpleXML->xpath('order_complete')[0]);
$order->done = boolval((string) $simpleXML->xpath('done')[0]);
return $order;
}

}

0 comments on commit 99f40e2

Please sign in to comment.