PHP code example of digital-craftsman / deserializing-connection
1. Go to this page and download the library: Download digital-craftsman/deserializing-connection library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digital-craftsman / deserializing-connection example snippets
final readonly class User
{
public function __construct(
public UserId $userId,
public string $name,
public ProjectIdList $accessibleProjects,
) {
}
}
$user = $this->deserializingConnection->getOne(
sql: <<<'SQL'
SELECT
user_id AS "userId",
name,
accessible_projects AS "accessibleProjects"
FROM
`user`
WHERE user_id = :userId
SQL,
class: User::class,
parameters: [
'userId' => $userId,
],
decoderTypes: [
'accessibleProjects' => DecoderType::JSON,
],
);