diff --git a/composer.json b/composer.json index 3366f09ce..fbc2beaf7 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "ext-json": "*", "ext-pdo": "*", "cakephp/chronos": "^3", - "cakephp/database": "^4", - "cakephp/validation": "^4.4", + "cakephp/database": "^5", + "cakephp/validation": "^5", "fig/http-message-util": "^1.1", "monolog/monolog": "^3", "nyholm/psr7": "^1.4", @@ -31,7 +31,7 @@ "mikey179/vfsstream": "^1.6", "phpstan/phpstan": "1.*", "phpunit/phpunit": "^10", - "selective/test-traits": "^3", + "selective/test-traits": "^4", "squizlabs/php_codesniffer": "^3", "symfony/console": "^6", "symfony/dotenv": "^6", diff --git a/config/container.php b/config/container.php index ee3db2e2f..3c041a363 100644 --- a/config/container.php +++ b/config/container.php @@ -75,11 +75,13 @@ }, PDO::class => function (ContainerInterface $container) { - $db = $container->get(Connection::class); - $driver = $db->getDriver(); - $driver->connect(); + $driver = $container->get(Connection::class)->getDriver(); - return $driver->getConnection(); + $class = new ReflectionClass($driver); + $method = $class->getMethod('getPdo'); + $method->setAccessible(true); + + return $method->invoke($driver); }, ErrorMiddleware::class => function (ContainerInterface $container) { diff --git a/src/Factory/QueryFactory.php b/src/Factory/QueryFactory.php index 9db6bde38..e07215528 100644 --- a/src/Factory/QueryFactory.php +++ b/src/Factory/QueryFactory.php @@ -3,84 +3,45 @@ namespace App\Factory; use Cake\Database\Connection; -use Cake\Database\Query; +use Cake\Database\Query\DeleteQuery; +use Cake\Database\Query\InsertQuery; +use Cake\Database\Query\SelectQuery; +use Cake\Database\Query\UpdateQuery; -/** - * Factory. - */ final class QueryFactory { private Connection $connection; - /** - * The constructor. - * - * @param Connection $connection The database connection - */ public function __construct(Connection $connection) { $this->connection = $connection; } /** - * Create a new 'select' query for the given table. + * @param string $table * - * @param string $table The table name - * - * @return Query A new select query + * @return SelectQuery */ - public function newSelect(string $table): Query + public function newSelect(string $table): SelectQuery { - return $this->newQuery()->from($table); + return $this->connection->selectQuery([], $table); } - /** - * Create a new query. - * - * @return Query The query - */ - public function newQuery(): Query - { - return $this->connection->newQuery(); - } - - /** - * Create an 'update' statement for the given table. - * - * @param string $table The table to update rows from - * @param array $data The values to be updated - * - * @return Query The new update query - */ - public function newUpdate(string $table, array $data): Query + public function newUpdate(string $table, array $data = []): UpdateQuery { - return $this->newQuery()->update($table)->set($data); + return $this->connection->updateQuery($table)->set($data); } - /** - * Create an 'update' statement for the given table. - * - * @param string $table The table to update rows from - * @param array $data The values to be updated - * - * @return Query The new insert query - */ - public function newInsert(string $table, array $data): Query + public function newInsert(string $table, array $data): InsertQuery { - return $this->newQuery()->insert(array_keys($data)) + return $this->connection->insertQuery($table) + ->insert(array_keys($data)) ->into($table) ->values($data); } - /** - * Create a 'delete' query for the given table. - * - * @param string $table The table to delete from - * - * @return Query A new delete query - */ - public function newDelete(string $table): Query + public function newDelete(string $table): DeleteQuery { - return $this->newQuery()->delete($table); + return $this->connection->deleteQuery($table); } }