Accept exception factory for performance gains
This commit is contained in:
		
							parent
							
								
									3c3588fc8b
								
							
						
					
					
						commit
						1579666238
					
				| @ -53,15 +53,15 @@ class MessageStreamer { | ||||
|         CloseFrameChecker $frameChecker, | ||||
|         callable $onMessage, | ||||
|         callable $onControl = null, | ||||
|         $expectMask = true | ||||
|         $expectMask = true, | ||||
|         $exceptionFactory = null | ||||
|     ) { | ||||
|         $this->validator = $encodingValidator; | ||||
|         $this->closeFrameChecker = $frameChecker; | ||||
|         $this->checkForMask = (bool)$expectMask; | ||||
| 
 | ||||
|         $exception = new \UnderflowException; | ||||
|         $this->exceptionFactory = function() use ($exception) { | ||||
|             return $exception; | ||||
|         $this->exceptionFactory ?: $this->exceptionFactory = function($msg) { | ||||
|             return new \UnderflowException($msg); | ||||
|         }; | ||||
| 
 | ||||
|         $this->onMessage = $onMessage; | ||||
|  | ||||
| @ -13,7 +13,9 @@ $encodingValidator = new \Ratchet\RFC6455\Encoding\Validator; | ||||
| $closeFrameChecker = new \Ratchet\RFC6455\Messaging\Protocol\CloseFrameChecker; | ||||
| $negotiator = new \Ratchet\RFC6455\Handshake\Negotiator($encodingValidator); | ||||
| 
 | ||||
| $server->on('request', function (\React\Http\Request $request, \React\Http\Response $response) use ($negotiator, $encodingValidator, $closeFrameChecker) { | ||||
| $uException = new \UnderflowException; | ||||
| 
 | ||||
| $server->on('request', function (\React\Http\Request $request, \React\Http\Response $response) use ($negotiator, $encodingValidator, $closeFrameChecker, $uException) { | ||||
|     $psrRequest = new \GuzzleHttp\Psr7\Request($request->getMethod(), $request->getPath(), $request->getHeaders()); | ||||
| 
 | ||||
|     $negotiatorResponse = $negotiator->handshake($psrRequest); | ||||
| @ -42,6 +44,8 @@ $server->on('request', function (\React\Http\Request $request, \React\Http\Respo | ||||
|                 $response->write($parser->newFrame($frame->getPayload(), true, Frame::OP_PONG)->getContents()); | ||||
|                 break; | ||||
|         } | ||||
|     }, true, function() use ($uException) { | ||||
|         return $uException; | ||||
|     }); | ||||
| 
 | ||||
|     $request->on('data', [$parser, 'onData']); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Chris Boden
						Chris Boden