From 95e4ff445db0cb6b008a3a6e7357dacd0b28b4e8 Mon Sep 17 00:00:00 2001 From: Bohan Yang Date: Sun, 24 Sep 2023 05:25:58 +0000 Subject: [PATCH] u --- packages/mango/Doctrine/Query.php | 21 +++++++++++++++++++-- packages/mango/Jose/CachedJWKSLoader.php | 4 +--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/mango/Doctrine/Query.php b/packages/mango/Doctrine/Query.php index 1237d72..d435681 100644 --- a/packages/mango/Doctrine/Query.php +++ b/packages/mango/Doctrine/Query.php @@ -866,9 +866,17 @@ public function gte(string|array $x, $y): string return $this->comparison($x, '>=', $y); } - public function executeStatement(?int $rowsAffected = null): int + public function executeStatement(?int $rowsAffected = null, ?callable $preprocess = null): int { - $actual = $this->builder->executeStatement(); + $sql = $this->getSQL(); + $params = $this->getParameters(); + $types = $this->getParameterTypes(); + + if ($preprocess) { + $preprocess($sql, $params, $types); + } + + $actual = $this->connection->executeStatement($sql, $params, $types); if ($actual !== ($rowsAffected ?? $actual)) { throw UnexpectedRowsAffected::create($rowsAffected, $actual); @@ -919,4 +927,13 @@ public function where(mixed ...$expressions): self return $this; } + + public function onConflictDoNothing(string|array $conflict, ?int $rowsAffected = null): int + { + $conflict = array_map(static fn ($n) => $this->quoteColumn($n), (array) $conflict); + + return $this->executeStatement($rowsAffected, static function (&$sql) use ($conflict) { + $sql .= ' ON CONFLICT (' . implode(', ', $conflict) . ') DO NOTHING'; + }); + } } diff --git a/packages/mango/Jose/CachedJWKSLoader.php b/packages/mango/Jose/CachedJWKSLoader.php index b08d332..59bf59b 100644 --- a/packages/mango/Jose/CachedJWKSLoader.php +++ b/packages/mango/Jose/CachedJWKSLoader.php @@ -11,8 +11,6 @@ use Symfony\Contracts\Cache\CacheInterface; use Symfony\Contracts\Cache\ItemInterface; -use function spl_object_hash; - class CachedJWKSLoader implements JWKSLoader { public function __construct( @@ -27,7 +25,7 @@ public function __construct( public function __invoke(): JWKSet { - return $this->cache->get(spl_object_hash($this), function (ItemInterface $item) { + return $this->cache->get($this->url, function (ItemInterface $item) { $item->expiresAfter($this->expiresAfter); return $this->jkuFactory->loadFromUrl($this->url, $this->header);