idevlab / essential
All the methods and tools useful for the development of the various idevlab projects.
1.8.0
2022-10-31 08:50 UTC
Requires
- php: ^8.1
- ext-mbstring: *
- idevlab/helpers: ^1.0
This package is auto-updated.
Last update: 2025-05-29 01:56:44 UTC
README
Many PHP functions used in my projects, that you can use in your developments.
Authors
Installation
Install in your project with composer.
composer require idevlab/essential
Methods
Array
i_array_merge(array...$arrays): array
Merge array
/** @var array $foo */
$foo = ['one' => 1, 'three' => 3];
/** @var array $bar */
$bar = ['two' => 2];
$foo = i_array_merge($foo, $bar); // ['one' => 1, 'three' => 3, 'two' => 2]}
String
str_to_snake_case(string $string): string
Format a string in snake_case.
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_snake_case($foo); // test_de_chaine
str_to_pascal_case(string $string): string
Format a string in PascalCase.
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_pascal_case($foo); // TestDeChaine
str_to_skewer_case(string $string): string
Format a string in skewer-case.
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_skewer_case($foo); // test-de-chaine
str_to_no_case(string $string): string
Format a string in no case.
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_no_case($foo); // test de chaine
str_to_case(string $string): string
Format a string in no case.
/** @var string $foo */
$foo = 'Test_DeChaine';
// NO : 0
// PASCAL : 1
// CAMEL : 2
// SKEWER : 3
// SNAKE : 4
$foo = str_to_case($foo,1); // test de chaine
JSON
i_json_serialize(object $object, string ...$excludes): array
Serialize a object you.
class Foo {
public string $bar = 'purple';
public string $other = 'exclude value';
}
$foo = new Foo();
$foo = i_json_serialize($foo,['other']); // { 'bar' => 'purple' }
Date
i_random_date(DateTime $start, ?DateTime $end = new DateTime('now')): DateTime
Find a random date between $start and $end