This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tetiuev Pavel <jetexe2@gmail.com>
- Loading branch information
1 parent
0b8c3f5
commit 2f7cac7
Showing
12 changed files
with
509 additions
and
36 deletions.
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
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
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
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,15 @@ | ||
<?php | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Events\Contracts; | ||
|
||
use Throwable; | ||
|
||
interface WithException | ||
{ | ||
/** | ||
* Get exception instance. | ||
* | ||
* @return Throwable | ||
*/ | ||
public function exception(): Throwable; | ||
} |
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 | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Events; | ||
|
||
use Throwable; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Illuminate\Contracts\Foundation\Application as ApplicationContract; | ||
|
||
final class LoopErrorOccurredEvent implements Contracts\WithApplication, Contracts\WithException, Contracts\WithServerRequest | ||
{ | ||
/** | ||
* @var ApplicationContract | ||
*/ | ||
private $app; | ||
|
||
/** | ||
* @var Throwable | ||
*/ | ||
private $exception; | ||
|
||
/** | ||
* @var ServerRequestInterface | ||
*/ | ||
private $server_request; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param ApplicationContract $app | ||
* @param ServerRequestInterface $server_request | ||
* @param Throwable $exception | ||
*/ | ||
public function __construct(ApplicationContract $app, ServerRequestInterface $server_request, Throwable $exception) | ||
{ | ||
$this->app = $app; | ||
$this->server_request = $server_request; | ||
$this->exception = $exception; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function application(): ApplicationContract | ||
{ | ||
return $this->app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function exception(): Throwable | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function serverRequest(): ServerRequestInterface | ||
{ | ||
return $this->server_request; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Listeners; | ||
|
||
use AvtoDev\RoadRunnerLaravel\Events\Contracts\WithException; | ||
|
||
class SendExceptionToStderrListener implements ListenerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if ($event instanceof WithException) { | ||
\fwrite(\STDERR, (string) $event->exception()); | ||
} | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Listeners; | ||
|
||
use Spiral\RoadRunner\PSR7Client; | ||
use AvtoDev\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
|
||
/** | ||
* Common usage - stop worker on unhandled error occurring. | ||
* | ||
* @link https://roadrunner.dev/docs/php-restarting | ||
*/ | ||
class StopWorkerListener implements ListenerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if ($event instanceof WithApplication) { | ||
/** @var PSR7Client $psr7_client */ | ||
$psr7_client = $event->application()->make(PSR7Client::class); | ||
|
||
$psr7_client->getWorker()->stop(); | ||
} | ||
} | ||
} |
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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Tests\Events; | ||
|
||
use Zend\Diactoros\ServerRequest; | ||
use AvtoDev\RoadRunnerLaravel\Events\LoopErrorOccurredEvent; | ||
use AvtoDev\RoadRunnerLaravel\Events\Contracts\WithException; | ||
use AvtoDev\RoadRunnerLaravel\Events\Contracts\WithApplication; | ||
use AvtoDev\RoadRunnerLaravel\Events\Contracts\WithServerRequest; | ||
|
||
/** | ||
* @covers \AvtoDev\RoadRunnerLaravel\Events\LoopErrorOccurredEvent<extended> | ||
*/ | ||
class LoopErrorOccurredTest extends AbstractEventTestCase | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $required_interfaces = [ | ||
WithApplication::class, | ||
WithException::class, | ||
WithServerRequest::class, | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $event_class = LoopErrorOccurredEvent::class; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function testConstructor(): void | ||
{ | ||
$event = new LoopErrorOccurredEvent( | ||
$this->app, | ||
$request = new ServerRequest, | ||
$exception = new \Exception('foo') | ||
); | ||
|
||
$this->assertSame($this->app, $event->application()); | ||
$this->assertSame($exception, $event->exception()); | ||
$this->assertSame($request, $event->serverRequest()); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\RoadRunnerLaravel\Tests\Listeners; | ||
|
||
use AvtoDev\RoadRunnerLaravel\Listeners\SendExceptionToStderrListener; | ||
|
||
/** | ||
* @covers \AvtoDev\RoadRunnerLaravel\Listeners\SendExceptionToStderrListener<extended> | ||
*/ | ||
class SendExceptionToStderrListenerTest extends AbstractListenerTestCase | ||
{ | ||
public function testHandle(): void | ||
{ | ||
$this->listenerFactory()->handle(new \stdClass); | ||
|
||
$this->markTestIncomplete('There is no legal way for handle method testing.'); | ||
} | ||
|
||
protected function listenerFactory() | ||
{ | ||
return new SendExceptionToStderrListener; | ||
} | ||
} |
Oops, something went wrong.