Skip to content

Commit 5e064bd

Browse files
committed
Add date string to Carbon conversion
1 parent bd9067e commit 5e064bd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
"require": {
2222
"ext-curl": "*",
2323
"ext-json": "*",
24-
"symfony/polyfill-php80": "^1.0",
24+
"nesbot/carbon": "^2.0",
2525
"psr/http-client-implementation": "^1.0",
2626
"php-http/client-common": "^2.5",
27-
"php-http/discovery": "^1.14"
27+
"php-http/discovery": "^1.14",
28+
"symfony/polyfill-php80": "^1.0"
2829
},
2930
"require-dev": {
3031
"friendsofphp/php-cs-fixer": "^3.9",

src/Resource/AbstractResource.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44

55
namespace Hypernode\Api\Resource;
66

7+
use Carbon\Carbon;
8+
79
class AbstractResource
810
{
911
protected array $data;
12+
protected array $dateAttributes = [];
1013

1114
public function __get(string $name)
1215
{
13-
return $this->data[$name] ?? null;
16+
$value = $this->data[$name] ?? null;
17+
18+
if (in_array($name, $this->dateAttributes)) {
19+
return Carbon::create($value);
20+
}
21+
22+
return $value;
1423
}
1524

1625
public function __isset($name)

0 commit comments

Comments
 (0)