本文整理汇总了PHP中Rx\Observable::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::filter方法的具体用法?PHP Observable::filter怎么用?PHP Observable::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: extractDateFrom
/**
* @param Observable $observable
*
* @return Observable
*/
public function extractDateFrom(Observable $observable)
{
return $observable->filter(function (SplFileInfo $file) {
return in_array(strtolower($file->getExtension()), ['jpg', 'jpeg', 'mp4']);
})->map(function (SplFileInfo $file) {
$date = $this->imageDateRepository->extractDate($file);
return new FileWithDate($file, $date);
});
}