-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README, EasyAdmin integration, SQLite support and some other s…
…mall fixes
- Loading branch information
Showing
56 changed files
with
1,010 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Infrastructure/Persistence/Dql/DqlFunctionsFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ranky\MediaBundle\Infrastructure\Persistence\Dql; | ||
|
||
/** | ||
* @phpstan-type DqlFunctions = array<"string_functions"|"datetime_functions"|"numeric_functions", array<string, class-string<\Doctrine\ORM\Query\AST\Functions\FunctionNode>>> | ||
*/ | ||
interface DqlFunctionsFactory | ||
{ | ||
/** | ||
* @return DqlFunctions | ||
*/ | ||
public static function functions(): array; | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Infrastructure/Persistence/Dql/DqlFunctionsManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Ranky\MediaBundle\Infrastructure\Persistence\Dql; | ||
|
||
/** | ||
* @phpstan-import-type DqlFunctions from DqlFunctionsFactory | ||
*/ | ||
class DqlFunctionsManager | ||
{ | ||
public const MYSQL = 'mysql'; | ||
public const SQLITE = 'sqlite'; | ||
public const DRIVERS = [ | ||
self::MYSQL, | ||
self::SQLITE, | ||
]; | ||
|
||
/** | ||
* @param string $driver | ||
* @return DqlFunctions | ||
*/ | ||
public static function getFunctionsByDriver(string $driver): array | ||
{ | ||
return match ($driver) { | ||
self::MYSQL => MysqlDqlFunctionsFactory::functions(), | ||
self::SQLITE => SqliteDqlFunctionsFactory::functions(), | ||
default => throw new \InvalidArgumentException( | ||
\sprintf( | ||
'Invalid database driver %s. Available drivers: %s', | ||
$driver, | ||
\implode(',', \array_keys(self::DRIVERS)) | ||
) | ||
), | ||
}; | ||
} | ||
|
||
/** | ||
* @param string $classPlatform | ||
* @return DqlFunctions | ||
*/ | ||
public static function getFunctionsByClassPlatform(string $classPlatform): array | ||
{ | ||
$classPlatform = \mb_strtolower($classPlatform); | ||
|
||
/** @see \Doctrine\DBAL\Platforms\AbstractPlatform */ | ||
return match (true) { | ||
(\str_contains($classPlatform, 'mysql') || \str_contains( | ||
$classPlatform, | ||
'mariadb' | ||
)) => MysqlDqlFunctionsFactory::functions(), | ||
(\str_contains($classPlatform, 'sqlite')) => SqliteDqlFunctionsFactory::functions(), | ||
default => throw new \InvalidArgumentException( | ||
\sprintf( | ||
'Invalid database driver %s. Available drivers: %s', | ||
$classPlatform, | ||
\implode(',', \array_keys(self::DRIVERS)) | ||
) | ||
), | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.