Skip to content

Commit 7f427c4

Browse files
committed
backport cloud support
1 parent a39f4db commit 7f427c4

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Database\Migrations;
44

5+
use Closure;
56
use Doctrine\DBAL\Schema\SchemaException;
67
use Illuminate\Console\View\Components\BulletList;
78
use Illuminate\Console\View\Components\Error;
@@ -52,6 +53,13 @@ class Migrator
5253
*/
5354
protected $resolver;
5455

56+
/**
57+
* The custom connection resolver callback.
58+
*
59+
* @var \Closure|null
60+
*/
61+
protected static $connectionResolverCallback;
62+
5563
/**
5664
* The name of the default connection.
5765
*
@@ -660,7 +668,26 @@ public function setConnection($name)
660668
*/
661669
public function resolveConnection($connection)
662670
{
663-
return $this->resolver->connection($connection ?: $this->connection);
671+
if (static::$connectionResolverCallback) {
672+
return call_user_func(
673+
static::$connectionResolverCallback,
674+
$this->resolver,
675+
$connection ?: $this->connection
676+
);
677+
} else {
678+
return $this->resolver->connection($connection ?: $this->connection);
679+
}
680+
}
681+
682+
/**
683+
* Set a connection resolver callback.
684+
*
685+
* @param \Closure $callback
686+
* @return void
687+
*/
688+
public static function resolveConnectionsUsing(Closure $callback)
689+
{
690+
static::$connectionResolverCallback = $callback;
664691
}
665692

666693
/**

src/Illuminate/Foundation/Application.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public function __construct($basePath = null)
204204
$this->registerBaseBindings();
205205
$this->registerBaseServiceProviders();
206206
$this->registerCoreContainerAliases();
207+
$this->registerLaravelCloudServices();
207208
}
208209

209210
/**
@@ -247,6 +248,28 @@ protected function registerBaseServiceProviders()
247248
$this->register(new RoutingServiceProvider($this));
248249
}
249250

251+
/**
252+
* Register any services needed for Laravel Cloud.
253+
*
254+
* @return void
255+
*/
256+
protected function registerLaravelCloudServices()
257+
{
258+
if (! laravel_cloud()) {
259+
return;
260+
}
261+
262+
$this['events']->listen(
263+
'bootstrapping: *',
264+
fn ($bootstrapper) => Cloud::bootstrapperBootstrapping($this, Str::after($bootstrapper, 'bootstrapping: '))
265+
);
266+
267+
$this['events']->listen(
268+
'bootstrapped: *',
269+
fn ($bootstrapper) => Cloud::bootstrapperBootstrapped($this, Str::after($bootstrapper, 'bootstrapped: '))
270+
);
271+
}
272+
250273
/**
251274
* Run the given array of bootstrap classes.
252275
*

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public function bootstrap(Application $app)
5454
if (! $app->environment('testing')) {
5555
ini_set('display_errors', 'Off');
5656
}
57-
58-
if (laravel_cloud()) {
59-
$this->configureCloudLogging($app);
60-
}
6157
}
6258

6359
/**
@@ -250,34 +246,6 @@ protected function fatalErrorFromPhpError(array $error, $traceOffset = null)
250246
return new FatalError($error['message'], 0, $error, $traceOffset);
251247
}
252248

253-
/**
254-
* Configure the Laravel Cloud log channels.
255-
*
256-
* @param \Illuminate\Contracts\Foundation\Application $app
257-
* @return void
258-
*/
259-
protected function configureCloudLogging(Application $app)
260-
{
261-
$app['config']->set('logging.channels.stderr.formatter_with', [
262-
'includeStacktraces' => true,
263-
]);
264-
265-
$app['config']->set('logging.channels.laravel-cloud-socket', [
266-
'driver' => 'monolog',
267-
'handler' => SocketHandler::class,
268-
'formatter' => JsonFormatter::class,
269-
'formatter_with' => [
270-
'includeStacktraces' => true,
271-
],
272-
'with' => [
273-
'connectionString' => $_ENV['LARAVEL_CLOUD_LOG_SOCKET'] ??
274-
$_SERVER['LARAVEL_CLOUD_LOG_SOCKET'] ??
275-
'unix:///tmp/cloud-init.sock',
276-
'persistent' => true,
277-
],
278-
]);
279-
}
280-
281249
/**
282250
* Forward a method call to the given method if an application instance exists.
283251
*

0 commit comments

Comments
 (0)