Skip to content
This repository was archived by the owner on Dec 14, 2019. It is now read-only.

Commit d91b126

Browse files
committed
Updated package for Laravel 6.
1 parent d1d1379 commit d91b126

File tree

8 files changed

+37
-20
lines changed

8 files changed

+37
-20
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"require": {
2929
"laravel/tinker": "~1.0",
30-
"illuminate/container": "^5.2"
30+
"illuminate/container": "^5.2|^6.0"
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "^6.4|^7.0"

resources/views/includes.blade.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<php
22

33
use Ajthinking\Tinx\Console\State;
4+
use Illuminate\Support\Arr;
45

56
/**
67
* Restarts Tinker.
@@ -52,7 +53,7 @@ function names(...$args) {
5253
* @return void
5354
* */
5455
function tinx_forget_name($class) {
55-
array_forget($GLOBALS, "tinx.names.$class");
56+
Arr::forget($GLOBALS, "tinx.names.$class");
5657
}
5758
5859
/**
@@ -124,14 +125,14 @@ function tinx_query($class, ...$args)
124125
* For "first" variable, returns "::first()" if class DB table exists, otherwise "new" (if 'tableless_models' set to true).
125126
* For "last" variable, returns "::latest()->first()" if class DB table exists, otherwise "new" (if 'tableless_models' set to true).
126127
* */
127-
array_set($GLOBALS, 'tinx.names', {!! var_export($names); !!});
128-
$latestColumn = '{{ array_get($config, 'latest_column', 'created_at') }}';
128+
Arr::set($GLOBALS, 'tinx.names', {!! var_export($names); !!});
129+
$latestColumn = '{{ Arr::get($config, 'latest_column', 'created_at') }}';
129130
@foreach ($names as $class => $name)
130131
try {
131132
${!! $name !!} = {!! $class !!}::first() ?: app('{!! $class !!}');
132133
${!! $name !!}_ = {!! $class !!}::latest($latestColumn)->first() ?: app('{!! $class !!}');
133-
array_set($GLOBALS, 'tinx.shortcuts.{!! $name !!}', ${!! $name !!});
134-
array_set($GLOBALS, 'tinx.shortcuts.{!! $name !!}_', ${!! $name !!}_);
134+
Arr::set($GLOBALS, 'tinx.shortcuts.{!! $name !!}', ${!! $name !!});
135+
Arr::set($GLOBALS, 'tinx.shortcuts.{!! $name !!}_', ${!! $name !!}_);
135136
if (!function_exists('{!! $name !!}')) {
136137
function {!! $name !!}(...$args) {
137138
return tinx_query('{!! $class !!}', ...$args);
@@ -148,19 +149,19 @@ function {!! $name !!}(...$args) {
148149
/**
149150
* Quick names reference array.
150151
* */
151-
$names = array_get($GLOBALS, 'tinx.names');
152+
$names = Arr::get($GLOBALS, 'tinx.names');
152153

153154
/**
154155
* Define shortcuts for "names()" table, and also set quick shortcuts reference array.
155156
* */
156157
$shortcuts = collect($names)->map(function ($name, $class) {
157158
$shortcuts = [];
158-
if (array_has($GLOBALS, "tinx.shortcuts.$name")) $shortcuts[] = "\${$name}";
159-
if (array_has($GLOBALS, "tinx.shortcuts.{$name}_")) $shortcuts[] = "\${$name}_";
159+
if (Arr::has($GLOBALS, "tinx.shortcuts.$name")) $shortcuts[] = "\${$name}";
160+
if (Arr::has($GLOBALS, "tinx.shortcuts.{$name}_")) $shortcuts[] = "\${$name}_";
160161
if (function_exists($name)) $shortcuts[] = "{$name}()";
161162
return implode(', ', $shortcuts);
162163
})->all();
163-
array_set($GLOBALS, 'tinx.names', $shortcuts);
164+
Arr::set($GLOBALS, 'tinx.names', $shortcuts);
164165

165166
/**
166167
* Conditionally render the "Class/Shortcuts" names table.

resources/views/on-name-error.blade.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
@if ((bool) array_get($config, 'tableless_models') === true)
1+
<?php
2+
3+
use Illuminate\Support\Arr;
4+
5+
?>
6+
7+
@if ((bool) Arr::get($config, 'tableless_models') === true)
28
try {
39
${!! $name !!} = app('{!! $class !!}');
410
${!! $name !!}_ = app('{!! $class !!}');
5-
array_set($GLOBALS, 'tinx.shortcuts.{!! $name !!}', ${!! $name !!});
6-
array_set($GLOBALS, 'tinx.shortcuts.{!! $name !!}_', ${!! $name !!}_);
11+
Arr::set($GLOBALS, 'tinx.shortcuts.{!! $name !!}', ${!! $name !!});
12+
Arr::set($GLOBALS, 'tinx.shortcuts.{!! $name !!}_', ${!! $name !!}_);
713
if (!function_exists('{!! $name !!}')) {
814
function {!! $name !!}(...$args) {
915
return '{!! $class !!}';

src/Console/NamesTable.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Ajthinking\Tinx\Console;
44

5+
use Illuminate\Support\Arr;
6+
57
class NamesTable
68
{
79
/**
@@ -20,7 +22,7 @@ public static function make(TinxCommand $command)
2022
private function __construct(TinxCommand $command)
2123
{
2224
$this->command = $command;
23-
$this->names = array_get($GLOBALS, 'tinx.names');
25+
$this->names = Arr::get($GLOBALS, 'tinx.names');
2426
}
2527

2628
/**

src/Includes/IncludeManager.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Ajthinking\Tinx\Includes;
44

5+
use Illuminate\Support\Str;
6+
57
class IncludeManager
68
{
79
/**
@@ -14,7 +16,7 @@ public function generateIncludesFile($names)
1416

1517
$contents = view('tinx::includes', compact('names', 'config'))->render();
1618

17-
$contents = str_replace_first('<php', '<?php', $contents);
19+
$contents = Str::replaceFirst('<php', '<?php', $contents);
1820

1921
app('tinx.storage')->put('includes.php', $contents);
2022
}

src/Models/Model.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Ajthinking\Tinx\Models;
44

5+
use Illuminate\Support\Str;
6+
57
class Model
68
{
79
/**
@@ -13,7 +15,7 @@ public function __construct($fullClassName)
1315
$this->fullClassName = $fullClassName;
1416
$this->shortClassName = class_basename($this->fullClassName);
1517
$this->namespace = trim(preg_replace("/{$this->shortClassName}$/", '', $this->fullClassName), '\\');
16-
$this->shortClassNameSlug = str_slug($this->shortClassName);
18+
$this->shortClassNameSlug = Str::slug($this->shortClassName);
1719
$this->shortClassNameWords = $this->getWordsFromString($this->shortClassName);
1820
}
1921

@@ -23,6 +25,6 @@ public function __construct($fullClassName)
2325
* */
2426
private function getWordsFromString($string)
2527
{
26-
return preg_split('/_|(\d+)/u', snake_case($string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
28+
return preg_split('/_|(\d+)/u', Str::snake($string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
2729
}
2830
}

src/Models/Models.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Ajthinking\Tinx\Models;
44

55
use Exception;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Collection;
8+
use Illuminate\Support\Str;
79

810
class Models extends Collection
911
{
@@ -51,7 +53,7 @@ private function getModels()
5153
foreach ($modelFilePaths as $modelFilePath) {
5254
$absoluteFilePath = $this->getAbsoluteFilePath($modelFilePath);
5355
$recursive = false;
54-
if (ends_with($absoluteFilePath, '*')) {
56+
if (Str::endsWith($absoluteFilePath, '*')) {
5557
$absoluteFilePath = rtrim($absoluteFilePath, '/*');
5658
$recursive = true;
5759
}
@@ -107,7 +109,7 @@ private function getFullClassName($path)
107109
// Fail silently…
108110
}
109111

110-
$namespace = array_get($matches, 1);
112+
$namespace = Arr::get($matches, 1);
111113

112114
if (null === $namespace) {
113115
return null;

src/Naming/PascalStrategy.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Ajthinking\Tinx\Naming;
44

5+
use Illuminate\Support\Arr;
6+
57
class PascalStrategy implements Strategy
68
{
79
/**
@@ -126,7 +128,7 @@ private function getConflictingModel($conflictingName, $causalModel)
126128
$conflictingModel = $causalModel;
127129
$this->dump("Can't set [{$causalModel->fullClassName}] due to forbidden name [$conflictingName].");
128130
} else {
129-
$conflictingModel = array_get($this->names, $conflictingName, $causalModel);
131+
$conflictingModel = Arr::get($this->names, $conflictingName, $causalModel);
130132
$this->dump("Can't set [{$causalModel->fullClassName}] as [$conflictingName] due to [{$conflictingModel->fullClassName}].");
131133
}
132134

0 commit comments

Comments
 (0)