Skip to content

Commit 6d32ae4

Browse files
committed
Add public methods to collect NITs
1 parent 848b108 commit 6d32ae4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Context/GlobalContext.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public function addNit(Nit $nit)
5757
}
5858
}
5959

60+
/**
61+
* @return NitAggregator[]
62+
*/
63+
public function getNitAggregators(): array
64+
{
65+
return $this->nitByNetworks;
66+
}
67+
6068
public function addEit(Eit $eit)
6169
{
6270
if ($eit->currentNextIndicator !== 1) {

src/Context/NitAggregator.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class NitAggregator
4444

4545
protected $version;
4646

47+
protected $lastSectionNumber;
48+
4749
/**
4850
* Aggregate a new EIT
4951
*
@@ -63,19 +65,31 @@ public function add(Nit $nit): bool
6365
if (!isset($this->version) || $nit->versionNumber > $this->version || ($nit->versionNumber === 0 && $this->version === 31)) {
6466
// Version update (or initial collection of nit)
6567
$this->version = $nit->versionNumber;
68+
$this->lastSectionNumber = $nit->lastSectionNumber;
6669
$this->segments = [];
6770
}
6871
if (!isset($this->segments[$nit->sectionNumber])) {
6972
$this->segments[$nit->sectionNumber] = $nit;
7073
}
71-
if (count($this->segments) >= $nit->lastSectionNumber + 1) {
74+
return $this->isComplete();
75+
}
76+
77+
/**
78+
* Return true if all NIT segments have been aggregated
79+
* @return bool
80+
*/
81+
public function isComplete(): bool
82+
{
83+
if (!isset($this->lastSectionNumber)) {
84+
return false;
85+
}
86+
if (count($this->segments) >= $this->lastSectionNumber + 1) {
7287
// NIT aggregation is complete
7388
return true;
7489
}
7590
return false;
7691
}
7792

78-
7993
public function __toString()
8094
{
8195
$str = '';

0 commit comments

Comments
 (0)