Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parsilver/php-types-guesser
คาดเดา และตรวจสอบชนิดของค่าที่ได้รับมา
https://github.com/parsilver/php-types-guesser
Last synced: 3 days ago
JSON representation
คาดเดา และตรวจสอบชนิดของค่าที่ได้รับมา
- Host: GitHub
- URL: https://github.com/parsilver/php-types-guesser
- Owner: parsilver
- Created: 2020-10-09T06:52:16.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-12T17:45:28.000Z (over 3 years ago)
- Last Synced: 2024-05-17T02:42:59.982Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-types-guesser
This package will helpful cast your value or guess your value type[![Build Status](https://travis-ci.com/parsilver/php-types-guesser.svg?branch=master)](https://travis-ci.com/parsilver/php-types-guesser)
### Required
```json
{
"php": "^7.3||^8.0"
}
```### Installation
```
composer require farzai/php-types-guesser
```### Example
##### String type
```php
use Farzai\Guesser\TypeGuesser;$guesser = TypeGuesser::of("This is message");
// Print "This is message"
echo $guesser;$guesser->isString() === true;
```##### Array type
```php
use Farzai\Guesser\TypeGuesser;$guesser = TypeGuesser::of([1, 2]);
// Print "[1, 2]"
echo $guesser;$guesser->isArray() === true;
$guesser->isJson() === false;
```##### JSON Type
```php
use Farzai\Guesser\TypeGuesser;$guesser = TypeGuesser::of("[1, 2]");
echo $guesser; // Print "[1, 2]"
$guesser->isArray() === true;
$guesser->isJson() === true;
$guesser->isString() === true;
```##### Boolean Type
```php
use Farzai\Guesser\TypeGuesser;// Try to enter string value
$guesser = TypeGuesser::of("true");
$guesser->isBoolean() === true;
$guesser->getValue() === true;// Boolean type
$guesser = TypeGuesser::of(true);
$guesser->isBoolean() === true;
$guesser->getValue() === true;
```##### Numeric Type
```php
use Farzai\Guesser\TypeGuesser;$guesser = TypeGuesser::of("1");
$guesser->isNumeric() === true;
$guesser->isInteger() === true;
$guesser->isFloat() === false;
$guesser->getValue() === 1;$guesser = TypeGuesser::of(1.2);
$guesser->isNumeric() === true;
$guesser->isInteger() === false;
$guesser->isFloat() === true;
$guesser->getValue() === 1.2;$guesser = TypeGuesser::of("2.1");
$guesser->isNumeric() === true;
$guesser->isInteger() === false;
$guesser->isFloat() === true;
$guesser->getValue() === 2.1;
```