-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\PeakWMS\Consumer; | ||
|
||
use CuyZ\Valinor\MapperBuilder; | ||
|
||
final class WebhookConsumer implements WebhookConsumerInterface | ||
{ | ||
private ?MapperBuilder $mapperBuilder = null; | ||
|
||
public function consume(string $json, string $dataClass): object | ||
{ | ||
return $this | ||
->getMapperBuilder() | ||
->mapper() | ||
->map( | ||
$dataClass, | ||
json_decode($json, true, 512, \JSON_THROW_ON_ERROR), | ||
); | ||
} | ||
|
||
public function setMapperBuilder(MapperBuilder $mapperBuilder): void | ||
{ | ||
$this->mapperBuilder = $mapperBuilder; | ||
} | ||
|
||
public function getMapperBuilder(): MapperBuilder | ||
{ | ||
if (null === $this->mapperBuilder) { | ||
$this->mapperBuilder = (new MapperBuilder()) | ||
->allowSuperfluousKeys() | ||
; | ||
} | ||
|
||
return $this->mapperBuilder; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\PeakWMS\Consumer; | ||
|
||
interface WebhookConsumerInterface | ||
{ | ||
/** | ||
* @template T | ||
* | ||
* @param class-string<T> $dataClass | ||
* | ||
* @return T | ||
*/ | ||
public function consume(string $json, string $dataClass): object; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\PeakWMS\DataTransferObject\Webhook; | ||
|
||
final class WebhookDataStockAdjust | ||
{ | ||
public function __construct( | ||
public string $productId, | ||
public int $adjustedQuantity, | ||
public int $quantity, | ||
public ?string $variantId = null, | ||
public ?string $stockHostIdentifier = null, | ||
public ?string $warehouseHostId = null, | ||
public ?string $lotNumber = null, | ||
public ?int $adjustmentReason = null, | ||
public ?int $stockItemId = null, | ||
) { | ||
} | ||
} |