Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/Ouzo/Core/Config/ConfigValueSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class ConfigValueSelector
{
private const CONFIG_START = '${';
private const CONFIG_END = '}';
private const VALUE_SEPARATOR = ':';
private const string CONFIG_START = '${';
private const string CONFIG_END = '}';
private const string VALUE_SEPARATOR = ':';

public static function selectConfigValue(string $selector): mixed
{
Expand Down
2 changes: 2 additions & 0 deletions src/Ouzo/Core/Config/Inject/ValueAttributeInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class ValueAttributeInjector implements AttributeInjector
{
#[Override]
public function injectForProperties(object $instance, array $reflectionProperties, InstanceFactory $instanceFactory): void
{
foreach ($reflectionProperties as $reflectionProperty) {
Expand All @@ -30,6 +31,7 @@ public function injectForProperties(object $instance, array $reflectionPropertie
}
}

#[Override]
public function injectForConstructorParameter(ReflectionMethod $constructor, InstanceFactory $instanceFactory): array
{
$constructorParameters = [];
Expand Down
12 changes: 12 additions & 0 deletions src/Ouzo/Core/Db/Dialect/MySqlDialect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class MySqlDialect extends Dialect
{
#[Override]
public function table(): string
{
$alias = $this->query->aliasTable;
Expand All @@ -24,57 +25,68 @@ public function table(): string
return $table;
}

#[Override]
public function getConnectionErrorCodes(): array
{
return [2003, 2006];
}

#[Override]
public function getErrorCode(array $errorInfo): mixed
{
return Arrays::getValue($errorInfo, 1);
}

#[Override]
public function using(): string
{
return $this->usingClause($this->query->usingClauses, ' INNER JOIN ', $this->query->table, $this->query->aliasTable);
}

#[Override]
public function batchInsert(string $table, string $primaryKey, array $columns, int $batchSize, ?OnConflict $onConflict): string
{
throw new InvalidArgumentException("Batch insert not supported in mysql");
}

#[Override]
protected function insertEmptyRow(): string
{
return "INSERT INTO {$this->query->table} VALUES ()";
}

#[Override]
public function regexpMatcher(): string
{
return 'REGEXP';
}

#[Override]
protected function quote(string $word): string
{
return "`{$word}`";
}

#[Override]
public function onConflictUpdate(): string
{
$attributes = DialectUtil::buildAttributesPartForUpdate($this->query->updateAttributes);
return " ON DUPLICATE KEY UPDATE {$attributes}";
}

#[Override]
public function onConflictDoNothing(): string
{
throw new InvalidArgumentException("On conflict do nothing is not supported in mysql");
}

#[Override]
protected function getDistinctOnQuery(): string
{
throw new InvalidArgumentException("DISTINCT ON is not supported in mysql");
}

#[Override]
protected function wrapQueryWithDistinctCount(string $sql): string
{
throw new InvalidArgumentException("DISTINCT for COUNT is not supported in mysql");
Expand Down
10 changes: 10 additions & 0 deletions src/Ouzo/Core/Db/Dialect/PostgresDialect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@

class PostgresDialect extends Dialect
{
#[Override]
public function getConnectionErrorCodes(): array
{
return ['57000', '57014', '57P01', '57P02', '57P03'];
}

#[Override]
public function getErrorCode(array $errorInfo): mixed
{
return Arrays::getValue($errorInfo, 0);
}

#[Override]
public function batchInsert(string $table, string $primaryKey, $columns, $batchSize, ?OnConflict $onConflict): string
{
$valueClause = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')';
Expand All @@ -49,21 +52,25 @@ public function batchInsert(string $table, string $primaryKey, $columns, $batchS
return $sql;
}

#[Override]
protected function insertEmptyRow(): string
{
return "INSERT INTO {$this->query->table} DEFAULT VALUES";
}

#[Override]
public function regexpMatcher(): string
{
return '~';
}

#[Override]
protected function quote(string $word): string
{
return "\"{$word}\"";
}

#[Override]
public function onConflictUpdate(): string
{
$attributes = DialectUtil::buildAttributesPartForUpdate($this->query->updateAttributes);
Expand All @@ -72,16 +79,19 @@ public function onConflictUpdate(): string
return " ON CONFLICT ({$joinedColumns}) DO UPDATE SET {$attributes}";
}

#[Override]
public function onConflictDoNothing(): string
{
return " ON CONFLICT DO NOTHING";
}

#[Override]
protected function getDistinctOnQuery(): string
{
return 'DISTINCT ON (' . Joiner::on(', ')->join($this->query->distinctOnColumns) . ') ';
}

#[Override]
protected function wrapQueryWithDistinctCount(string $sql): string
{
return "SELECT count(*) FROM ({$sql}) AS count_data";
Expand Down
15 changes: 15 additions & 0 deletions src/Ouzo/Core/Db/Dialect/Sqlite3Dialect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@

class Sqlite3Dialect extends Dialect
{
#[Override]
public function getConnectionErrorCodes(): array
{
return [10, 11, 14];
}

#[Override]
public function getErrorCode(array $errorInfo): mixed
{
return Arrays::getValue($errorInfo, 1);
}

#[Override]
public function update(): string
{
if ($this->query->aliasTable) {
Expand All @@ -33,6 +36,7 @@ public function update(): string
return parent::update();
}

#[Override]
public function join(): string
{
$any = Arrays::any($this->query->joinClauses, function (JoinClause $joinClause) {
Expand All @@ -44,6 +48,7 @@ public function join(): string
return parent::join();
}

#[Override]
public function lockForUpdate(): string
{
if ($this->query->lockForUpdate) {
Expand All @@ -52,6 +57,7 @@ public function lockForUpdate(): string
return '';
}

#[Override]
public function using(): string
{
if ($this->query->usingClauses) {
Expand All @@ -60,47 +66,56 @@ public function using(): string
return '';
}

#[Override]
public function batchInsert(string $table, string $primaryKey, $columns, $batchSize, ?OnConflict $onConflict): string
{
throw new InvalidArgumentException("Batch insert not supported in sqlite3");
}

#[Override]
protected function insertEmptyRow(): string
{
return "INSERT INTO {$this->query->table} DEFAULT VALUES";
}

#[Override]
public function regexpMatcher(): string
{
//needs package sqlite3-pcre to work correctly
return 'REGEXP';
}

#[Override]
protected function quote(string $word): string
{
return "\"{$word}\"";
}

#[Override]
public function getIteratorOptions(): array
{
return [];
}

#[Override]
public function onConflictUpdate(): string
{
throw new BadMethodCallException('UPSERT is not supported in sqlite3');
}

#[Override]
public function onConflictDoNothing(): string
{
throw new BadMethodCallException('On conflict do nothing is not supported in sqlite3');
}

#[Override]
protected function getDistinctOnQuery(): string
{
throw new InvalidArgumentException("DISTINCT ON is not supported in sqlite3");
}

#[Override]
protected function wrapQueryWithDistinctCount(string $sql): string
{
throw new InvalidArgumentException("DISTINCT for COUNT is not supported in sqlite3");
Expand Down
1 change: 1 addition & 0 deletions src/Ouzo/Core/Db/EmulatedPDOPreparedStatementExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class EmulatedPDOPreparedStatementExecutor extends PDOExecutor
{
#[Override]
public function createPDOStatement(PDO $dbHandle, string $sql, array $boundValues, string $queryString, array $options = []): PDOStatement
{
$sql = PreparedStatementEmulator::substitute($sql, $boundValues);
Expand Down
2 changes: 1 addition & 1 deletion src/Ouzo/Core/Db/ModelQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class ModelQueryBuilder
{
const MODEL_QUERY_MARKER_COMMENT = 'orm:model';
const string MODEL_QUERY_MARKER_COMMENT = 'orm:model';

private Db $db;
/** @var ModelJoin[] */
Expand Down
4 changes: 2 additions & 2 deletions src/Ouzo/Core/Db/OnConflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class OnConflict
{
const DO_NOTHING = 'DO_NOTHING';
const UPDATE = 'UPDATE';
const string DO_NOTHING = 'DO_NOTHING';
const string UPDATE = 'UPDATE';
private ?string $onConflictAction;
private array $onConflictColumns;
private array $onConflictUpdateValues;
Expand Down
2 changes: 1 addition & 1 deletion src/Ouzo/Core/Db/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

class Options
{
const EMULATE_PREPARES = 'EMULATE_PREPARES';
const string EMULATE_PREPARES = 'EMULATE_PREPARES';
}
1 change: 1 addition & 0 deletions src/Ouzo/Core/Db/PDOPreparedStatementExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class PDOPreparedStatementExecutor extends PDOExecutor
{
#[Override]
public function createPDOStatement(PDO $dbHandle, string $sql, array $boundValues, string $queryString, array $options = []): PDOStatement
{
try {
Expand Down
1 change: 1 addition & 0 deletions src/Ouzo/Core/Db/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function withName(string $name): Relation
return new Relation($name, $this->class, $this->localKey, $this->foreignKey, $this->collection, $this->condition);
}

#[Override]
public function __toString(): string
{
return "Relation {$this->name} {$this->class} {$this->localKey} {$this->foreignKey}";
Expand Down
1 change: 1 addition & 0 deletions src/Ouzo/Core/Db/RelationWithAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function __construct(public Relation $relation, public ?string $alias)
{
}

#[Override]
public function __toString(): string
{
return "{$this->relation} {$this->alias}";
Expand Down
5 changes: 5 additions & 0 deletions src/Ouzo/Core/Db/StatementIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ public function __construct(private PDOStatement $statement)
$this->iterator = new IteratorIterator($statement);
}

#[Override]
public function current(): mixed
{
return $this->iterator->current();
}

#[Override]
public function next(): void
{
$this->iterator->next();
}

#[Override]
public function key(): float|bool|int|string|null
{
return $this->iterator->key();
}

#[Override]
public function valid(): bool
{
$valid = $this->iterator->valid();
Expand All @@ -44,6 +48,7 @@ public function valid(): bool
return $valid;
}

#[Override]
public function rewind(): void
{
$this->iterator->rewind();
Expand Down
4 changes: 4 additions & 0 deletions src/Ouzo/Core/Db/WhereClause/ArrayWhereClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ public function __construct(array $where, string $operator = 'AND')
$this->operator = $operator;
}

#[Override]
public function isNeverSatisfied(): bool
{
return Arrays::any($this->where, fn($value) => is_array($value) && sizeof($value) == 0);
}

#[Override]
public function isEmpty(): bool
{
return empty($this->where);
}

#[Override]
public function toSql(): string
{
$whereKeys = self::buildWhereKeys($this->where);
return DialectUtil::joinClauses($whereKeys, $this->operator);
}

#[Override]
public function getParameters(): array
{
return $this->values;
Expand Down
Loading
Loading