1414
1515namespace PhpAidc \LabelPrinter ;
1616
17+ use PhpAidc \LabelPrinter \Label \Batch ;
18+ use PhpAidc \LabelPrinter \Contract \Job ;
1719use PhpAidc \LabelPrinter \Contract \Label ;
1820use PhpAidc \LabelPrinter \Contract \Language ;
1921
@@ -32,19 +34,17 @@ public function __construct(Language $language)
3234 $ this ->language = $ language ;
3335 }
3436
35- public function compile (Label $ label , int $ copies = 1 ): string
37+ public function compile (Job $ job ): string
3638 {
37- $ instructions = [
38- $ this ->language ->compileDeclaration ($ label ),
39- ];
39+ $ instructions = [];
4040
41- foreach ($ label ->getCommands (\get_class ($ this ->language )) as $ command ) {
42- if ($ this ->language ->isSupport ($ command )) {
43- $ instructions [] = $ this ->language ->compileCommand ($ command );
44- }
41+ if ($ job instanceof Label) {
42+ $ instructions [] = $ this ->compileLabel ($ job );
4543 }
4644
47- $ instructions [] = $ this ->language ->compilePrint ($ copies );
45+ if ($ job instanceof Batch) {
46+ $ instructions [] = $ this ->compileBatch ($ job );
47+ }
4848
4949 $ payload = \array_reduce ($ instructions , static function ($ carry , $ item ) {
5050 return $ item instanceof \Generator
@@ -54,4 +54,24 @@ public function compile(Label $label, int $copies = 1): string
5454
5555 return \implode ($ payload );
5656 }
57+
58+ private function compileLabel (Label $ label ): iterable
59+ {
60+ yield from $ this ->language ->compileDeclaration ($ label );
61+
62+ foreach ($ label ->getCommands (\get_class ($ this ->language )) as $ command ) {
63+ if ($ this ->language ->isSupport ($ command )) {
64+ yield from $ this ->language ->compileCommand ($ command );
65+ }
66+ }
67+
68+ yield from $ this ->language ->compilePrint ($ label ->getCopies ());
69+ }
70+
71+ private function compileBatch (Batch $ batch ): iterable
72+ {
73+ foreach ($ batch ->getLabels () as $ label ) {
74+ yield from $ this ->compileLabel ($ label );
75+ }
76+ }
5777}
0 commit comments