Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/components/minishop3/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
],
"require": {
"php": ">=8.2",
"rakit/validation": "^1.4",
"robmorgan/phinx": "^0.16",
"nikic/fast-route": "^1.3",
"intervention/image": "^3.0",
Expand Down
48 changes: 1 addition & 47 deletions core/components/minishop3/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use MiniShop3\MiniShop3;
use MiniShop3\Model\msCustomer;
use MiniShop3\Services\Customer\CustomerPublicDto;
use MiniShop3\Services\Validation\ValidationService;
use MODX\Revolution\modX;
use Rakit\Validation\Validator;

/**
* CustomerProfileController - Customer profile management API controller
Expand Down Expand Up @@ -84,9 +84,7 @@ public function update(array $data): array
}

$customerId = (int)$customer->get('id');
$validator = new Validator();
$validation = $validator->make($data, $this->getProfileFieldRules());

$validation = $this->getValidationService()->make($data, $this->getProfileFieldRules());
$validation->validate();

if ($validation->fails()) {
Expand Down Expand Up @@ -173,7 +171,7 @@ public function updateField(array $data): array
$rules = $this->getProfileFieldRules();
if (isset($rules[$key])) {
$value = trim((string) ($data['value'] ?? ''));
$validation = (new Validator())->make([$key => $value], [$key => $rules[$key]]);
$validation = $this->getValidationService()->make([$key => $value], [$key => $rules[$key]]);
$validation->validate();

if ($validation->fails()) {
Expand Down Expand Up @@ -232,6 +230,16 @@ protected function getProfileFieldRules(): array
];
}

/**
* Resolve the canonical validation service from MODX DI.
*/
protected function getValidationService(): ValidationService
{
$service = $this->modx->services->get('ms3_validation_service');

return $service instanceof ValidationService ? $service : new ValidationService();
}

/**
* Coerce a single-field quick update value using xPDO field metadata (extra columns & OE fields).
*
Expand Down
19 changes: 12 additions & 7 deletions core/components/minishop3/src/Controllers/Customer/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
use MiniShop3\Model\msCustomer;
use MiniShop3\Model\msCustomerToken;
use MiniShop3\Services\Customer\CustomerAddressManager;
use MiniShop3\Services\Validation\ValidationService;
use MiniShop3\Utils\CookieHelper;
use MODX\Revolution\modX;

use Rakit\Validation\Validator;

class Customer
{
/** @var modX $modx */
Expand Down Expand Up @@ -251,16 +250,12 @@ public function validate(string $key, mixed $value): mixed

// Standard validation
if (!empty($this->validationRules[$key])) {
$validator = new Validator();

$validation = $validator->validate(
$validation = $this->getValidationService()->validate(
[$key => $value],
[$key => $this->validationRules[$key]],
$this->validationMessages
);

$validation->validate();

if ($validation->fails()) {
$errors = $validation->errors();

Expand Down Expand Up @@ -388,6 +383,16 @@ protected function getAddressManager(): CustomerAddressManager
return $service;
}

/**
* Resolve the canonical validation service from MODX DI.
*/
protected function getValidationService(): ValidationService
{
$service = $this->modx->services->get('ms3_validation_service');

return $service instanceof ValidationService ? $service : new ValidationService();
}

/**
* Get or create customer for order
*
Expand Down
4 changes: 4 additions & 0 deletions core/components/minishop3/src/ServiceRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ class ServiceRegistry
'class' => \MiniShop3\Services\CustomerFactory::class,
'interface' => null,
],
'ms3_validation_service' => [
'class' => \MiniShop3\Services\Validation\ValidationService::class,
'interface' => null,
],
];

/**
Expand Down
16 changes: 12 additions & 4 deletions core/components/minishop3/src/Services/Order/OrderFieldManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use MiniShop3\Model\msOrder;
use MiniShop3\Model\msOrderLog;
use MiniShop3\Services\Order\OrderLogService;
use MiniShop3\Services\Validation\ValidationService;
use MODX\Revolution\modX;
use Rakit\Validation\Validator;

/**
* Order Field Manager
Expand Down Expand Up @@ -223,13 +223,11 @@ public function validate(array $orderData, string $key, mixed $value): array
}

// Run validation
$validator = new Validator();
$validation = $validator->validate(
$validation = $this->getValidationService()->validate(
[$key => $value],
[$key => $this->validationRules[$key]],
$this->validationMessages
);
$validation->validate();

if ($validation->fails()) {
$errors = $validation->errors();
Expand Down Expand Up @@ -320,6 +318,16 @@ public function setValidationMessages(array $messages): void
$this->validationMessages = array_merge($this->validationMessages, $messages);
}

/**
* Resolve the canonical validation service from MODX DI.
*/
protected function getValidationService(): ValidationService
{
$service = $this->modx->services->get('ms3_validation_service');

return $service instanceof ValidationService ? $service : new ValidationService();
}

/**
* Shorthand for success response
*/
Expand Down
Loading