當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Rx\Observable類代碼示例

本文整理匯總了PHP中Rx\Observable的典型用法代碼示例。如果您正苦於以下問題:PHP Observable類的具體用法?PHP Observable怎麽用?PHP Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Observable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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);
     });
 }
開發者ID:remyhonig,項目名稱:PhotoOrganize,代碼行數:14,代碼來源:ImagesAndMoviesWithDateRepository.php

示例2: __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;
 }
開發者ID:RxPHP,項目名稱:RxWebsocket,代碼行數:65,代碼來源:MessageSubject.php

示例3: summarize

 /**
  * @param Observable $observable
  * @return Observable\AnonymousObservable
  */
 public function summarize(Observable $observable)
 {
     return $observable->groupBy(function (FileWithDate $file) {
         return $file->getDatePath();
     }, function (FileWithDate $file) {
         return $file->getDatePath();
     }, function ($key) {
         return $key;
     })->flatMap(function (GroupedObservable $g) {
         return $g->zip([$g->distinct(), $g->count()], function ($_, $b, $c) {
             return "Created {$b} with {$c} files";
         });
     });
 }
開發者ID:remyhonig,項目名稱:PhotoOrganize,代碼行數:18,代碼來源:SummaryRepository.php

示例4: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     if ($this->scheduler !== null) {
         $scheduler = $this->scheduler;
     }
     $innerDisp = new SerialDisposable();
     $disp = $observable->subscribe(new CallbackObserver(function ($x) use($innerDisp, $observer, $scheduler) {
         $now = $scheduler->now();
         if ($this->nextSend <= $now) {
             $innerDisp->setDisposable(new EmptyDisposable());
             $observer->onNext($x);
             $this->nextSend = $now + $this->throttleTime - 1;
             return;
         }
         $newDisp = Observable::just($x)->delay($this->nextSend - $now)->subscribe(new CallbackObserver(function ($x) use($observer, $scheduler) {
             $observer->onNext($x);
             $this->nextSend = $scheduler->now() + $this->throttleTime - 1;
             if ($this->completed) {
                 $observer->onCompleted();
             }
         }, [$observer, 'onError']), $scheduler);
         $innerDisp->setDisposable($newDisp);
     }, function (\Exception $e) use($observer, $innerDisp) {
         $innerDisp->dispose();
         $observer->onError($e);
     }, function () use($observer) {
         $this->completed = true;
         if ($this->nextSend === 0) {
             $observer->onCompleted();
         }
     }), $scheduler);
     return new CompositeDisposable([$disp, $innerDisp]);
 }
開發者ID:ReactiveX,項目名稱:RxPHP,代碼行數:36,代碼來源:ThrottleOperator.php

示例5: refCount_not_connected

 /**
  * @test
  */
 public function refCount_not_connected()
 {
     $disconnected = false;
     $count = 0;
     $xs = Observable::defer(function () use(&$count, &$disconnected) {
         $count++;
         return new AnonymousObservable(function () use(&$disconnected) {
             return new CallbackDisposable(function () use(&$disconnected) {
                 $disconnected = true;
             });
         });
     });
     $subject = new TestSubject();
     $conn = new ConnectableObservable($xs, $subject);
     $refd = $conn->refCount();
     $dis1 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(1, $count);
     $this->assertEquals(1, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis2 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(1, $count);
     $this->assertEquals(2, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis1->dispose();
     $this->assertFalse($disconnected);
     $dis2->dispose();
     $this->assertTrue($disconnected);
     $disconnected = false;
     $dis3 = $refd->subscribe(new CallbackObserver());
     $this->assertEquals(2, $count);
     $this->assertEquals(3, $subject->getSubscribeCount());
     $this->assertFalse($disconnected);
     $dis3->dispose();
     $this->assertTrue($disconnected);
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:38,代碼來源:PublishTest.php

示例6: range_dispose

 /**
  * @test
  */
 public function range_dispose()
 {
     $results = $this->scheduler->startWithDispose(function () {
         return Observable::range(-10, 5, $this->scheduler);
     }, 204);
     $this->assertMessages([onNext(201, -10), onNext(202, -9), onNext(203, -8)], $results->getMessages());
 }
開發者ID:ReactiveX,項目名稱:RxPHP,代碼行數:10,代碼來源:RangeTest.php

示例7: testAsObservableNever

 public function testAsObservableNever()
 {
     $results = $this->scheduler->startWithCreate(function () {
         return Observable::never()->asObservable();
     });
     $this->assertMessages([], $results->getMessages());
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:7,代碼來源:AsObservableTest.php

示例8: toObservable

 /**
  * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
  *
  * @param callable $factory
  * @return \Rx\Observable\AnonymousObservable
  */
 public static function toObservable(callable $factory)
 {
     $observableFactory = function () use($factory) {
         return Promise::toObservable($factory());
     };
     return Observable::defer($observableFactory);
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:13,代碼來源:PromiseFactory.php

示例9: never_basic

 /**
  * @test
  */
 public function never_basic()
 {
     $xs = Observable::never();
     $results = new MockObserver($this->scheduler);
     $xs->subscribe($results);
     $this->assertMessages([], $results->getMessages());
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:10,代碼來源:NeverTest.php

示例10: annotations

 /**
  * @return ObservableInterface
  */
 public function annotations() : ObservableInterface
 {
     return Promise::toObservable($this->getTransport()->request('jobs/' . $this->id() . '/annotations'))->flatMap(function ($response) {
         return Observable::fromArray($response['annotations']);
     })->map(function ($annotation) {
         return $this->getTransport()->getHydrator()->hydrate('Annotation', $annotation);
     });
 }
開發者ID:WyriHaximus,項目名稱:php-travis-client,代碼行數:11,代碼來源:Job.php

示例11: fromArray_dispose

 /**
  * @test
  */
 public function fromArray_dispose()
 {
     $xs = Observable::fromArray(['foo', 'bar', 'baz']);
     $results = $this->scheduler->startWithDispose(function () use($xs) {
         return $xs;
     }, 202);
     $this->assertMessages([onNext(201, 'foo')], $results->getMessages());
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:11,代碼來源:FromArrayTest.php

示例12: distinct_until_changed_never

 /**
  * @test
  */
 public function distinct_until_changed_never()
 {
     $results = $this->scheduler->startWithCreate(function () {
         $o = new EmptyObservable();
         return Observable::never()->distinctUntilChanged();
     });
     $this->assertMessages([], $results->getMessages());
 }
開發者ID:ReactiveX,項目名稱:RxPHP,代碼行數:11,代碼來源:DistinctUntilChangedTest.php

示例13: jobs

 /**
  * @return ObservableInterface
  */
 public function jobs() : ObservableInterface
 {
     return Promise::toObservable($this->getTransport()->request('builds/' . $this->id()))->flatMap(function ($response) {
         return Observable::fromArray($response['jobs']);
     })->map(function ($job) {
         return $this->getTransport()->getHydrator()->hydrate('Job', $job);
     });
 }
開發者ID:WyriHaximus,項目名稱:php-travis-client,代碼行數:11,代碼來源:Build.php

示例14: connect

 /**
  * @return \Rx\Disposable\BinaryDisposable
  */
 public function connect()
 {
     if ($this->hasSubscription) {
         return $this->subscription;
     }
     $this->hasSubscription = true;
     $isDisposed = false;
     $connectableDisposable = new CallbackDisposable(function () use(&$isDisposed) {
         if ($isDisposed) {
             return;
         }
         $isDisposed = true;
         $this->hasSubscription = false;
     });
     $this->subscription = new BinaryDisposable($this->sourceObservable->subscribe($this->subject, $this->scheduler), $connectableDisposable);
     return $this->subscription;
 }
開發者ID:voryx,項目名稱:Rx.PHP,代碼行數:20,代碼來源:ConnectableObservable.php

示例15: commits

 public function commits() : ObservableInterface
 {
     return Promise::toObservable($this->getTransport()->request('repos/' . $this->slug() . '/builds'))->flatMap(function ($response) {
         return Observable::fromArray($response['commits']);
     })->map(function ($build) {
         return $this->getTransport()->getHydrator()->hydrate('Commit', $build);
     });
 }
開發者ID:localheinz,項目名稱:php-travis-client,代碼行數:8,代碼來源:Repository.php


注:本文中的Rx\Observable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。