Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<p align="center">
<a href="https://travis-ci.org/omnicode/lara-support"><img src="https://travis-ci.org/omnicode/lara-support.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/omnicode/lara-support"><img src="https://poser.pugx.org/omnicode/lara-support/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/omnicode/lara-support"><img src="https://poser.pugx.org/omnicode/lara-support/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/omnicode/lara-support"><img src="https://poser.pugx.org/omnicode/lara-support/license.svg" alt="License"></a>
</p>

# Lara-Support

Useful classes/methods
# lara-Support

Have useful classes

# LaraServiceProvider

Expand All @@ -34,33 +26,27 @@ Useful classes/methods
getViewVendorPath($path)
getViewPath($rootPath, $view = 'views')
getRoutePath($rootPath, $path = 'routes.php')


# Str
positions($string, $search)

finds the given string's position in the text
search occourence
return empty array or associative array
[
occurence => position
]
example


Str::positions('I love php, I love php too!','php')

returns
[
1 => 7
2 => 19
]
Str::positions('I love php, I love php too!','Php')
return []


ipositions($string, $search)

case-insesitive versino for positions
search case-insesitive simialar positions

Str::ipositions('I love php, I love php too!','php')
returns
Expand Down Expand Up @@ -108,12 +94,11 @@ Useful classes/methods
between
wrap
iwrap

# DB
getTable
return all db tables list

getColumnsFullInfo*
getColumnsFullInfo
return list
[
coulumn => [
Expand All @@ -126,5 +111,3 @@ Useful classes/methods
]
]

*example is for mysql DB

18 changes: 14 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
}
],
"require": {
"laravel/framework": "5.6.*",
"omnicode/php-util": "3.0.*"
"laravel/framework": "5.5.*",
"omnicode/php-util": "0.1.*"
},
"require-dev": {
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~7.0",
"omnicode/lara-test": "~0.0",
"phpunit/phpunit": "~6.0",
"orchestra/testbench": "~3.0"

},
Expand All @@ -28,5 +27,16 @@
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"LaraSupport\\ServiceProvider\\LaraSupportServiceProvider"
],
"aliases": {
"LaraDB": "LaraSupport\\Facades\\LaraDB",
"LaraPassword": "LaraSupport\\Facades\\LaraPassword"
}
}
}
}
108 changes: 108 additions & 0 deletions src/Arr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace LaraSupport;

use Illuminate\Support\Arr as BaseArr;

class Arr extends BaseArr
{
/**
* returns array with options for select box
*
* @param $min
* @param $max
* @param int $step
* @return array
*/
public static function range($min, $max, $step = 1)
{
return array_combine(range($min, $max, $step), range($min, $max, $step));
}


/**
* returns the first key of the array
*
* @param array $array
* @return mixed
*/
public static function firstKey(array $array = [])
{
reset($array);
return key($array);
}

/**
* returns the last key of the array
*
* @param array $array
* @return mixed
*/
public static function lastKey(array $array)
{
$array = array_reverse($array, true);
reset($array);
return key($array);
}

/**
* unsets array's items by value
*
* @param array $array - the original array
* @param array|string - the value or array of values to be unset
* @return array - the processed array
*/
public static function unset(array $array, $values = [])
{
$values = (array) $values;
return array_diff($array, $values);
}

/**
* case-insensitive array_unique
*
* @param array
* @return array
* @link http://stackoverflow.com/a/2276400/932473
*/
public static function iUnique(array $array)
{
$lowered = array_map('mb_strtolower', $array);
return array_intersect_key($array, array_unique($lowered));
}

/**
* case-insensitive in_array
*
* @param string $needle
* @param array $haystack
* @return bool
*
* @link http://us2.php.net/manual/en/function.in-array.php#89256
* @link https://stackoverflow.com/a/2166524
* @link https://stackoverflow.com/a/2166522
*/
public static function inArrayI($needle, $haystack)
{
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}

/**
* check if array's keys are all numeric
*
* @param array
* @return bool
* @link https://codereview.stackexchange.com/q/201/32948
*/
public static function isNumeric($array)
{
foreach ($array as $k => $v) {
if (!is_int($k)) {
return false;
}
}

return true;
}

}
7 changes: 7 additions & 0 deletions src/LaraDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function getTables()
*/
public function getColumnsFullInfo($table)
{
// $query = 'show full columns from ' . $table;
$query = 'show columns from ' . $table;
$columns = $this->connection->select($query);
$columnsInfo = [];
Expand Down Expand Up @@ -164,6 +165,10 @@ public function getColumnsFullInfo($table)
*/
public function getDBStructure()
{
// SELECT *
// FROM INFORMATION_SCHEMA.COLUMNS
//WHERE table_name = 'Address'

$query = sprintf("SELECT * FROM information_schema.columns WHERE table_schema ='%s'", env('DB_DATABASE'));
$dbStructures = $this->connection->select($query);
$tables = [];
Expand All @@ -178,6 +183,8 @@ public function getDBStructure()
'extra' => $dbStructure->EXTRA,
'unsigned' => str_contains($dbStructure->COLUMN_TYPE, 'unsigned') ? true : false,
'column_type' => $dbStructure->COLUMN_TYPE,
'comment' => $dbStructure->COLUMN_COMMENT,
'key' => $dbStructure->COLUMN_KEY,
];
if ($dbStructure->CHARACTER_MAXIMUM_LENGTH) {
$tables[$dbStructure->TABLE_NAME][$dbStructure->COLUMN_NAME]['length'] = $dbStructure->CHARACTER_MAXIMUM_LENGTH;
Expand Down
6 changes: 0 additions & 6 deletions src/ServiceProvider/LaraSupportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public function boot()
*/
public function register()
{
$this->registerAliases(
[
'LaraDB' => \LaraSupport\Facades\LaraDB::class,
'LaraPassword' => \LaraSupport\Facades\LaraPassword::class,
]
);
$this->registerSingletons([
'lara-db' => LaraDB::class,
'lara-password' => LaraPassword::class,
Expand Down
Loading