-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
54 lines (42 loc) · 1.19 KB
/
example.php
File metadata and controls
54 lines (42 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Marwa\Support\{Arr, Date, File, Helper, Obj, Str};
// String examples
$slug = Str::slug('Hello World!'); // "hello-world"
$limited = Str::limit('This is a long string', 10); // "This is a..."
// Array examples
$array = ['user' => ['name' => 'John', 'age' => 30]];
$name = Arr::get($array, 'user.name'); // "John"
// File system examples
File::put('test.txt', 'Hello World');
$content = File::get('test.txt'); // "Hello World"
// Object examples
$object = new \stdClass();
$object->user = new \stdClass();
$object->user->name = 'John';
$name = Obj::get($object, 'user.name'); // "John"
// Date examples
$now = Date::now();
$tomorrow = Date::addDays($now, 1);
// Helper examples
Helper::dd($slug, $limited, $name);
// Tap example
$result = Helper::tap($value, function ($v) {
Logger::debug('Current value', $v);
});
// Pipe example
$processed = Helper::pipe(
' hello ',
[
fn ($s) => trim($s),
fn ($s) => strtoupper($s),
fn ($s) => Str::slug($s)
]
);
// With example
$config = Helper::with(
Helper::dataGet($settings, 'app.config'),
fn ($c) => json_decode($c, true),
['default' => 'value']
);