| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
-
- namespace App\Domain\Entity;
-
- final readonly class ParsedPortfolio
- {
- private array $header;
-
- private array $details;
-
- private array $movements;
-
-
- public function __construct(array $header, array $details, array $movements)
- {
- $this->header = $header;
- $this->details = $details;
- $this->movements = $movements;
- }
-
- public function getHeader(): array
- {
- return $this->header;
- }
-
- public function getDetails(): array
- {
- return $this->details;
- }
-
- public function getMovements(): array
- {
- return $this->movements;
- }
-
- public function extractPeriod(): array
- {
- if (array_key_exists('НачПериода', $this->header)) {
- $startDate = \DateTime::createFromFormat('d.m.Y', $this->header['НачПериода']);
- $endDate = \DateTime::createFromFormat('d.m.Y', $this->header['КонПериода']);
- } elseif (array_key_exists('СтрокаПериода', $this->header)) {
- $chunks = explode(' ', $this->header['СтрокаПериода']);
-
- if(count($chunks) !== 4) throw new \Exception('Unexpected period format!');
-
- $startDate = \DateTime::createFromFormat('d.m.Y', $chunks[1]);
- $endDate = \DateTime::createFromFormat('d.m.Y', $chunks[3]);
- } else {
- throw new \Exception('Can not detect xml header version!');
- }
-
- return [$startDate, $endDate];
- }
- }
|