4
4
namespace Sprout \Support ;
5
5
6
6
use Closure ;
7
+ use Illuminate \Contracts \Config \Repository ;
7
8
use Illuminate \Contracts \Foundation \Application ;
8
9
use Sprout \Exceptions \MisconfigurationException ;
9
10
use Sprout \Sprout ;
@@ -52,6 +53,13 @@ public static function register(string $name, Closure $creator): void
52
53
*/
53
54
protected Application $ app ;
54
55
56
+ /**
57
+ * The Laravel config
58
+ *
59
+ * @var \Illuminate\Contracts\Config\Repository
60
+ */
61
+ private Repository $ config ;
62
+
55
63
/**
56
64
* Previously created objects
57
65
*
@@ -109,11 +117,8 @@ abstract public function getConfigKey(string $name): string;
109
117
*/
110
118
public function getDefaultName (): string
111
119
{
112
- /** @var \Illuminate\Config\Repository $config */
113
- $ config = app ('config ' );
114
-
115
120
/** @var string|null $name */
116
- $ name = $ config ->get ('multitenancy.defaults. ' . $ this ->getFactoryName ());
121
+ $ name = $ this -> getAppConfig () ->get ('multitenancy.defaults. ' . $ this ->getFactoryName ());
117
122
118
123
if ($ name === null ) {
119
124
throw MisconfigurationException::noDefault ($ this ->getFactoryName ());
@@ -131,11 +136,8 @@ public function getDefaultName(): string
131
136
*/
132
137
protected function getConfig (string $ name ): ?array
133
138
{
134
- /** @var \Illuminate\Config\Repository $repo */
135
- $ repo = app ('config ' );
136
-
137
139
/** @var array<string,mixed>|null $config */
138
- $ config = $ repo ->get ($ this ->getConfigKey ($ name ));
140
+ $ config = $ this -> getAppConfig () ->get ($ this ->getConfigKey ($ name ));
139
141
140
142
return $ config ;
141
143
}
@@ -291,4 +293,20 @@ protected function setupResolvedObject(object $object): object
291
293
292
294
return $ object ;
293
295
}
296
+
297
+ /**
298
+ * Get the application config
299
+ *
300
+ * @return \Illuminate\Contracts\Config\Repository
301
+ *
302
+ * @throws \Illuminate\Contracts\Container\BindingResolutionException
303
+ */
304
+ protected function getAppConfig (): Repository
305
+ {
306
+ if (! isset ($ this ->config )) {
307
+ $ this ->config = $ this ->app ->make ('config ' );
308
+ }
309
+
310
+ return $ this ->config ;
311
+ }
294
312
}
0 commit comments