当前位置: 首页>>代码示例>>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;未经允许,请勿转载。