本文整理汇总了PHP中Rx\Observable::lift方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::lift方法的具体用法?PHP Observable::lift怎么用?PHP Observable::lift使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::lift方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* ConnectionSubject constructor.
* @param ObservableInterface $rawDataIn
* @param ObserverInterface $rawDataOut
* @param bool $mask
* @param bool $useMessageObject
* @param string $subProtocol
* @param RequestInterface $request
* @param ResponseInterface $response
*/
public function __construct(ObservableInterface $rawDataIn, ObserverInterface $rawDataOut, $mask = false, $useMessageObject = false, $subProtocol = "", RequestInterface $request, ResponseInterface $response)
{
$this->request = $request;
$this->response = $response;
$this->rawDataIn = new AnonymousObservable(function ($observer) use($rawDataIn) {
return $rawDataIn->subscribe($observer);
});
$this->rawDataOut = $rawDataOut;
$this->mask = $mask;
$this->subProtocol = $subProtocol;
// This can be used instead of the subjecg when this issue is addressed:
// https://github.com/asm89/Rx.PHP/issues/20
// Actually - using the subject is better so that the framing doesn't get done for every
// subscriber.
//$frames = $this->rawDataIn
// ->lift(new WebsocketFrameOperator());
$frames = new Subject();
$this->rawDataIn->lift(function () {
return new WebsocketFrameOperator();
})->subscribe(new CallbackObserver([$frames, "onNext"], function ($error) use($frames) {
$close = $this->createCloseFrame();
if ($error instanceof WebsocketErrorException) {
$close = $this->createCloseFrame($error->getCloseCode());
}
$this->sendFrame($close);
$this->rawDataOut->onCompleted();
// TODO: Should this error through to frame observers?
$frames->onCompleted();
}, function () use($frames) {
$this->rawDataOut->onCompleted();
$frames->onCompleted();
}));
$this->controlFrames = $frames->filter(function (Frame $frame) {
return $frame->getOpcode() > 2;
});
// default ping handler (ping received from far end
$this->controlFrames->filter(function (Frame $frame) {
return $frame->getOpcode() === $frame::OP_PING;
})->subscribe(new CallbackObserver(function (Frame $frame) {
$pong = new Frame($frame->getPayload(), true, Frame::OP_PONG);
$this->sendFrame($pong);
}));
$frames->filter(function (Frame $frame) {
return $frame->getOpcode() < 3;
})->lift(function () use($mask, $useMessageObject) {
return new WebsocketMessageOperator($mask, $useMessageObject);
})->subscribe(new CallbackObserver(function ($x) {
parent::onNext($x);
}, function ($x) {
parent::onError($x);
}, function () {
parent::onCompleted();
}));
$this->subProtocol = $subProtocol;
}