From a6bc1acf31ab82018dfc601bdf5f8d4e29ab8fe4 Mon Sep 17 00:00:00 2001 From: Hicham SADDEK Date: Wed, 17 Feb 2021 03:24:30 +0100 Subject: [PATCH] Adding documentation --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4a9273..69daff5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,55 @@ -# helpers +# Milebits Helpers A new laravel package including helper functions for every Milebits package. +# How to install +``` +composer require milebits/helpers +``` +# Available methods +#### Check if a constant exists within a class: +``` +constExists($class, $constant): bool +``` +- Example: `constExists(App\Models\User::class, "CREATED_AT")` will result in `true` +- Example: `constExists($user, "CREATED_AT")` will result in `true` +- Example: `constExists(App\Models\User::class, "RANDOM_VAR")` will result in `false` +- Example: `constExists($user, "RANDOM_VAR")` will result in `false` +#### Get the value of a constant or get default: +``` +constVal($class, $constant, $default): mixed +``` +- Example: `constVal(App\Models\User::class, "CREATED_AT", "JAJA")` will result in `created_at` +- Example: `constVal($user, "CREATED_AT", "JAJA")` will result in `created_at` +- Example: `constVal(App\Models\User::class, "RANDOM_VAR", "JAJA")` will result in `JAJA` +- Example: `constVal($user, "RANDOM_VAR", "JAJA")` will result in `JAJA` +- Example: `constVal(App\Models\User::class, "RANDOM_VAR")` will result in `null` +- Example: `constVal($user, "RANDOM_VAR")` will result in `null` +#### Get the value of a static property or get default: +``` +staticPropVal($class, $name, $default): mixed +``` +- Example: `staticPropVal(App\Models\User::class, "STATICPROP", "JAJA")` will result in the value of the property requested. +- Example: `staticPropVal($user, "STATICPROP", "JAJA")` will result in the value of the property requested. +- Example: `staticPropVal(App\Models\User::class, "NONSTATIC", "JAJA")` will result in `JAJA` +- Example: `staticPropVal($user, "NONSTATIC", "JAJA")` will result in `JAJA` +- Example: `staticPropVal(App\Models\User::class, "NONSTATIC")` will result in `null` +- Example: `staticPropVal($user, "NONSTATIC")` will result in `null` + +#### Get the value of a property or get default: +``` +propVal($class, $name, $default): mixed +``` +- Example: `propVal(App\Models\User::class, "prop", "JAJA")` will result in the value of the property requested. +- Example: `propVal($user, "prop", "JAJA")` will result in the value of the property requested. +- Example: `propVal(App\Models\User::class, "non_prop", "JAJA")` will result in `JAJA` +- Example: `propVal($user, "non_prop", "JAJA")` will result in `JAJA` +- Example: `propVal(App\Models\User::class, "non_prop")` will result in `null` +- Example: `propVal($user, "non_prop")` will result in `null` + +#### Check if a class has a certain trait +``` +hasTrait($object, $trait): bool +``` +- Example: `hasTrait($user, SoftDeletes::class)` will return true if the user has the SoftDeletes Trait. +- Example: `hasTrait($user, HasPosts::class)` will return true if the user hasn't got the HasPosts Trait +- Example: `hasTrait(App\Models\User, SoftDeletes::class)` will return true if the user class has the SoftDeletes Trait. +- Example: `hasTrait(App\Models\User, HasPosts::class)` will return true if the user class hasn't got the HasPosts Trait \ No newline at end of file