Skip to content

Commit 552a876

Browse files
committed
More compatibility adjustments
1 parent 7ba0095 commit 552a876

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"prefer-stable": true,
66
"license": "MIT",
77
"require": {
8-
"php": ">=8.1",
8+
"php": ">=8.1 <8.4",
99
"ext-json": "*",
1010
"ext-openssl": "*",
1111
"ext-curl": "*",

src/Repository/BaseRepository.php

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use ByJG\Config\Exception\KeyNotFoundException;
1111
use ByJG\MicroOrm\Exception\OrmBeforeInvalidException;
1212
use ByJG\MicroOrm\Exception\OrmInvalidFieldsException;
13-
use ByJG\MicroOrm\Exception\RepositoryReadOnlyException;
14-
use ByJG\MicroOrm\Exception\UpdateConstraintException;
1513
use ByJG\MicroOrm\FieldMapping;
1614
use ByJG\MicroOrm\Literal\HexUuidLiteral;
1715
use ByJG\MicroOrm\Literal\Literal;
@@ -41,6 +39,11 @@ public function get($itemId)
4139
return $this->repository->get(HexUuidLiteral::create($itemId));
4240
}
4341

42+
public function getRepository(): Repository
43+
{
44+
return $this->repository;
45+
}
46+
4447
public function getMapper()
4548
{
4649
return $this->repository->getMapper();
@@ -84,7 +87,7 @@ public function listGeneric($tableName, $fields = [], $page = 0, $size = 20, $or
8487

8588
$object = $query->build($this->repository->getDbDriver());
8689

87-
$iterator = $this->repository->getDbDriver()->getIterator($object["sql"], $object["params"]);
90+
$iterator = $this->repository->getDbDriver()->getIterator($object->getSql(), $object->getParameters());
8891
return $iterator->toArray();
8992
}
9093

@@ -158,26 +161,31 @@ public static function getUuid()
158161
protected function setClosureFixBinaryUUID(?Mapper $mapper, $binPropertyName = 'id', $uuidStrPropertyName = 'uuid')
159162
{
160163
$fieldMapping = FieldMapping::create($binPropertyName)
161-
->withUpdateFunction(function ($value, $instance) {
162-
if (empty($value)) {
163-
return null;
164-
}
165-
if (!($value instanceof Literal)) {
166-
$value = new HexUuidLiteral($value);
167-
}
168-
return $value;
169-
})
170-
->withSelectFunction(function ($value, $instance) use ($binPropertyName, $uuidStrPropertyName) {
171-
if (!empty($uuidStrPropertyName)) {
172-
$fieldValue = $instance->{'get' . $uuidStrPropertyName}();
173-
} else {
174-
$fieldValue = HexUuidLiteral::getFormattedUuid($instance->{'get' . $binPropertyName}(), false);
164+
->withUpdateFunction(
165+
function ($value, $instance) {
166+
if (empty($value)) {
167+
return null;
168+
}
169+
if (!($value instanceof Literal)) {
170+
$value = new HexUuidLiteral($value);
171+
}
172+
return $value;
175173
}
176-
if (is_null($fieldValue)) {
177-
return null;
174+
)
175+
->withSelectFunction(
176+
function ($value, $instance) use ($binPropertyName, $uuidStrPropertyName) {
177+
if (!empty($uuidStrPropertyName)) {
178+
$fieldValue = $instance->{'get' . $uuidStrPropertyName}();
179+
} else {
180+
$itemValue = $instance->{'get' . $binPropertyName}();
181+
$fieldValue = HexUuidLiteral::getFormattedUuid($itemValue, false, $itemValue);
182+
}
183+
if (is_null($fieldValue)) {
184+
return null;
185+
}
186+
return $fieldValue;
178187
}
179-
return $fieldValue;
180-
});
188+
);
181189

182190
if (!empty($mapper)) {
183191
$mapper->addFieldMapping($fieldMapping);
@@ -187,26 +195,21 @@ protected function setClosureFixBinaryUUID(?Mapper $mapper, $binPropertyName = '
187195
}
188196

189197
/**
190-
* @param $model
191-
* @param UpdateConstraint|null $updateConstraint
198+
* @param $model
192199
* @return mixed
193200
* @throws InvalidArgumentException
194201
* @throws OrmBeforeInvalidException
195202
* @throws OrmInvalidFieldsException
196203
* @throws \ByJG\MicroOrm\Exception\InvalidArgumentException
197-
* @throws RepositoryReadOnlyException
198-
* @throws UpdateConstraintException
199204
*/
200205
public function save($model, ?UpdateConstraint $updateConstraint = null)
201206
{
202207
$model = $this->repository->save($model, $updateConstraint);
203208

204209
$primaryKey = $this->repository->getMapper()->getPrimaryKey()[0];
205210

206-
if ($model->{"get$primaryKey"}() instanceof HexUuidLiteral) {
207-
/** @var HexUuidLiteral $literal */
208-
$literal = $model->{"get$primaryKey"}();
209-
$model->{"set$primaryKey"}($literal->formatUuid());
211+
if ($model->{"get$primaryKey"}() instanceof Literal) {
212+
$model->{"set$primaryKey"}(HexUuidLiteral::create($model->{"get$primaryKey"}()));
210213
}
211214

212215
return $model;

src/Util/OpenApiContext.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public static function validateRequest(HttpRequest $request)
1818
$path = $request->getRequestPath();
1919
$method = $request->server('REQUEST_METHOD');
2020

21-
// Returns a SwaggerRequestBody instance
22-
$bodyRequestDef = $schema->getRequestParameters($path, $method);
23-
2421
// Validate the request body (payload)
2522
if (str_contains($request->getHeader('Content-Type') ?? "", 'multipart/')) {
2623
$requestBody = $request->post();
@@ -31,7 +28,16 @@ public static function validateRequest(HttpRequest $request)
3128
}
3229

3330
try {
34-
$bodyRequestDef->match($requestBody);
31+
// Validate the request path and query against the OpenAPI schema
32+
$schema->getPathDefinition($path, $method);
33+
34+
if (!empty($requestBody)) {
35+
// Returns a SwaggerRequestBody instance
36+
$bodyRequestDef = $schema->getRequestParameters($path, $method);
37+
$bodyRequestDef->match($requestBody);
38+
} else {
39+
return [];
40+
}
3541
} catch (Exception $ex) {
3642
throw new Error400Exception(explode("\n", $ex->getMessage())[0]);
3743
}

0 commit comments

Comments
 (0)