Skip to content
Closed
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
30 changes: 30 additions & 0 deletions lib/UserManagement/UpdateUserOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
TARGET CODE:
<?php

namespace Lib\UserManagement;

use Lib\UserManagement\Interfaces\UpdateUserOptions;
use Lib\UserManagement\Interfaces\SerializedUpdateUserOptions;

class UpdateUserOptionsSerializer
{
public static function serializeUpdateUserOptions(UpdateUserOptions $options): SerializedUpdateUserOptions
{
return new SerializedUpdateUserOptions([
'email' => $options->getEmail(),
'email_verified' => $options->getEmailVerified(),
'first_name' => $options->getFirstName(),
'last_name' => $options->getLastName(),
'password' => $options->getPassword(),
'password_hash' => $options->getPasswordHash(),
'password_hash_type' => $options->getPasswordHashType(),
'external_id' => $options->getExternalId(),
]);
}
}

NOTES:
1. PHP does not have direct support for JavaScript's object literal syntax. Instead, we use an associative array to represent the serialized options.
2. In PHP, we typically use getter methods to access object properties, assuming that the `UpdateUserOptions` class follows the common practice of encapsulating its properties with getter and setter methods.
3. The `serializeUpdateUserOptions` function is made static, as it does not depend on any instance-specific data.
4. The `SerializedUpdateUserOptions` is assumed to be a class that accepts an associative array in its constructor. If this is not the case, the implementation of this function may need to be adjusted accordingly.
48 changes: 48 additions & 0 deletions lib/UserManagement/UpdateUserOptionsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
TARGET CODE:
<?php

namespace lib\UserManagement;

use lib\UserManagement\PasswordHashTypeInterface;

interface UpdateUserOptionsInterface
{
public function getUserId(): string;

public function getEmail(): ?string;

public function getFirstName(): ?string;

public function getLastName(): ?string;

public function getEmailVerified(): ?bool;

public function getPassword(): ?string;

public function getPasswordHash(): ?string;

public function getPasswordHashType(): ?PasswordHashTypeInterface;

public function getExternalId(): ?string;
}

interface SerializedUpdateUserOptionsInterface
{
public function getEmail(): ?string;

public function getFirstName(): ?string;

public function getLastName(): ?string;

public function getEmailVerified(): ?bool;

public function getPassword(): ?string;

public function getPasswordHash(): ?string;

public function getPasswordHashType(): ?PasswordHashTypeInterface;

public function getExternalId(): ?string;
}

In PHP, interfaces are used to specify what methods a class must implement. In this case, the UpdateUserOptionsInterface and SerializedUpdateUserOptionsInterface interfaces are defined with getter methods for each property. The "?" before the type means that the return type can be that type or null. The PasswordHashTypeInterface is assumed to be in the same namespace and is used as a return type for getPasswordHashType() method.
Loading