generated from open-southeners/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e19f94
commit 608c5a6
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
* [Helpers](function-helpers.md) | ||
* [Commands](commands.md) | ||
* [Middleware](middleware.md) | ||
* [Facades](facades.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
description: This package extends Laravel's framework facades with new useful methods. | ||
--- | ||
|
||
# Facades | ||
|
||
### Arr | ||
|
||
#### exceptValues | ||
|
||
Filter array shorthand by just excluding the values passed as second argument. | ||
|
||
```php | ||
Arr::exceptValues([ | ||
"hello" => "world", | ||
"foo" => "bar" | ||
], "bar"); | ||
|
||
// ["hello" => "world"] | ||
``` | ||
|
||
#### onlyValues | ||
|
||
Filter array shorthand by just including the values passed as second argument. | ||
|
||
```php | ||
Arr::onlyValues([ | ||
"hello" => "world", | ||
"foo" => "bar" | ||
], "world"); | ||
|
||
// ["hello" => "world"] | ||
``` | ||
|
||
#### query | ||
|
||
Write a URL query string from an array. | ||
|
||
```php | ||
Arr::query([ | ||
"q" => "this", | ||
"param2" => "value" | ||
], "world"); | ||
|
||
// "?q=this¶m2=value" | ||
``` | ||
|
||
### Collection | ||
|
||
#### toCsv | ||
|
||
Converts collection of items to CSV with its headers. | ||
|
||
```php | ||
collect([ | ||
[ | ||
"name" => "Ruben Robles", | ||
"role" => "Admin" | ||
], | ||
[ | ||
"name" => "Taylor Otwell", | ||
"role" => "Admin" | ||
] | ||
])->toCsv(); // "name,role\nRuben Robles,Admin\nTaylor Otwell,Admin" | ||
``` | ||
|
||
#### templateJoin | ||
|
||
Join items of the collection using a template substitution. | ||
|
||
```php | ||
collect([ | ||
[ | ||
"name" => "Ruben Robles", | ||
"email" => "[email protected]" | ||
], | ||
[ | ||
"name" => "Taylor Otwell", | ||
"email" => "[email protected]" | ||
] | ||
])->templateJoin(":name (:email)"); // "Ruben Robles ([email protected]), Taylor Otwell ([email protected])" | ||
``` | ||
|
||
### Number | ||
|
||
#### toShort | ||
|
||
Get shorter version of a big number if possible. | ||
|
||
```php | ||
Number::toShort(1000); // "1K" | ||
Number::toShort(2200); // "2,2K" | ||
``` | ||
|
||
#### toByteUnit | ||
|
||
Get byte unit version of a number. | ||
|
||
```php | ||
Number::toByteUnit(1000)->toKB(); // "1.00 KB" | ||
``` | ||
|
||
## Storage | ||
|
||
#### humanSize | ||
|
||
Get human readable file size at given path. | ||
|
||
```php | ||
use OpenSoutheners\ByteUnitConverter\MetricSystem; | ||
|
||
Storage::humanSize("path/file.png"); // "124.00 KB" | ||
Storage::humanSize("path/file.png", MetricSystem::KiB); // "121.09 KiB" | ||
``` | ||
|
||
### Str | ||
|
||
#### parseQuery | ||
|
||
Parse a URL query string into an array. | ||
|
||
```php | ||
Str::parseQuery("?q=search¶m1=value"); // ["q" => "search", "param1" => "value"] | ||
|
||
Str::of("?q=search¶m1=value")->parseQuery(); | ||
``` | ||
|
||
#### isJsonStructure | ||
|
||
Check if string contains a valid JSON structure. | ||
|
||
```php | ||
Str::isJsonStructure('{"foo": "bar"}'); // true | ||
|
||
Str::of('"bar"')->isJsonStructure(); // false | ||
``` | ||
|
||
#### emailDomain | ||
|
||
Get domain part from email address. | ||
|
||
```php | ||
Str::emailDomain("[email protected]"); // "example.com" | ||
|
||
Str::of("[email protected]")->emailDomain(); // "laravel.com" | ||
``` | ||
|