PHP code example of wiz-develop / php-value-object
1. Go to this page and download the library: Download wiz-develop/php-value-object 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/ */
wiz-develop / php-value-object example snippets
use WizDevelop\PhpValueObject\String\StringValue;
use WizDevelop\PhpValueObject\ValueObjectMeta;
#[ValueObjectMeta(name: '商品コード')]
final readonly class ProductCode extends StringValue
{
protected static function minLength(): int { return 5; }
protected static function maxLength(): int { return 5; }
protected static function regex(): string { return '/^P[0-9]{4}$/'; }
}
$code = ProductCode::from('P1234');
use WizDevelop\PhpMonad\Result;
$result = ProductCode::tryFrom('invalid');
$code = $result
->map(fn($code) => $code->value())
->unwrapOr('デフォルト');