goldenscarab / modulus-helpers
Different helpers for Laravel and Modulus
Requires
- php: >=7.1
README
Different helpers for Laravel and Modulus
Required
- Composer
- PHP >= 7.2
- Laravel >= 5.8
Installation
Require this package with composer.
composer require goldenscarab/modulus-helpers
Laravel 5.8 uses autoload files, so doesn't require you to manually add the ServiceProvider.
Available functions
Convert
Html
Image
List
Str
Array
Time
Url
Divers
Usage
carbonize()
La fonction carbonize()
convertie recursivement les dates fr en Instance Carbon
à l'intérieur d'une collection
$collection = collect(['id' => 23, 'date' => '12/06/1980']);
$collection_carbonized = carbonize($collection);
// Mixed::class([id => 23, date => \Carbon\Carbon::class])
collectize()
La fonction collectize()
converti les tableaux en Instance de Collection
à l'intérieur d'une collection
$collection = collect(['id' => 23, 'collect' => [1, 2, 3, 4]]);
$collection_collectized = collectize($collection);
// Mixed::class([id => 23, collect => Collection::class([1, 2, 3, 4])])
objectize()
La fonction objectize()
converti les tableaux associatif d'une collection en stdClass
$collection = collect(['id' => 23, 'object' => ['key' => 'foo', 'value' => 'far']]);
$collection_objectized = objectize($collection);
// Mixed::class([id => 23, object => stdClass($key='foo', $value='far')])
csv_to_collection()
La fonction csv_to_collection()
retourne une collection de stdClass
à partir d'une chaine de caractère de type CSV
$csv = col1, col2, col3 . PHP_EOL;
$csv .= value1, value2, value3;
$collection_objects = csv_to_collection($csv, ',');
// Collection::class([col1 => value1, col2 => value2, col3 => value3])
array_to_string()
La fonction array_to_string()
converti un tableau en string
$array = ['id', 'name', 'value'];
$string = array_to_string($array);
// "['id', 'name', 'value']"
string_to_float()
La fonction string_to_float()
parse une chaine de caractère en nombre flottant
$float = string_to_float('2,45');
// 2.45
$float = string_to_float('42.745');
// 42.745
float_to_money()
La fonction float_to_money
converti un flottant en nombre monétaire avec sigle €
$money = float_to_money(1234.56);
// 1 234,56 €
published_html()
La fonction published_html()
retourne le html correspondant à un état publié
$html = published_html(0);
// '<i class="fa fa-eye-slash text-warning"></i>'
$html = published_html(1);
// '<i class="fa fa-globe text-success"></i>'
boolean_html()
La fonction boolean_html()
retourne le html correspondant à un état boolean
$html = boolean_html(false);
// '<i class="fa fa-times text-danger"></i>'
$html = boolean_html(true);
// '<i class="fa fa-check text-success"></i>'
optimize_image()
La fonction optimize_image()
converti et optimise une image depuis une chemin de fichier image
optimize_image('path/to/image.png', $width = 1920, $height = null, $type = 'jpg', $quality = 80);
make_thumb_image()
La fonction make_thumb_image()
converti en miniature une image depuis une chemin de fichier image
$path_image_thumb = make_thumb_image('path/to/image.png', $width = 1920, $height = null, $type = 'jpg', $quality = 80);
// "path/to/image_thumb.jpg"
col_sort()
La fonction col_sort()
affiche un icone de tri de colonne dans une vue liste
$html = col_sort('name');
// "<span class="sort desc ml-1"><i class="fa fa-sort-amount-desc"></i></span>"
pos_sort()
La fonction pos_sort()
affiche un visuel pour tri des colonnes « position » en drag & drop
$html = pos_sort($item_id = 1, $item_position = 9);
// '<div class="position-wrap">'
// '...'
// '</div>'
str_singularize_fr()
La fonction str_singularize_fr()
converti une chaine de caractères pluriel en singulier (Francais)
$string = str_singularize_fr("chevaux");
// "cheval"
str_indent()
La fonction str_indent()
indente une chaine de caractères
$string = '<div>';
$string .= ' <p>lorem</p>';
$string .= '</div>';
$string = str_indent($string, 1);
// " <div>"
// " <p>lorem</p>"
// " </div>"
str_args_to_array()
La fonction str_args_to_array()
converti une chaine d'arguments en tableau d'arguments en respectant le typage
$array = str_args_to_array("lorem, 2, 45.78, true, 2,47, foo");
// array('lorem', 2, 45.78, true, '2.47', 'foo');
sum_times()
La fonction sum_times()
additionne tableau de string au format hh:mm:ss
pour en afficher un total formaté
$total = sum_times(['12:45:30', '6:12:10'], $segment = 3);
// "18:57:40"
gte_time()
La fonction gte_time()
compare un string de type horaire avec un autre (plus grand ou égal à)
$total = gte_time("12:50:10", "14:20:05");
// false
current_query_to_array()
La fonction current_query_to_array()
retourne un tableau avec les paramètres de l'url courante
$query = current_query_to_array();
// ['page' => 1254, 'order' => 'desc', 'token' => null]
current_query_to_string()
La fonction current_query_to_string()
retourne paramètres de l'url courante sans ses paramètres vides
$query = current_query_to_string();
// ?page=1254&order=desc'
current_route_belongs()
La fonction current_route_belongs()
vérifie si l'url courante appartient (enfant compris) à une route
$belongs = current_route_belongs('page.list');
// false
current_parent_route_belongs()
La fonction current_parent_route_belongs()
vérifie si l'url courante appartient (enfant compris) à une route parente (segment -1)
$belongs = current_parent_route_belongs('page.category.list');
// false
calc_increase_percent()
La fonction calc_increase_percent()
calcul le pourcentage d'accroissement entre 2 valeurs
$increase = calc_increase_percent(130, 160);
// 23.076923077
mixte_get()
La fonction mixte_get()
récupération avancée de contenu depuis une source Mixte, en utilisant la notation «.»
Possibilité d'appeler des méthodes en leur passant des arguments
$data = ['products' => ['desk' => ['price' => 100]]];
$price = mixte_get($data, 'products.desk.price', $default = null);
// 100
mixte_get($collection, "where('name', 'toto').first()");
// stdClass::class(name='toto')
mixte_get_multi()
La fonction mixte_get_multi()
récupère un tableau de données depuis une source à partir d'un tableau de clés
Possibilité d'appeler des méthodes en leur passant des arguments
$source = [
'content' => [
'key' => "my-key",
'value' => "my-value"
]
]
$getters = ['content.key', 'content.value'];
$price = mixte_get_multi($source, $getters, $default = null);
// ["my-key", "my-value"]
public_folder_to_urls()
La fonction public_folder_to_urls()
récupère une colelction d'url de fichiers à partir d'un chemin public relatif
$urls = public_folder_to_urls("upload/folder/");
// Collection(['http://domain.tld/upload/folder/images1.png', 'http://domain.tld/upload/folder/images2.png'])
is_indexed_array()
La fonction is_indexed_array()
teste un tableau pour savoir s'il est de type indexé ou associatif
is_indexed_array(['foo', 'bar']);
// true
is_indexed_array(['foo' => 'bar', 'boo' => 'tite']);
// false
array_contains()
La fonction array_contains()
teste un tableau contient plusieurs valeurs spécifiées
array_contains(['foo', 'boo'], ['foo', 'bar', 'boo']);
// true
array_contains(['foo', 'tuu'], ['foo', 'bar', 'boo']);
// false
time_to_float()
La fonction time_to_float()
convertie une chaine de caractères de type heure HH:MM:SS en flottant
time_to_float('1:23:45');
// 1.3958333333333
Security
If you discover any security related issues, please email contact@goldenscarab.fr instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.