Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Jaimies/master
Nicer access to line items
- Loading branch information
Showing
7 changed files
with
98 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EdifactParser; | ||
|
||
use EdifactParser\Segments\SegmentInterface; | ||
|
||
trait HasRetrievableSegments | ||
{ | ||
/** | ||
* @return array<string, array<string, SegmentInterface>> | ||
*/ | ||
abstract public function allSegments(): array; | ||
|
||
/** | ||
* @return array<string,SegmentInterface> | ||
*/ | ||
public function segmentsByTag(string $tag): array | ||
{ | ||
return $this->allSegments()[$tag] ?? []; | ||
} | ||
|
||
public function segmentByTagAndSubId(string $tag, string $subId): ?SegmentInterface | ||
{ | ||
return $this->allSegments()[$tag][$subId] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EdifactParser; | ||
|
||
use EdifactParser\Segments\SegmentInterface; | ||
|
||
final class LineItem | ||
{ | ||
use HasRetrievableSegments; | ||
|
||
/** | ||
* @param array<string, array<string, SegmentInterface>> $data | ||
*/ | ||
public function __construct(private array $data) | ||
{ | ||
} | ||
|
||
public function allSegments(): array | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters