Skip to content

Commit 6377814

Browse files
update
1 parent ffca0fd commit 6377814

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,79 @@ Tame()->formatNumberToNearestThousand(1500000);
389389
- The Core Class For String Manipulations
390390
- It's helper class can be called, using -- `TameStr()`
391391

392+
```php
393+
use Tamedevelopers\Support\Str;
394+
395+
// Quick examples
396+
Str::replaceFirst('foo', 'bar', 'foofoo'); // 'barfoo'
397+
Str::words('The quick brown fox jumps', 3); // 'The quick brown...'
398+
Str::ascii('Jürgen'); // 'Jurgen'
399+
Str::padLeft('7', 3, '0'); // '007'
400+
Str::is('user/*', 'user/42'); // true
401+
Str::exceptArray(['a'=>1,'b'=>2], 'a'); // ['b'=>2]
402+
Str::convertArrayCase(['Name' => ['Age' => 1]], 'lower', 'upper'); // ['name' => ['age' => 1]]
403+
```
404+
405+
## File
406+
- The Core File utilities (read, write, copy, move, info).
407+
- Class: `Tamedevelopers\Support\Capsule\File`
408+
409+
```php
410+
use Tamedevelopers\Support\Capsule\File;
411+
412+
// Create directory
413+
File::makeDirectory(storage_path('logs'));
414+
415+
// Write & read
416+
File::put(storage_path('logs/app.log'), 'Hello');
417+
$content = File::get(storage_path('logs/app.log')); // 'Hello'
418+
419+
// Info
420+
File::exists(storage_path('logs/app.log')); // true
421+
File::size(storage_path('logs/app.log')); // int bytes
422+
File::extension(storage_path('logs/app.log')); // 'log'
423+
File::lastModified(storage_path('logs/app.log')); // timestamp
424+
425+
// Move/Copy/Delete
426+
File::copy(storage_path('logs/app.log'), storage_path('logs/app_copy.log'));
427+
File::move(storage_path('logs/app_copy.log'), storage_path('logs/app_moved.log'));
428+
File::delete(storage_path('logs/app_moved.log'));
429+
430+
// List files
431+
$files = File::files(storage_path('logs')); // array of SplFileInfo
432+
```
433+
434+
## Collection
435+
- Lightweight collection utilities.
436+
- Class: `Tamedevelopers\Support\Collections\Collection`
437+
438+
```php
439+
use Tamedevelopers\Support\Collections\Collection;
440+
441+
$users = new Collection([
442+
['id' => 1, 'name' => 'Ada'],
443+
['id' => 2, 'name' => 'Ben'],
444+
['id' => 3, 'name' => 'Cee'],
445+
]);
446+
447+
$users->isEmpty(); // false
448+
$users->count(); // 3
449+
$users->keys()->all(); // [0,1,2]
450+
$users->values()->all(); // same as original but reindexed
451+
452+
// Keep only specific keys from an associative array
453+
$profile = new Collection(['id'=>1,'name'=>'Ada','role'=>'admin']);
454+
$profile->only('id', 'name')->all(); // ['id'=>1,'name'=>'Ada']
455+
$profile->except('role')->all(); // ['id'=>1,'name'=>'Ada']
456+
457+
// Filtering
458+
$even = (new Collection([1,2,3,4]))->filter(fn($v) => $v % 2 === 0)->all(); // [2,4]
459+
460+
// Merge/Chunk/Reverse
461+
(new Collection([1,2]))->merge([3,4])->all(); // [1,2,3,4]
462+
(new Collection(range(1,6)))->chunk(2)->all(); // [[1,2],[3,4],[5,6]]
463+
(new Collection([1,2,3]))->reverse()->all(); // [3,2,1]
392464
```
393-
Tamedevelopers\Support\Str
394-
```
395465

396466
## Mail
397467
- The Core Class/Wrapper For `PHPMailer`

0 commit comments

Comments
 (0)