File tree Expand file tree Collapse file tree 14 files changed +95
-77
lines changed
Feature/Drivers/CustomDriver/Driver Expand file tree Collapse file tree 14 files changed +95
-77
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
return [
4
6
/*
5
7
|--------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -17,6 +17,21 @@ public function __construct(array $data = [])
17
17
$ this ->mapResponse ($ data );
18
18
}
19
19
20
+ public function toArray (): array
21
+ {
22
+ $ publicProperties = (new ReflectionObject ($ this ))->getProperties (ReflectionProperty::IS_PUBLIC );
23
+
24
+ return collect ($ publicProperties )
25
+ ->mapWithKeys (function (ReflectionProperty $ property ) {
26
+ return [$ property ->name => $ this ->{$ property ->name }];
27
+ })->toArray ();
28
+ }
29
+
30
+ public function jsonSerialize (): mixed
31
+ {
32
+ return $ this ->toArray ();
33
+ }
34
+
20
35
protected function mapResponse (array $ data ): void
21
36
{
22
37
foreach ($ data as $ key => $ value ) {
@@ -44,19 +59,4 @@ protected function getTimestamp($timestamp): ?Carbon
44
59
45
60
return $ date ;
46
61
}
47
-
48
- public function toArray (): array
49
- {
50
- $ publicProperties = (new ReflectionObject ($ this ))->getProperties (ReflectionProperty::IS_PUBLIC );
51
-
52
- return collect ($ publicProperties )
53
- ->mapWithKeys (function (ReflectionProperty $ property ) {
54
- return [$ property ->name => $ this ->{$ property ->name }];
55
- })->toArray ();
56
- }
57
-
58
- public function jsonSerialize (): mixed
59
- {
60
- return $ this ->toArray ();
61
- }
62
62
}
Original file line number Diff line number Diff line change 10
10
11
11
class PrintJob extends Entity
12
12
{
13
+ protected const VALID_CONTENT_TYPES = [
14
+ ContentType::PDF_BASE64 ,
15
+ ContentType::RAW_BASE64 ,
16
+ ContentType::PDF_URI ,
17
+ ContentType::RAW_URI ,
18
+ ];
19
+
13
20
/**
14
21
* The print job's ID.
15
22
*/
@@ -60,13 +67,6 @@ class PrintJob extends Entity
60
67
*/
61
68
public ?Printer $ printer = null ;
62
69
63
- protected const VALID_CONTENT_TYPES = [
64
- ContentType::PDF_BASE64 ,
65
- ContentType::RAW_BASE64 ,
66
- ContentType::PDF_URI ,
67
- ContentType::RAW_URI ,
68
- ];
69
-
70
70
public function setPrinter (array $ data ): self
71
71
{
72
72
$ this ->printer = new Printer ($ data );
@@ -180,15 +180,15 @@ public function setCreateTimestamp($date): self
180
180
return $ this ;
181
181
}
182
182
183
- protected function isValidContentType (string $ type ): bool
184
- {
185
- return in_array ($ type , static ::VALID_CONTENT_TYPES , true );
186
- }
187
-
188
183
public function toArray (): array
189
184
{
190
185
return array_merge (parent ::toArray (), [
191
186
'createTimestamp ' => $ this ->created ,
192
187
]);
193
188
}
189
+
190
+ protected function isValidContentType (string $ type ): bool
191
+ {
192
+ return in_array ($ type , static ::VALID_CONTENT_TYPES , true );
193
+ }
194
194
}
Original file line number Diff line number Diff line change @@ -31,14 +31,9 @@ public function __construct(protected string $apiKey)
31
31
])->acceptJson ();
32
32
}
33
33
34
- protected function endpoint (string $ service ): string
35
- {
36
- return $ this ->applyPaginationToUrl (static ::BASE_URL . $ service );
37
- }
38
-
39
- protected function getRequest (string $ service ): array
34
+ public function postRequest (string $ service , array $ data = [])
40
35
{
41
- $ response = $ this ->http ->get ($ this ->endpoint ($ service ));
36
+ $ response = $ this ->http ->post ($ this ->endpoint ($ service ), $ data );
42
37
43
38
if (! $ response ->successful ()) {
44
39
$ this ->handleFailedResponse ($ response );
@@ -47,9 +42,14 @@ protected function getRequest(string $service): array
47
42
return $ response ->json ();
48
43
}
49
44
50
- public function postRequest (string $ service, array $ data = [])
45
+ protected function endpoint (string $ service): string
51
46
{
52
- $ response = $ this ->http ->post ($ this ->endpoint ($ service ), $ data );
47
+ return $ this ->applyPaginationToUrl (static ::BASE_URL . $ service );
48
+ }
49
+
50
+ protected function getRequest (string $ service ): array
51
+ {
52
+ $ response = $ this ->http ->get ($ this ->endpoint ($ service ));
53
53
54
54
if (! $ response ->successful ()) {
55
55
$ this ->handleFailedResponse ($ response );
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Rawilk \Printing \Contracts ;
4
6
5
7
use Illuminate \Support \Collection ;
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Rawilk \Printing \Contracts ;
4
6
5
7
use Carbon \Carbon ;
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Rawilk \Printing \Contracts ;
4
6
5
7
interface PrintTask
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Rawilk \Printing \Contracts ;
4
6
5
7
use Illuminate \Support \Collection ;
Original file line number Diff line number Diff line change @@ -56,6 +56,27 @@ public function __construct()
56
56
static ::$ lineCharacterLength = config ('printing.receipts.line_character_length ' , 45 );
57
57
}
58
58
59
+ public function __destruct ()
60
+ {
61
+ $ this ->close ();
62
+ }
63
+
64
+ public function __toString (): string
65
+ {
66
+ return $ this ->connector ->getData ();
67
+ }
68
+
69
+ public function __call ($ name , $ arguments )
70
+ {
71
+ if (method_exists ($ this ->printer , $ name )) {
72
+ $ this ->printer ->{$ name }(...$ arguments );
73
+
74
+ return $ this ;
75
+ }
76
+
77
+ throw new InvalidArgumentException ("Method [ {$ name }] not found on receipt printer object. " );
78
+ }
79
+
59
80
public function centerAlign (): self
60
81
{
61
82
$ this ->printer ->setJustification (Printer::JUSTIFY_CENTER );
@@ -131,25 +152,4 @@ public function doubleLine(): self
131
152
{
132
153
return $ this ->text (str_repeat ('= ' , static ::$ lineCharacterLength ));
133
154
}
134
-
135
- public function __toString (): string
136
- {
137
- return $ this ->connector ->getData ();
138
- }
139
-
140
- public function __call ($ name , $ arguments )
141
- {
142
- if (method_exists ($ this ->printer , $ name )) {
143
- $ this ->printer ->{$ name }(...$ arguments );
144
-
145
- return $ this ;
146
- }
147
-
148
- throw new InvalidArgumentException ("Method [ {$ name }] not found on receipt printer object. " );
149
- }
150
-
151
- public function __destruct ()
152
- {
153
- $ this ->close ();
154
- }
155
155
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Rawilk \Printing \Tests \Concerns ;
4
6
5
7
use Illuminate \Support \Facades \Http ;
You can’t perform that action at this time.
0 commit comments