PHP code example of noahlvb / valueobject

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

    

noahlvb / valueobject example snippets


class Name extends ValueObjectString
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return true;
    }
}

class Name extends ValueObject
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return strlen($value) < 255;
    }
}

class Name extends ValueObject
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return strlen($value) < 255;
    }

    protected function getException(): Exception
    {
        return new NameToLongException();
    }
}