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

Commit 9835271

Browse files
committed
Patched (and better documented) custom naming strategy bug.
1 parent 2fa48f0 commit 9835271

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ return [
150150
],
151151

152152
/**
153-
* Model shortcut naming strategy (e.g. 'App\User' = '$u', 'u()').
154-
* Supported: 'pascal', 'shortestUnique'
155-
* Also supports any resolvable full class name implementing 'Ajthinking\Tinx\Naming\Strategy'.
153+
* Model shortcut naming strategy (e.g. 'App\User' = '$u', '$u_', 'u()').
154+
* Supported values: 'pascal', 'shortestUnique'
156155
* */
157156
'strategy' => 'pascal',
157+
/**
158+
* Alternatively, you may pass a resolvable fully qualified class name
159+
* implementing 'Ajthinking\Tinx\Naming\Strategy'.
160+
* */
161+
// 'strategy' => App\CustomNamingStrategy::class,
158162

159163
/**
160164
* Column name (e.g. 'id', 'created_at') used to determine last model shortcut (i.e. '$u_').

config/tinx.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
],
3030

3131
/**
32-
* Model shortcut naming strategy (e.g. 'App\User' = '$u', 'u()').
33-
* Supported: 'pascal', 'shortestUnique'
34-
* Also supports any resolvable full class name implementing 'Ajthinking\Tinx\Naming\Strategy'.
32+
* Model shortcut naming strategy (e.g. 'App\User' = '$u', '$u_', 'u()').
33+
* Supported values: 'pascal', 'shortestUnique'
3534
* */
3635
'strategy' => 'pascal',
36+
/**
37+
* Alternatively, you may pass a resolvable fully qualified class name
38+
* implementing 'Ajthinking\Tinx\Naming\Strategy'.
39+
* */
40+
// 'strategy' => App\CustomNamingStrategy::class,
3741

3842
/**
3943
* Column name (e.g. 'id', 'created_at') used to determine last model shortcut (i.e. '$u_').

src/Naming/StrategyFactory.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ private static function resolveViaContainer($strategy, $models)
4747
/**
4848
* This is the same as calling Laravel's "app()" helper,
4949
* but we don't have that framework function available.
50+
* The make method check supports legacy Laravel installs.
5051
* */
51-
$instance = Container::getInstance()->make($strategy, [$models]);
52+
$container = Container::getInstance();
53+
$makeMethod = method_exists($container, 'makeWith') ? 'makeWith' : 'make';
54+
$instance = $container->$makeMethod($strategy, ['models' => $models]);
5255

5356
if ($instance instanceof Strategy) {
5457
return $instance;

0 commit comments

Comments
 (0)