- php-fints Bibliothek von 3.7.0 auf 4.0.0 aktualisiert - Parser-Fix: Ignoriert zusätzliche Bank-Felder statt Exception - HKEKA Segmente implementiert (HIEKASv5, HKEKAv5, HIEKAv5) - HKKAA Segmente implementiert (HIKAASv1, HKKAAv1) - GetStatementFromArchive und GetElectronicStatement Actions HINWEIS: HKKAA/HKEKA funktionieren noch nicht mit VR Bank (Fehler "unerwarteter Aufbau wrt DE 2" - Kontoverbindungsformat) Normale Funktionalität (Transaktionsimport) ist nicht betroffen. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Fhp\Protocol;
|
|
|
|
use Fhp\Segment\BaseSegment;
|
|
|
|
/**
|
|
* Collects segments and assigns them segment numbers in order to form a {@link Message}.
|
|
*/
|
|
class MessageBuilder
|
|
{
|
|
/**
|
|
* This is where the builder collects the (unencrypted/unwrapped) segments as they are being added.
|
|
* @var BaseSegment[]
|
|
*/
|
|
public $segments = [];
|
|
|
|
/** @return MessageBuilder A new instance. */
|
|
public static function create(): MessageBuilder
|
|
{
|
|
return new MessageBuilder();
|
|
}
|
|
|
|
/**
|
|
* @param BaseSegment|BaseSegment[] $segments The segment(s) to be added.
|
|
* @return $this The same instance for chaining.
|
|
*/
|
|
public function add($segments)
|
|
{
|
|
if (is_array($segments)) {
|
|
foreach ($segments as $segment) {
|
|
$this->addInternal($segment);
|
|
}
|
|
} else {
|
|
$this->addInternal($segments);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
private function addInternal(BaseSegment $segment)
|
|
{
|
|
if ($segment->segmentkopf === null) {
|
|
throw new \InvalidArgumentException(
|
|
'Segment lacks Segmentkopf, maybe you called ctor instead of createEmpty()');
|
|
}
|
|
$this->segments[] = $segment;
|
|
}
|
|
|
|
// Note: There is no single build() function, use Message::createWrappedMessage() instead.
|
|
}
|