- Changed returned object from PdoObject runQuery method correcting 'Creation of dynamic property PDOStatement:: is deprecated'
This commit is contained in:
parent
3c5aa51850
commit
f3712c9cc7
|
@ -27,4 +27,4 @@ class Where implements \Notes\Annotation {
|
|||
$this->operator = $operator !== null ? $operator : Query\Where::OPERATOR_EQUAL;
|
||||
$this->condition = $condition !== null ? $condition : Query\Where::CONDITION_AND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ class EntityResolver {
|
|||
|
||||
protected function getTableAttribute()
|
||||
{
|
||||
return $this->getAnnotationFromClassname(Attribute\Obj\Table::class, false) ?: $this->getAnnotationFromClassname( Table::class );
|
||||
return $this->getAnnotationFromClassname(Attribute\Obj\Table::class, false) ?: $this->getAnnotationFromClassname( Table::class, false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,14 +11,18 @@ class PdoObject extends PDO {
|
|||
|
||||
public bool $executionStatus;
|
||||
|
||||
public function select(string $sql, array $parameters = []): PDOStatement
|
||||
public int $rowCount = 0;
|
||||
|
||||
public mixed $lastInsertId = null;
|
||||
|
||||
public function select(string $sql, array $parameters = []): PDOStatement
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
|
||||
try {
|
||||
if (false !== ( $statement = $this->prepare($sql) )) {
|
||||
$statement = $this->execute($statement, $parameters, false);
|
||||
$statement->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
$this->execute($statement, $parameters, false);
|
||||
|
||||
return $statement;
|
||||
}
|
||||
|
@ -28,10 +32,7 @@ class PdoObject extends PDO {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function runQuery(string $sql, array $parameters = []): ? PDOStatement
|
||||
public function runQuery(string $sql, array $parameters = []): ? static
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
|
||||
|
@ -47,24 +48,25 @@ class PdoObject extends PDO {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function runInsertQuery(string $sql, array $parameters = [])
|
||||
public function runInsertQuery(string $sql, array $parameters = []) : ? static
|
||||
{
|
||||
return $this->runQuery($sql, $parameters);
|
||||
}
|
||||
|
||||
public function runUpdateQuery(string $sql, array $parameters = [])
|
||||
public function runUpdateQuery(string $sql, array $parameters = []) : ? static
|
||||
{
|
||||
return $this->runQuery($sql, $parameters);
|
||||
}
|
||||
|
||||
public function runDeleteQuery(string $sql, array $parameters = []): ? PDOStatement
|
||||
public function runDeleteQuery(string $sql, array $parameters = []) : ? static
|
||||
{
|
||||
return $this->runQuery($sql, $parameters);
|
||||
}
|
||||
|
||||
public function execute(PDOStatement $statement, array $parameters = [], bool $commit = true): ? PDOStatement
|
||||
public function execute(PDOStatement $statement, array $parameters = [], bool $commit = true) : ? static
|
||||
{
|
||||
$this->executionStatus = false;
|
||||
$this->lastInsertId = null;
|
||||
|
||||
try {
|
||||
if ( ! $this->inTransaction() ) {
|
||||
|
@ -74,13 +76,14 @@ class PdoObject extends PDO {
|
|||
$this->executionStatus = empty($parameters) ? $statement->execute() : $statement->execute($parameters);
|
||||
|
||||
if ( $this->executionStatus ) {
|
||||
$statement->lastInsertId = $this->lastInsertId();
|
||||
$this->lastInsertId = $this->lastInsertId();
|
||||
$this->rowCount = $statement->rowCount();
|
||||
|
||||
if ( $commit ) {
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
return $statement;
|
||||
return $this;
|
||||
}
|
||||
else {
|
||||
throw new \PDOException($statement->errorCode() . " - " . json_encode($statement->errorInfo()));
|
||||
|
|
|
@ -57,7 +57,7 @@ trait EntityTrait {
|
|||
$data = json_decode($value, true);
|
||||
|
||||
if (json_last_error() !== \JSON_ERROR_NONE) {
|
||||
throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s", json_last_error_msg(), $value));
|
||||
throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s with field %s", json_last_error_msg(), $value, json_encode($field)));
|
||||
}
|
||||
|
||||
$this->{$field['name']} = $data;
|
||||
|
|
|
@ -51,7 +51,7 @@ class Repository
|
|||
|
||||
public function loadOne() : ? object
|
||||
{
|
||||
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0];
|
||||
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0] ?? null;
|
||||
}
|
||||
|
||||
public function loadOneFromField($field, $value) : ? object
|
||||
|
@ -113,7 +113,7 @@ class Repository
|
|||
throw new Exception\EntityPrimaryKeyUnknown("A primary key value has to be defined to delete an item.");
|
||||
}
|
||||
|
||||
return (bool) $this->wherePrimaryKey($value)->deleteOne()->rowCount();
|
||||
return (bool) $this->wherePrimaryKey($value)->deleteOne()->rowCount;
|
||||
}
|
||||
|
||||
public function destroy(object $entity) : bool
|
||||
|
@ -160,13 +160,13 @@ class Repository
|
|||
if ( $replace || ! $entity->isLoaded() ) {
|
||||
# $dataset = array_filter($dataset, fn($item, $field) => ! ($this->entityResolver->searchFieldAnnotation($field, new Field, false)->readonly ?? false), \ARRAY_FILTER_USE_BOTH);
|
||||
|
||||
$statement = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery();
|
||||
$pdoObject = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery();
|
||||
|
||||
if ( null !== $primaryKeyDefinition ) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
|
||||
if ($statement->lastInsertId ) {
|
||||
$dataset[$pkField] = $statement->lastInsertId;
|
||||
if ($pdoObject->lastInsertId ) {
|
||||
$dataset[$pkField] = $pdoObject->lastInsertId;
|
||||
}
|
||||
elseif ($replace) {
|
||||
$pkValue = $dataset[$pkField];
|
||||
|
@ -175,7 +175,7 @@ class Repository
|
|||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return (bool) ($pkValue ?? $statement->lastInsertId);
|
||||
return (bool) ( $pkValue ?? $pdoObject->lastInsertId );
|
||||
}
|
||||
else {
|
||||
if ( $primaryKeyDefinition === null ) {
|
||||
|
@ -193,7 +193,7 @@ class Repository
|
|||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return $update ? (bool) $update->rowCount() : false;
|
||||
return $update ? (bool) $update->rowCount : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ class Repository
|
|||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return $update ? (bool) $update->rowCount() : false;
|
||||
return $update ? (bool) $update->rowCount : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ class RelationBuilder
|
|||
|
||||
$this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository);
|
||||
|
||||
$results = call_user_func([ $this->repository, $relationRelation->function() ]);
|
||||
$results = call_user_func([ $this->repository, 'loadAll' ]);
|
||||
|
||||
if ($relation->bridgeField ?? false) {
|
||||
$collection = $relation->bridge::entityCollection();
|
||||
|
|
Loading…
Reference in New Issue