PHP code example of nitier / datatype

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

    

nitier / datatype example snippets


use Nitier\DataType\Type\VarcharType;

$varchar = new VarcharType(length: 100);
$varchar->setValue('Example text');
echo $varchar->getValue(); // Output: Example text

try {
    $varchar->setValue(str_repeat('A', 101)); 
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage(); // Error: length exceeded
}

use Nitier\DataType\Type\DateType;

$date = new DateType();
$date->setValue('2023-11-28');
echo $date->getValue(); // Output: 2023-11-28

try {
    $date->setValue('28.11.2023');
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage(); // Error: invalid format
}

DataType/
├── src/
│   └── Type/
│       ├── TextType.php
│       ├── VarcharType.php
│       ├── DateType.php
│       ├── DatetimeType.php
│       └── ...
├── tests/
└── composer.json