Initial commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Logic\Dividends;
|
||||
|
||||
|
||||
class XMLReader
|
||||
{
|
||||
private string $filePath;
|
||||
private array $datas=[];
|
||||
|
||||
public function __construct(string $file)
|
||||
{
|
||||
if (file_exists($file)){
|
||||
$this->filePath = $file;
|
||||
}
|
||||
}
|
||||
|
||||
public function readFile()
|
||||
{
|
||||
if (!is_file($this->filePath)) {
|
||||
return;
|
||||
}
|
||||
$a = $this->tryCashTransaction();
|
||||
$xml = simplexml_load_file($this->filePath, null, LIBXML_NOCDATA);
|
||||
$json = json_encode($xml);
|
||||
$arr = json_decode($json, true);
|
||||
$this->findValues($arr);
|
||||
}
|
||||
|
||||
private function tryCashTransaction()
|
||||
{
|
||||
$obj = new \DOMDocument();
|
||||
$obj->load($this->filePath);
|
||||
$node = $obj->getElementsByTagName("CashTransaction");
|
||||
if (count($node) < 1) {
|
||||
return;
|
||||
}
|
||||
foreach ($node as $item) {
|
||||
$values = explode(" ", $item->getAttribute('description'));
|
||||
dd($values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function findValues(array $arr)
|
||||
{
|
||||
$obj = new DividendsData();
|
||||
$isset=false;
|
||||
foreach ($arr as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->findValues($value);
|
||||
} else {
|
||||
$isset=true;
|
||||
if ($key === "currency") {
|
||||
$obj->setCurrency($value);
|
||||
}
|
||||
if ($key === "payDate") {
|
||||
$tmp = str_split($value, 4);
|
||||
$y=$tmp[0];
|
||||
$tmp = str_split($tmp[1],2);
|
||||
$d = $tmp[1];
|
||||
$m = $tmp[0];
|
||||
|
||||
// $a = implode("-", array_merge(str_split($tmp[1],2),$tmp[0]));
|
||||
// print_r($a);
|
||||
$obj->setDateTime(new \DateTime("$y-$m-$d"));
|
||||
}
|
||||
if ($key === "quantity") {
|
||||
$obj->setCount(intval($value));
|
||||
}
|
||||
if ($key === "isin") {
|
||||
$obj->setIsin($value);
|
||||
}
|
||||
if ($key === "grossRate") {
|
||||
$obj->setValue(floatval($value));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if ($isset) {
|
||||
$this->datas[] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user