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
Requires
- php: >=8.3
Requires (Dev)
- overtrue/phplint: ^9.5
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.4
- squizlabs/php_codesniffer: ^3.11
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!