idevlab/helpers

Helpers for the idevlab project

1.0.2 2022-10-30 20:33 UTC

This package is auto-updated.

Last update: 2024-11-29 06:41:58 UTC


README

Auteur Release Codacy grade License Téléchargement

Many PHP functions used in my projects, that you can use in your developments.

Authors

@fsinama

Installation

Install in your project with composer.

  composer require Idevlab/Helpers

Methods

ArrayHelper

::merge(array...$arrays): array

Merge array

/** @var array $foo */
$foo = ['one' => 1, 'three' => 3];

/** @var array $bar */
$bar = ['two' => 2];

$foo = ArrayHelper::merge($foo, $bar); // ['one' => 1, 'three' => 3, 'two' => 2]}

StringHelper

::toSnakeCase(string $string): string

Format a string in snake_case.

/** @var string $foo */
$foo = 'Test_DeChaine';

$foo = StringHelper::toSnakeCase($foo); // test_de_chaine

::toPascalCase(string $string): string

Format a string in PascalCase.

/** @var string $foo */
$foo = 'Test_DeChaine';

$foo = StringHelper::toPascalCase($foo); // TestDeChaine

::toSkewerCase(string $string): string

Format a string in skewer-case.

/** @var string $foo */
$foo = 'Test_DeChaine';

$foo = StringHelper::toSkewerCase($foo); // test-de-chaine

::toNoCase(string $string): string

Format a string in no case.

/** @var string $foo */
$foo = 'Test_DeChaine';

$foo = StringHelper::toNoCase($foo); // test de chaine

::toCase(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 = StringHelper::toCase($foo,1); // test de chaine

JsonHelper

::jsonSerialize(object $object, string ...$excludes): array

Serialize a object you.


class Foo {
    public string $bar = 'purple';
    public string $other = 'exclude value';
}

$foo = new Foo();

$foo = JsonHelper::jsonSerialize($foo,['other']); // { 'bar' => 'purple' }

DateHelper

::randomDateForRange(DateTime $start, ?DateTime $end = new DateTime('now')): DateTime

Find a random date between $start and $end

License

GPL3 or later