1. Go to this page and download the library: Download digital-craftsman/ids 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 / ids example snippets
declare(strict_types=1);
namespace App\ValueObject;
use DigitalCraftsman\Ids\ValueObject\Id;
final readonly class UserId extends Id
{
}
$requestingUser->userId->mustNotBeEqualTo(
$command->targetUserId,
static fn () => new Exception\UserCanNotTargetItself(),
);
namespace App\DTO;
final readonly class UserPayload
{
public function __construct(
public UserId $userId,
public string $firstName,
public string $lastName,
) {
}
}
public function __construct(
private SerializerInterface $serializer,
) {
}
public function handle(UserPayload $userPayload): string
{
return $this->serializer->serialize($userPayload, JsonEncoder::FORMAT);
}
declare(strict_types=1);
namespace App\Entity;
use App\ValueObject\UserId;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity()]
#[ORM\Table(name: '`user`')]
class User
{
#[ORM\Id]
#[ORM\Column(name: 'id', type: UserId::class)]
public UserId $userId;
...
}
declare(strict_types=1);
namespace App\ValueObject;
use DigitalCraftsman\Ids\ValueObject\IdList;
/** @extends IdList<UserId> */
final readonly class UserIdList extends IdLIst
{
public static function handlesIdClass(): string
{
return UserId::class;
}
}
$userIdList = new UserIdList($userIds);
if ($idsOfEnabledUsers->contains($command->userId)) {
...
}
$idsOfEnabledUsers->mustContainId(
$command->targetUserId,
static fn () => new Exception\UserIsNotEnabled(),
);
declare(strict_types=1);
namespace App\Entity;
use App\ValueObject\UserIdList;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity()]
#[ORM\Table(name: 'investor')]
class Investor
{
...
#[ORM\Column(name: 'ids_of_users_with_access', type: UserIdList::class)]
public UserIdList $idsOfUsersWithAccess;
...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.