-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProviderFactoryServiceProvider with .env var to specify SystemInf…
…o outgoing_ips
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ LOG_CHANNEL=stack | |
|
||
DB_CONNECTION=sqlite | ||
DB_DATABASE="database.sqlite" | ||
|
||
OUTGOING_IPS= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Contracts\Filesystem\Filesystem; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\ServiceProvider; | ||
use Psr\Log\LoggerInterface; | ||
use Upmind\ProvisionBase\Provider\DataSet\SystemInfo; | ||
use Upmind\ProvisionBase\ProviderFactory; | ||
use Upmind\ProvisionBase\Registry\Registry; | ||
|
||
class ProviderFactoryServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->singleton(SystemInfo::class, function ($app) { | ||
return new SystemInfo([ | ||
'outgoing_ips' => $this->getOutgoingIps(), | ||
]); | ||
}); | ||
|
||
$this->app->singleton(ProviderFactory::class, function ($app) { | ||
return new ProviderFactory( | ||
$app->make(Registry::class), | ||
$app->make(Filesystem::class), | ||
$app->make(LoggerInterface::class), | ||
$app->make(SystemInfo::class), | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function getOutgoingIps(): array | ||
{ | ||
// Get IPs from config | ||
if ($ips = array_filter(array_map('trim', explode(',', config('app.outgoing_ips') ?: '')))) { | ||
return $ips; | ||
} | ||
|
||
// Try to determine IP automatically | ||
return Arr::wrap( | ||
isset($_SERVER['SERVER_ADDR']) | ||
? $_SERVER['SERVER_ADDR'] | ||
: gethostbyname(gethostname() ?: php_uname('n')) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters