Skip to content

Commit e318aa1

Browse files
committed
refactor: Update base factory to not use app helper
1 parent c45fe5e commit e318aa1

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/Support/BaseFactory.php

+26-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Sprout\Support;
55

66
use Closure;
7+
use Illuminate\Contracts\Config\Repository;
78
use Illuminate\Contracts\Foundation\Application;
89
use Sprout\Exceptions\MisconfigurationException;
910
use Sprout\Sprout;
@@ -52,6 +53,13 @@ public static function register(string $name, Closure $creator): void
5253
*/
5354
protected Application $app;
5455

56+
/**
57+
* The Laravel config
58+
*
59+
* @var \Illuminate\Contracts\Config\Repository
60+
*/
61+
private Repository $config;
62+
5563
/**
5664
* Previously created objects
5765
*
@@ -109,11 +117,8 @@ abstract public function getConfigKey(string $name): string;
109117
*/
110118
public function getDefaultName(): string
111119
{
112-
/** @var \Illuminate\Config\Repository $config */
113-
$config = app('config');
114-
115120
/** @var string|null $name */
116-
$name = $config->get('multitenancy.defaults.' . $this->getFactoryName());
121+
$name = $this->getAppConfig()->get('multitenancy.defaults.' . $this->getFactoryName());
117122

118123
if ($name === null) {
119124
throw MisconfigurationException::noDefault($this->getFactoryName());
@@ -131,11 +136,8 @@ public function getDefaultName(): string
131136
*/
132137
protected function getConfig(string $name): ?array
133138
{
134-
/** @var \Illuminate\Config\Repository $repo */
135-
$repo = app('config');
136-
137139
/** @var array<string,mixed>|null $config */
138-
$config = $repo->get($this->getConfigKey($name));
140+
$config = $this->getAppConfig()->get($this->getConfigKey($name));
139141

140142
return $config;
141143
}
@@ -291,4 +293,20 @@ protected function setupResolvedObject(object $object): object
291293

292294
return $object;
293295
}
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+
}
294312
}

0 commit comments

Comments
 (0)