Compare commits

..

No commits in common. "af5f5feb33e37bbded655f9fef0b5d9b80262d09" and "875cd8bb46ef51c5ee79d4d10d672bf676a1577a" have entirely different histories.

5 changed files with 18 additions and 143 deletions

View file

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php: [ '8.2', '8.3' ] php: [ '8.1', '8.2', '8.3' ]
services: services:
mysql: mysql:
image: mysql:8 image: mysql:8

2
.gitignore vendored
View file

@ -48,5 +48,3 @@ com_crashlytics_export_strings.xml
crashlytics.properties crashlytics.properties
crashlytics-build.properties crashlytics-build.properties
fabric.properties fabric.properties
.junie.json

View file

@ -15,7 +15,7 @@ MIT
## Installation ## Installation
- Requirements: PHP >= 8.2, PDO extension for your database(s) - Requirements: PHP >= 8.1, PDO extension for your database(s)
- Install via Composer: - Install via Composer:
``` ```

View file

@ -38,7 +38,7 @@
"source": "https://github.com/getphred/pairity" "source": "https://github.com/getphred/pairity"
}, },
"require": { "require": {
"php": "^8.2", "php": ">=8.1",
"ext-mongodb": "*", "ext-mongodb": "*",
"mongodb/mongodb": "^2.0" "mongodb/mongodb": "^2.0"
}, },

View file

@ -143,15 +143,7 @@ abstract class AbstractDao implements DaoInterface
public function findOneBy(array $criteria): ?AbstractDto public function findOneBy(array $criteria): ?AbstractDto
{ {
// Events: dao.beforeFind (criteria may be mutated) // Events: dao.beforeFind (criteria may be mutated)
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'criteria' => &$criteria]; Events::dispatcher()->dispatch('dao.beforeFind', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'criteria' => &$criteria,
];
Events::dispatcher()->dispatch('dao.beforeFind', $ev);
} catch (\Throwable) {
}
$criteria = $this->applyDefaultScopes($criteria); $criteria = $this->applyDefaultScopes($criteria);
$this->applyRuntimeScopesToCriteria($criteria); $this->applyRuntimeScopesToCriteria($criteria);
[$where, $bindings] = $this->buildWhere($criteria); [$where, $bindings] = $this->buildWhere($criteria);
@ -175,15 +167,7 @@ abstract class AbstractDao implements DaoInterface
$this->eagerStrategy = null; // reset $this->eagerStrategy = null; // reset
$this->withStrategies = []; $this->withStrategies = [];
// Events: dao.afterFind // Events: dao.afterFind
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $dto]; Events::dispatcher()->dispatch('dao.afterFind', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $dto,
];
Events::dispatcher()->dispatch('dao.afterFind', $payload);
} catch (\Throwable) {
}
return $dto; return $dto;
} }
@ -206,15 +190,7 @@ abstract class AbstractDao implements DaoInterface
public function findAllBy(array $criteria = []): array public function findAllBy(array $criteria = []): array
{ {
// Events: dao.beforeFind (criteria may be mutated) // Events: dao.beforeFind (criteria may be mutated)
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'criteria' => &$criteria]; Events::dispatcher()->dispatch('dao.beforeFind', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'criteria' => &$criteria,
];
Events::dispatcher()->dispatch('dao.beforeFind', $ev);
} catch (\Throwable) {
}
$criteria = $this->applyDefaultScopes($criteria); $criteria = $this->applyDefaultScopes($criteria);
$this->applyRuntimeScopesToCriteria($criteria); $this->applyRuntimeScopesToCriteria($criteria);
[$where, $bindings] = $this->buildWhere($criteria); [$where, $bindings] = $this->buildWhere($criteria);
@ -236,15 +212,7 @@ abstract class AbstractDao implements DaoInterface
$this->eagerStrategy = null; // reset $this->eagerStrategy = null; // reset
$this->withStrategies = []; $this->withStrategies = [];
// Events: dao.afterFind (list) // Events: dao.afterFind (list)
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dtos' => $dtos]; Events::dispatcher()->dispatch('dao.afterFind', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dtos' => $dtos,
];
Events::dispatcher()->dispatch('dao.afterFind', $payload);
} catch (\Throwable) {
}
return $dtos; return $dtos;
} }
@ -332,15 +300,7 @@ abstract class AbstractDao implements DaoInterface
throw new \InvalidArgumentException('insert() requires non-empty data'); throw new \InvalidArgumentException('insert() requires non-empty data');
} }
// Events: dao.beforeInsert (allow mutation of $data) // Events: dao.beforeInsert (allow mutation of $data)
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'data' => &$data]; Events::dispatcher()->dispatch('dao.beforeInsert', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'data' => &$data,
];
Events::dispatcher()->dispatch('dao.beforeInsert', $ev);
} catch (\Throwable) {
}
$data = $this->prepareForInsert($data); $data = $this->prepareForInsert($data);
$cols = array_keys($data); $cols = array_keys($data);
$placeholders = array_map(fn($c) => ':' . $c, $cols); $placeholders = array_map(fn($c) => ':' . $c, $cols);
@ -350,28 +310,12 @@ abstract class AbstractDao implements DaoInterface
$pk = $this->getPrimaryKey(); $pk = $this->getPrimaryKey();
if ($id !== null) { if ($id !== null) {
$dto = $this->findById($id) ?? $this->hydrate(array_merge($data, [$pk => $id])); $dto = $this->findById($id) ?? $this->hydrate(array_merge($data, [$pk => $id]));
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $dto]; Events::dispatcher()->dispatch('dao.afterInsert', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $dto,
];
Events::dispatcher()->dispatch('dao.afterInsert', $payload);
} catch (\Throwable) {
}
return $dto; return $dto;
} }
// Fallback when lastInsertId is unavailable: return hydrated DTO from provided data // Fallback when lastInsertId is unavailable: return hydrated DTO from provided data
$dto = $this->hydrate($this->castRowFromStorage($data)); $dto = $this->hydrate($this->castRowFromStorage($data));
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $dto]; Events::dispatcher()->dispatch('dao.afterInsert', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $dto,
];
Events::dispatcher()->dispatch('dao.afterInsert', $payload);
} catch (\Throwable) {
}
return $dto; return $dto;
} }
@ -386,16 +330,7 @@ abstract class AbstractDao implements DaoInterface
throw new \InvalidArgumentException('No data provided to update and record not found'); throw new \InvalidArgumentException('No data provided to update and record not found');
} }
// Events: dao.beforeUpdate (mutate $data) // Events: dao.beforeUpdate (mutate $data)
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'id' => $id, 'data' => &$data]; Events::dispatcher()->dispatch('dao.beforeUpdate', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'id' => $id,
'data' => &$data,
];
Events::dispatcher()->dispatch('dao.beforeUpdate', $ev);
} catch (\Throwable) {
}
$toStore = $this->prepareForUpdate($data); $toStore = $this->prepareForUpdate($data);
$self = $this; $self = $this;
$conn = $this->connection; $conn = $this->connection;
@ -414,15 +349,7 @@ abstract class AbstractDao implements DaoInterface
$pk = $this->getPrimaryKey(); $pk = $this->getPrimaryKey();
$result = array_merge($base, $data, [$pk => $id]); $result = array_merge($base, $data, [$pk => $id]);
$dto = $this->hydrate($this->castRowFromStorage($result)); $dto = $this->hydrate($this->castRowFromStorage($result));
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $dto]; Events::dispatcher()->dispatch('dao.afterUpdate', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $dto,
];
Events::dispatcher()->dispatch('dao.afterUpdate', $payload);
} catch (\Throwable) {
}
return $dto; return $dto;
} }
@ -432,42 +359,17 @@ abstract class AbstractDao implements DaoInterface
throw new \InvalidArgumentException('No data provided to update and record not found'); throw new \InvalidArgumentException('No data provided to update and record not found');
} }
// Events: dao.beforeUpdate // Events: dao.beforeUpdate
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'id' => $id, 'data' => &$data]; Events::dispatcher()->dispatch('dao.beforeUpdate', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'id' => $id,
'data' => &$data,
];
Events::dispatcher()->dispatch('dao.beforeUpdate', $ev);
} catch (\Throwable) {
}
$data = $this->prepareForUpdate($data); $data = $this->prepareForUpdate($data);
$this->doImmediateUpdateWithLock($id, $data); $this->doImmediateUpdateWithLock($id, $data);
$updated = $this->findById($id); $updated = $this->findById($id);
if ($updated === null) { if ($updated === null) {
$pk = $this->getPrimaryKey(); $pk = $this->getPrimaryKey();
$dto = $this->hydrate($this->castRowFromStorage(array_merge($data, [$pk => $id]))); $dto = $this->hydrate($this->castRowFromStorage(array_merge($data, [$pk => $id])));
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $dto]; Events::dispatcher()->dispatch('dao.afterUpdate', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $dto,
];
Events::dispatcher()->dispatch('dao.afterUpdate', $payload);
} catch (\Throwable) {
}
return $dto; return $dto;
} }
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'dto' => $updated]; Events::dispatcher()->dispatch('dao.afterUpdate', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'dto' => $updated,
];
Events::dispatcher()->dispatch('dao.afterUpdate', $payload);
} catch (\Throwable) {
}
return $updated; return $updated;
} }
@ -476,15 +378,7 @@ abstract class AbstractDao implements DaoInterface
$uow = UnitOfWork::current(); $uow = UnitOfWork::current();
if ($uow && !UnitOfWork::isSuspended()) { if ($uow && !UnitOfWork::isSuspended()) {
$self = $this; $conn = $this->connection; $theId = $id; $self = $this; $conn = $this->connection; $theId = $id;
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'id' => $id]; Events::dispatcher()->dispatch('dao.beforeDelete', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'id' => $id,
];
Events::dispatcher()->dispatch('dao.beforeDelete', $ev);
} catch (\Throwable) {
}
$uow->enqueueWithMeta($conn, [ $uow->enqueueWithMeta($conn, [
'type' => 'delete', 'type' => 'delete',
'mode' => 'byId', 'mode' => 'byId',
@ -496,15 +390,7 @@ abstract class AbstractDao implements DaoInterface
// deferred; immediate affected count unknown // deferred; immediate affected count unknown
return 0; return 0;
} }
try { try { $ev = ['dao' => $this, 'table' => $this->getTable(), 'id' => $id]; Events::dispatcher()->dispatch('dao.beforeDelete', $ev); } catch (\Throwable) {}
$ev = [
'dao' => $this,
'table' => $this->getTable(),
'id' => $id,
];
Events::dispatcher()->dispatch('dao.beforeDelete', $ev);
} catch (\Throwable) {
}
if ($this->hasSoftDeletes()) { if ($this->hasSoftDeletes()) {
$columns = $this->softDeleteConfig(); $columns = $this->softDeleteConfig();
$deletedAt = $columns['deletedAt'] ?? 'deleted_at'; $deletedAt = $columns['deletedAt'] ?? 'deleted_at';
@ -514,16 +400,7 @@ abstract class AbstractDao implements DaoInterface
} }
$sql = 'DELETE FROM ' . $this->getTable() . ' WHERE ' . $this->getPrimaryKey() . ' = :pk'; $sql = 'DELETE FROM ' . $this->getTable() . ' WHERE ' . $this->getPrimaryKey() . ' = :pk';
$affected = $this->connection->execute($sql, ['pk' => $id]); $affected = $this->connection->execute($sql, ['pk' => $id]);
try { try { $payload = ['dao' => $this, 'table' => $this->getTable(), 'id' => $id, 'affected' => $affected]; Events::dispatcher()->dispatch('dao.afterDelete', $payload); } catch (\Throwable) {}
$payload = [
'dao' => $this,
'table' => $this->getTable(),
'id' => $id,
'affected' => $affected,
];
Events::dispatcher()->dispatch('dao.afterDelete', $payload);
} catch (\Throwable) {
}
return $affected; return $affected;
} }