Skip to content

Commit

Permalink
Add public methods to collect NITs
Browse files Browse the repository at this point in the history
  • Loading branch information
phpbg committed Mar 10, 2019
1 parent 848b108 commit 6d32ae4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Context/GlobalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function addNit(Nit $nit)
}
}

/**
* @return NitAggregator[]
*/
public function getNitAggregators(): array
{
return $this->nitByNetworks;
}

public function addEit(Eit $eit)
{
if ($eit->currentNextIndicator !== 1) {
Expand Down
18 changes: 16 additions & 2 deletions src/Context/NitAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class NitAggregator

protected $version;

protected $lastSectionNumber;

/**
* Aggregate a new EIT
*
Expand All @@ -63,19 +65,31 @@ public function add(Nit $nit): bool
if (!isset($this->version) || $nit->versionNumber > $this->version || ($nit->versionNumber === 0 && $this->version === 31)) {
// Version update (or initial collection of nit)
$this->version = $nit->versionNumber;
$this->lastSectionNumber = $nit->lastSectionNumber;
$this->segments = [];
}
if (!isset($this->segments[$nit->sectionNumber])) {
$this->segments[$nit->sectionNumber] = $nit;
}
if (count($this->segments) >= $nit->lastSectionNumber + 1) {
return $this->isComplete();
}

/**
* Return true if all NIT segments have been aggregated
* @return bool
*/
public function isComplete(): bool
{
if (!isset($this->lastSectionNumber)) {
return false;
}
if (count($this->segments) >= $this->lastSectionNumber + 1) {
// NIT aggregation is complete
return true;
}
return false;
}


public function __toString()
{
$str = '';
Expand Down

0 comments on commit 6d32ae4

Please sign in to comment.