2017 © Pedro Peláez
 

library laravel-helpers

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

image

mojopollo/laravel-helpers

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  • Thursday, January 7, 2016
  • by mojopollo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 553 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

Mojo's Laravel Helpers

Build Status Latest Stable Version Latest Unstable Version License Total Downloads, (*1)

Mojo's Laravel Helpers: A suite of various complimentary helpers for the Laravel framework and PHP 5.4/5.5/5.6/7.0. Some of these helpers are based on code found in Stackoverflow, look for the @see properties for references., (*2)

, (*3)

Installation

Step 1: Add package via composer

Add this package to your composer.json file with the following command, (*4)

composer require mojopollo/laravel-helpers

Step 2: Update laravel 5.x config/app.php file

Add the following into the providers array:, (*5)

Mojopollo\Helpers\StringHelperServiceProvider::class,
Mojopollo\Helpers\ArrayHelperServiceProvider::class,
Mojopollo\Helpers\DateTimeHelperServiceProvider::class,
Mojopollo\Helpers\FileHelperServiceProvider::class,

Add the following into the aliases array:, (*6)

'StringHelper'   => Mojopollo\Helpers\Facades\StringHelper::class,
'ArrayHelper'    => Mojopollo\Helpers\Facades\ArrayHelper::class,
'DateTimeHelper' => Mojopollo\Helpers\Facades\DateTimeHelper::class,
'FileHelper'     => Mojopollo\Helpers\Facades\FileHelper::class,

, (*7)

Usage

To enable any of the helpers classes inside a controller, invoke the use keyword:, (*8)

<?php namespace App\Http\Controllers;

use ArrayHelper;
use FileHelper;
...

You can now call any of helper methods via their facades:, (*9)

StringHelper::replaceFirstMatch('one two three four five six', 3)

FileHelper::directoryFiles('/directory-path')

...

If you do not want to utilize the use keyword, you can alternatively use a blackslash\ when calling the helpers:, (*10)

\StringHelper::replaceFirstMatch('one two three four five six', 3)

\FileHelper::directoryFiles('/directory-path')

...

, (*11)

StringHelper

camelCase

Convert a value to camel case, (*12)

string camelCase(string $value)
StringHelper::camelCase('mojo_pollo');

// mojoPollo



#### snakeCase Convert a value to snake case ```php string snakeCase(string $value [, string $delimiter = '_'])
```php StringHelper::snakeCase('mojoPollo'); // mojo_pollo

#### replaceFirstMatch str_replace() for replacing just the first match in a string search ```php string replaceFirstMatch(string $search, string $replace, string $subject)
```php StringHelper::replaceFirstMatch('mojo', 'jojo', 'mojo is a pollo and mojo'); // jojo is a pollo and mojo

#### limitByWords Returns a string limited by the word count specified ```php string limitByWords(string $str [, int $wordCount = 10])
```php StringHelper::limitByWords('one two three four five six', 3); // one two three

<a id="helper-array"></a> ## ArrayHelper #### random Get a random element from the array supplied ```php mixed random(array $array)
```php ArrayHelper::random(['one', 'two', 'three']); // two

#### morphKeys Will camelize all keys found in a array or multi dimensional array ```php array morphKeys(array $originalArray [, $morphTo = 'camel'])
```php ArrayHelper::morphKeys([ 'user' => [ 'first_name' => 'mojo', 'attributes' => [ 'second_key' => 'second value', ], ], ], 'camel'); // [ // 'user' => [ // 'firstName' => 'mojo', // 'attributes' => [ // 'secondKey' => 'second value', // ], // ], // ]

#### castValues Will cast '123' as int, 'true' as the boolean true, etc ```php array castValues(array $originalArray)
```php ArrayHelper::castValues([ 'value1' => 'true', 'value2' => 'false', 'value3' => '123', 'value4' => '{"mojo": "pollo"}', ]); // [ // 'value1' => true, // 'value2' => false, // 'value3' => 123, // 'value4' => ['mojo' => 'pollo'], // ]

#### sortByPriority Re-orders an array by moving elements to the top of the array based on a pre-defined array stating which elements to move to top of array. Note: when $strictMatch is set to false, the match will not take into account type and case sensitivity ```php array sortByPriority(array $originalArray, array $priority [, $strictMatch = true])
```php $originalArray = [ [ 'name' => 'White Castle', 'city' => 'Las Vegas', 'zip' => '89109', ], [ 'name' => 'Burger Town', 'city' => 'Sherman Oaks', 'zip' => '91403', ], [ 'name' => 'Krabby Patty', 'city' => 'Walking the Plankton', 'zip' => '00000', ], [ 'name' => 'Uber Burger', 'city' => 'Little Rock', 'zip' => '72201', ], ]; $priority = [ [ 'city' => 'Walking the Plankton' ], [ 'name' => 'Burger Town' ], ]; ArrayHelper::sortByPriority($originalArray, $priority); // [ // [ // 'name' => 'Krabby Patty', // 'city' => 'Walking the Plankton', // 'zip' => '00000', // ], // [ // 'name' => 'Burger Town', // 'city' => 'Sherman Oaks', // 'zip' => '91403', // ], // [ // 'name' => 'White Castle', // 'city' => 'Las Vegas', // 'zip' => '89109', // ], // [ // 'name' => 'Uber Burger', // 'city' => 'Little Rock', // 'zip' => '72201', // ], // ]

<a id="helper-datetime"></a> ## DateTimeHelper #### range Generates an array of start and endates for a specified period of time (UTC) ```php array range(string $startDate, string $endDate, string $periodDate, string $step = '+1 day', string $daysOfWeek = null, string $dateFormat = 'Y-m-d H:i:s')
$startDate = '2015-06-04 08:00:00';
$endDate = '2015-06-04 12:00:00';
$periodDate = '2015-06-06 12:00:00';
$step = '+1 day';
$daysOfWeek = null;
$dateFormat = 'Y-m-d H:i:s';

DateTimeHelper::range($startDate, $endDate, $periodDate, $step, $daysOfWeek, $dateFormat);

// [
//   [
//     'start' => '2015-06-04 08:00:00',
//     'end' => '2015-06-04 12:00:00',
//   ],
//   [
//     'start' => '2015-06-05 08:00:00',
//     'end' => '2015-06-05 12:00:00',
//   ],
//   [
//     'start' => '2015-06-06 08:00:00',
//     'end' => '2015-06-06 12:00:00',
//   ],
// ]
$startDate = '2015-09-23 10:11:51';
$endDate = '2015-09-24 02:55:51';
$periodDate = '2015-09-30 11:59:59';
$step = '+1 week';
$daysOfWeek = 'mon,wed,fri';
$dateFormat = 'Y-m-d H:i:s';

DateTimeHelper::range($startDate, $endDate, $periodDate, $step, $daysOfWeek, $dateFormat);

// [
//   [
//     'start' => '2015-09-21 10:11:51',
//     'end' => '2015-09-22 02:55:51',
//   ],
//   [
//     'start' => '2015-09-23 10:11:51',
//     'end' => '2015-09-24 02:55:51',
//   ],
//   [
//     'start' => '2015-09-25 10:11:51',
//     'end' => '2015-09-26 02:55:51',
//   ],
//   [
//     'start' => '2015-09-28 10:11:51',
//     'end' => '2015-09-29 02:55:51',
//   ],
//   [
//     'start' => '2015-09-30 10:11:51',
//     'end' => '2015-10-01 02:55:51',
//   ],
//   [
//     'start' => '2015-10-02 10:11:51',
//     'end' => '2015-10-03 02:55:51',
//   ],
// ];
<a id="helper-file"></a> ## FileHelper #### directoryFiles Return an array of files with their full paths contained in a directory and its subdirectories
array directoryFiles(string $path)
```php FileHelper::directoryFiles('/directory-path'); // [ // '/directory-path/file1.txt', // '/directory-path/file2.txt', // '/directory-path/subdirectory/file3.txt', // ]

The Versions

07/01 2016

1.0.x-dev

1.0.9999999.9999999-dev http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

07/01 2016

dev-master

9999999-dev http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

07/01 2016

1.0.12

1.0.12.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

06/01 2016

1.0.11

1.0.11.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

23/12 2015

1.0.10

1.0.10.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

19/12 2015

1.0.9

1.0.9.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

18/12 2015

1.0.8

1.0.8.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

18/12 2015

1.0.7

1.0.7.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

18/12 2015

1.0.6

1.0.6.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

18/12 2015

1.0.5

1.0.5.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel file helpers helper array date time php7 string mojo mojopollo

17/12 2015

1.0.4

1.0.4.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel helpers helper mojo mojopollo

16/12 2015

1.0.3

1.0.3.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel helpers helper mojo mojopollo

15/12 2015

1.0.2

1.0.2.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel helpers helper mojo mojopollo

24/11 2015

1.0.1

1.0.1.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel helpers helper mojo mojopollo

19/11 2015

1.0.0

1.0.0.0 http://localhost

Mojo's Laravel Helpers: A suite of various helpers for use in Laravel 5.0 / 5.1 / Composer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jaime Medina

laravel helpers helper mojo mojopollo