Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Helpers
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Modulus
Helpers
Commits
e01f526a
Commit
e01f526a
authored
Apr 02, 2020
by
Sylvain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
Update README.md Update README.md
parent
797f5873
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
285 additions
and
1 deletion
+285
-1
README.md
README.md
+285
-1
No files found.
README.md
View file @
e01f526a
# Helpers
\ No newline at end of file
# Modulus Helpers
Different helpers for Laravel and Modulus
## Required
-
Composer
-
PHP >= 7.2
-
Laravel >= 5.8
## Installation
Require this package with composer.
```
shell
composer require goldenscarab/modulus-helpers
```
Laravel 5.8 uses autoload files, so doesn't require you to manually add the ServiceProvider.
## Available functions
**_Convert_**
-
[
carbonize
](
#carbonize
)
-
[
collectize
](
#collectize
)
-
[
objectize
](
#objectize
)
-
[
csv_to_collection
](
#csv_to_collection
)
-
[
array_to_string
](
#array_to_string
)
-
[
string_to_float
](
#string_to_float
)
**_Html_**
-
[
published_html
](
#published_html
)
-
[
boolean_html
](
#boolean_html
)
**_Image_**
-
[
optimize_image
](
#optimize_image
)
-
[
make_thumb_image
](
#make_thumb_image
)
**_List_**
-
[
col_sort
](
#col_sort
)
-
[
pos_sort
](
#pos_sort
)
**_Str_**
-
[
str_singularize_fr
](
#str_singularize_fr
)
-
[
str_indent
](
#str_indent
)
-
[
str_args_to_array
](
#str_args_to_array
)
**_Time_**
-
[
sum_times
](
#sum_times
)
-
[
gte_time
](
#gte_time
)
**_Url_**
-
[
current_query_to_array
](
#current_query_to_array
)
-
[
current_query_to_string
](
#current_query_to_string
)
-
[
current_route_belongs
](
#current_route_belongs
)
**_Divers_**
-
[
calc_increase_percent
](
#calc_increase_percent
)
-
[
mixte_get
](
#mixte_get
)
-
[
mixte_get_multi
](
#mixte_get_multi
)
## Usage
#### `carbonize()`
La fonction
`carbonize()`
convertie recursivement les dates fr en Instance
`Carbon`
à l'intérieur d'une collection
```
php
$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
```
php
$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`
```
php
$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*
```
php
$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
```
php
$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
```
php
$float
=
string_to_float
(
'2,45'
);
// 2.45
$float
=
string_to_float
(
'42.745'
);
// 42.745
```
#### `published_html()`
La fonction
`published_html()`
retourne le html correspondant à un état publié
```
php
$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
```
php
$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
```
php
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
```
php
$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
```
php
$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
```
php
$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)
```
php
$string
=
str_singularize_fr
(
"chevaux"
);
// "cheval"
```
#### `str_indent()`
La fonction
`str_indent()`
indente une chaine de caractères
```
php
$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
```
php
$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é
```
php
$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 à)
```
php
$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
```
php
$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
```
php
$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
```
php
$belongs
=
current_route_belongs
(
'page.list'
);
// false
```
#### `calc_increase_percent()`
La fonction
`calc_increase_percent()`
calcul le pourcentage d'accroissement entre 2 valeurs
```
php
$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
```
php
$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
```
php
$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"]
```
## Security
If you discover any security related issues, please email contact@goldenscarab.fr instead of using the issue tracker.
## Credits
-
[
Sylvain CARRE
](
https://git.goldenscarab.fr/modulus
)
## License
The MIT License (MIT). Please see
[
License File
](
LICENSE.md
)
for more information.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment