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
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
],
"require": {
"laravel/framework": "5.6.*",
"omnicode/php-util": "3.0.*"
"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