File tree Expand file tree Collapse file tree 6 files changed +207
-0
lines changed
Expand file tree Collapse file tree 6 files changed +207
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
55The format is based on [ Keep a Changelog] [ keepachangelog ] and this project adheres to [ Semantic Versioning] [ semver ] .
66
7+ ## UNRELEASED
8+
9+ ### Added
10+
11+ - Give the current App instance to ` FilesystemManager ` (listener ` RebindFilesystemManagerListener ` ) [ #77 ]
12+ - Monolog state resetting between requests (listener ` FlushMonologStateListener ` ) [ #77 ]
13+
14+ [ #77 ] :https://github.com/spiral/roadrunner-laravel/pull/77
15+
716## v5.5.0
817
918### Added
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ public static function beforeLoopIteration(): array
3939 Listeners \RebindBroadcastManagerListener::class,
4040 Listeners \RebindDatabaseManagerListener::class,
4141 Listeners \RebindDatabaseSessionHandlerListener::class,
42+ Listeners \RebindFilesystemManagerListener::class,
4243 Listeners \RebindMailManagerListener::class,
4344 Listeners \RebindNotificationChannelManagerListener::class,
4445 Listeners \RebindPipelineHubListener::class,
@@ -95,6 +96,7 @@ public static function afterLoopIteration(): array
9596 Listeners \FlushDumperStackListener::class,
9697 Listeners \FlushLogContextListener::class,
9798 Listeners \FlushArrayCacheListener::class,
99+ Listeners \FlushMonologStateListener::class,
98100 Listeners \FlushTranslatorCacheListener::class,
99101 Listeners \ResetDatabaseRecordModificationStateListener::class,
100102 Listeners \FlushDatabaseQueryLogListener::class,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Spiral \RoadRunnerLaravel \Listeners ;
6+
7+ /**
8+ * @link https://github.com/laravel/octane/blob/1.x/src/Listeners/FlushMonologState.php
9+ */
10+ class FlushMonologStateListener implements ListenerInterface
11+ {
12+ /**
13+ * {@inheritdoc}
14+ */
15+ public function handle ($ event ): void
16+ {
17+ if ($ event instanceof \Spiral \RoadRunnerLaravel \Events \Contracts \WithApplication) {
18+ $ app = $ event ->application ();
19+
20+ if (!$ app ->resolved ($ log_abstract = 'log ' )) {
21+ return ;
22+ }
23+
24+ /** @var \Illuminate\Log\LogManager $log_manager */
25+ $ log_manager = $ app ->make ($ log_abstract );
26+
27+ foreach ($ log_manager ->getChannels () as $ channel ) {
28+ if ($ channel instanceof \Illuminate \Log \Logger) {
29+ $ logger = $ channel ->getLogger ();
30+
31+ if ($ logger instanceof \Monolog \ResettableInterface) {
32+ $ logger ->reset ();
33+ }
34+ }
35+ }
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Spiral \RoadRunnerLaravel \Listeners ;
6+
7+ use Spiral \RoadRunnerLaravel \Events \Contracts \WithApplication ;
8+
9+ /**
10+ * @link https://github.com/laravel/octane/blob/1.x/src/Listeners/GiveNewApplicationInstanceToFilesystemManager.php
11+ */
12+ class RebindFilesystemManagerListener implements ListenerInterface
13+ {
14+ use Traits \InvokerTrait;
15+
16+ /**
17+ * {@inheritdoc}
18+ */
19+ public function handle ($ event ): void
20+ {
21+ if ($ event instanceof WithApplication) {
22+ $ app = $ event ->application ();
23+
24+ if (!$ app ->resolved ($ filesystem_abstract = 'filesystem ' )) {
25+ return ;
26+ }
27+
28+ /** @var \Illuminate\Filesystem\FilesystemManager $filesystem_manager */
29+ $ filesystem_manager = $ app ->make ($ filesystem_abstract );
30+
31+ /**
32+ * Method `setApplication` for the FilesystemManager available since Laravel v8.77.0.
33+ *
34+ * @link https://github.com/laravel/framework/blob/v8.77.0/src/Illuminate/Filesystem/FilesystemManager.php#L395-L400
35+ * @see \Illuminate\Filesystem\FilesystemManager::setApplication
36+ */
37+ if (! $ this ->invokeMethod ($ filesystem_manager , 'setApplication ' , $ app )) {
38+ $ this ->setProperty ($ filesystem_manager , 'app ' , $ app );
39+ }
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Spiral \RoadRunnerLaravel \Tests \Unit \Listeners ;
6+
7+ use Mockery as m ;
8+ use Spiral \RoadRunnerLaravel \Events \Contracts \WithApplication ;
9+ use Spiral \RoadRunnerLaravel \Listeners \FlushMonologStateListener ;
10+
11+ /**
12+ * @covers \Spiral\RoadRunnerLaravel\Listeners\FlushMonologStateListener
13+ */
14+ class FlushMonologStateListenerTest extends AbstractListenerTestCase
15+ {
16+ /**
17+ * {@inheritdoc}
18+ */
19+ public function testHandle (): void
20+ {
21+ /** @var \Illuminate\Log\LogManager $log_manager */
22+ $ log_manager = $ this ->app ->make ('log ' );
23+
24+ /** @var \Illuminate\Log\Logger $driver */
25+ $ driver = $ log_manager ->driver ();
26+
27+ /** @var \Monolog\Logger $logger */
28+ $ logger = $ driver ->getLogger ();
29+
30+ $ this ->app ->instance ('log ' , m::mock ($ log_manager )
31+ ->makePartial ()
32+ ->expects ('getChannels ' )
33+ ->withNoArgs ()
34+ ->andReturns ([
35+ m::mock ($ driver )
36+ ->makePartial ()
37+ ->expects ('getLogger ' )
38+ ->withNoArgs ()
39+ ->andReturn (
40+ m::mock ($ logger )
41+ ->makePartial ()
42+ ->expects ('reset ' )
43+ ->once ()
44+ ->withNoArgs ()
45+ ->getMock (),
46+ )
47+ ->getMock (),
48+ ])
49+ ->getMock ());
50+
51+ /** @var m\MockInterface|WithApplication $event_mock */
52+ $ event_mock = m::mock (WithApplication::class)
53+ ->makePartial ()
54+ ->expects ('application ' )
55+ ->andReturn ($ this ->app )
56+ ->getMock ();
57+
58+ $ this ->listenerFactory ()->handle ($ event_mock );
59+ }
60+
61+ /**
62+ * @return FlushMonologStateListener
63+ */
64+ protected function listenerFactory (): FlushMonologStateListener
65+ {
66+ return new FlushMonologStateListener ();
67+ }
68+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Spiral \RoadRunnerLaravel \Tests \Unit \Listeners ;
6+
7+ use Mockery as m ;
8+ use Illuminate \Filesystem \FilesystemManager ;
9+ use Spiral \RoadRunnerLaravel \Events \Contracts \WithApplication ;
10+ use Spiral \RoadRunnerLaravel \Listeners \RebindFilesystemManagerListener ;
11+
12+ /**
13+ * @covers \Spiral\RoadRunnerLaravel\Listeners\RebindFilesystemManagerListener
14+ */
15+ class RebindFilesystemManagerListenerTest extends AbstractListenerTestCase
16+ {
17+ /**
18+ * {@inheritdoc}
19+ */
20+ public function testHandle (): void
21+ {
22+ $ app_clone = clone $ this ->app ;
23+
24+ /** @var FilesystemManager $filesystem_manager */
25+ $ filesystem_manager = $ this ->app ->make ('filesystem ' );
26+
27+ $ this ->setProperty ($ filesystem_manager , $ app_prop = 'app ' , $ app_clone );
28+
29+ /** @var m\MockInterface|WithApplication $event_mock */
30+ $ event_mock = m::mock (WithApplication::class)
31+ ->makePartial ()
32+ ->expects ('application ' )
33+ ->andReturn ($ this ->app )
34+ ->getMock ();
35+
36+ $ this ->listenerFactory ()->handle ($ event_mock );
37+
38+ $ this ->assertSame ($ this ->app , $ this ->getProperty ($ filesystem_manager , $ app_prop ));
39+ }
40+
41+ /**
42+ * @return RebindFilesystemManagerListener
43+ */
44+ protected function listenerFactory (): RebindFilesystemManagerListener
45+ {
46+ return new RebindFilesystemManagerListener ();
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments