PHP code example of phprise / common-contract

1. Go to this page and download the library: Download phprise/common-contract 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/ */

    

phprise / common-contract example snippets




declare(strict_types=1);

namespace App\Domain\ValueObject;

use Phprise\Common\Contract\Arrayable;
use Phprise\Common\Contract\Snakeable;

final class UserName implements Arrayable, Snakeable
{
    public function __construct(
        private readonly string $firstName,
        private readonly string $lastName
    ) {}

    public function toArray(): array
    {
        return [
            'first_name' => $this->firstName,
            'last_name' => $this->lastName,
        ];
    }

    public function toSnake(): string
    {
        return strtolower($this->firstName . '_' . $this->lastName);
    }
}