PHP code example of anis-saied / user-core-php

1. Go to this page and download the library: Download anis-saied/user-core-php 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/ */

    

anis-saied / user-core-php example snippets


use AnisSaied\UserCore\Domain\ValueObject\UserId;
use AnisSaied\UserCore\Domain\ValueObject\Email;
use AnisSaied\UserCore\Domain\User;
use AnisSaied\UserCore\Application\Service\UserService;
use AnisSaied\UserCore\Infrastructure\Persistence\InMemoryUserRepository;

/**
 * Repository
 */
$repository = new InMemoryUserRepository();

/**
 * Service
 * En test → InMemoryUserRepository
 * En Laravel → EloquentUserRepository
 * En Symfony → DoctrineUserRepository
 * Sans changer une seule ligne dans UserService.
 */
$service = new UserService($repository);

// Create a user
$user = new User(new UserId('1'), 'Anis', new Email('[email protected]'));
$service->create($user);