nitier/datatype

This package is abandoned and no longer maintained. No replacement package was suggested.

Data type helpers

0.1.0 2024-11-28 19:42 UTC

This package is auto-updated.

Last update: 2024-12-28 21:13:47 UTC


README

A PHP library for handling various data types with built-in validation for format, range, and nullability.

๐Ÿ“ฆ Installation

Requires PHP 8.0+. Install the package via Composer:

composer require nitier/datatype

๐Ÿ›  Supported Data Types

  • Text Types: TextType, VarcharType, TinyTextType, MediumTextType, LongTextType
  • Temporal Types: DateType, TimeType, DatetimeType, TimestampType, YearType
  • Numeric Types: IntType, FloatType, DecimalType, TinyIntType, MediumIntType, SmallIntType

๐Ÿš€ Usage Examples

Text Types

VarcharType

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
}

Temporal Types

DateType

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
}

๐Ÿ“‚ Project Structure

DataType/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ Type/
โ”‚       โ”œโ”€โ”€ TextType.php
โ”‚       โ”œโ”€โ”€ VarcharType.php
โ”‚       โ”œโ”€โ”€ DateType.php
โ”‚       โ”œโ”€โ”€ DatetimeType.php
โ”‚       โ””โ”€โ”€ ...
โ”œโ”€โ”€ tests/
โ””โ”€โ”€ composer.json

๐Ÿงช Running Tests

Ensure PHPUnit is installed:

composer require --dev phpunit/phpunit

Run tests:

composer test

๐Ÿ“ License

Licensed under the MIT License. See LICENSE for details.

๐Ÿค Contributions

Contributions are welcome via pull requests or issues. Let's make this library better together!