Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rikudousage/scalar-objects
https://github.com/rikudousage/scalar-objects
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/rikudousage/scalar-objects
- Owner: RikudouSage
- Created: 2016-07-19T15:39:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-27T15:21:44.000Z (about 5 years ago)
- Last Synced: 2024-04-22T15:21:01.936Z (7 months ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scalar types as objects for php
This php library requires php extension from .
## Installation
Run `composer require rikudou/scalar-objects`.
## Usage
The handlers are automatically registered when you include composer
autoload. That means you can use it immediately with no configuration.Since IDEs don't understand the syntax, there are typehint classes
available to help you.## Examples
```php
isInt()); // bool(true)
var_dump($num2->isString()); // bool(true)
var_dump($num2->isNumeric()); // bool(true)
var_dump($num2->isNumber()); // bool(false) - isNumber() returns true only for int and floatvar_dump($num1->toString()->length()); // int(1)
/** @var StringTypehint $string */
$string = "This is a test string";var_dump($string->length()); // int(21);
var_dump($string->capitalize()); // string(21) "This Is A Test String"
var_dump($string->caseInsensitiveCompare("this Is a TESt STRInG")); // int(0)
var_dump($string->toUpper()); // string(21) "THIS IS A TEST STRING"
var_dump($string->toLower()); //string(21) "this is a test string"```
As you can see, you can use the scalar values as objects.
But you can still use them as regular scalar types.
```php
abs()); // int(15)
var_dump($int1 + $int2); // int(-5)
var_dump($int1 + $int2 + $int3->toInt()->abs()); // int(10)```