本文整理汇总了PHP中Rx\Observable::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::fromArray方法的具体用法?PHP Observable::fromArray怎么用?PHP Observable::fromArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::fromArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
});
}
示例2: 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);
});
}
示例3: 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);
});
}
示例4: 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());
}
示例5: await_multiple
/**
* @test
*/
public function await_multiple()
{
$array = [1, 2, 3];
$observable = Observable::fromArray($array);
$generator = \Rx\await($observable);
$result = [];
foreach ($generator as $item) {
$result[] = $item;
}
$this->assertEquals($array, $result);
$this->assertEquals(count($result), 3);
}
示例6: findSavingsAccountObs
function findSavingsAccountObs($userId)
{
return Observable::just($userId)->skipWhile(function ($input) {
return empty($input);
})->map(function ($userId) {
return User::find($userId);
})->flatMap(function (User $user) {
return Observable::fromArray(Account::query('user_id', $user->getId()));
})->takeWhile(function (Account $account) {
return $account->getType() === 'SAVINGS';
});
}
示例7: __invoke
/**
* @param \Rx\ObservableInterface $observable
* @param \Rx\ObserverInterface $observer
* @param \Rx\SchedulerInterface $scheduler
* @return \Rx\DisposableInterface
*/
public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
{
$buffer = "";
return $observable->defaultIfEmpty(Observable::just(null))->concat(Observable::just($this->delimiter))->concatMap(function ($x) use(&$buffer) {
if ($x === null || $buffer === null) {
$buffer = null;
return Observable::emptyObservable();
}
$items = explode($this->delimiter, $buffer . $x);
$buffer = array_pop($items);
return Observable::fromArray($items);
})->subscribe($observer, $scheduler);
}
示例8:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::fromArray([24, 42, 24, 24])->distinctUntilChanged();
$subscription = $source->subscribe($stdoutObserver);
//Next value: 24
//Next value: 42
//Next value: 24
//Complete!
示例9:
<?php
require_once __DIR__ . "/../bootstrap.php";
/* Without comparer */
$source = \Rx\Observable::fromArray([1, 3, 5, 7, 9, 2, 4, 6, 8])->min();
$subscription = $source->subscribe($createStdoutObserver());
示例10: println
println('Example 3 - Just and Map');
\Rx\Observable::just(\Model\User::all())->map(function ($results) {
return count($results);
})->subscribe($stdoutObserver());
println('Example 4 - Get all accounts of type SAVING');
\Rx\Observable::fromArray(\Model\Account::all())->filter(function (Account $account) {
return $account->getType() === 'SAVINGS';
})->map(function (Account $savingsAccount) {
return $savingsAccount->getBalance();
})->subscribe($stdoutObserver());
println('Withdraw 1000 from Luis SAVINGS account');
$id = 1;
Observable::just($id)->map(function ($userId) {
return User::find($userId);
})->doOnNext(function (User $user) {
printf("Found user: %s \n", $user->getEmail());
})->flatMap(function (User $user) {
return Observable::fromArray(Account::query('user_id', $user->getId()));
})->takeWhile(function (Account $account) {
return $account->getType() === 'SAVINGS';
})->doOnNext(function (Account $account) {
printf("Found savings account. Current balance: %d \n", $account->getBalance());
})->map(function (Account $account) {
return $account->withdraw(1000)->save();
})->subscribe(new Observer\CallbackObserver(function ($account) {
printf("New account balance: %d \n", $account->getBalance());
}, function (Exception $ex) {
print 'Error: ' . $ex->getMessage();
}, function () {
print 'Completed!';
}));
示例11:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::fromArray([['id' => '42'], ['id' => '24'], ['id' => '42'], ['id' => '24']])->distinctKey(function ($x) {
return $x['id'];
})->map(function ($x) {
return $x['id'];
});
$subscription = $source->subscribe($stdoutObserver);
示例12:
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::fromArray([['id' => '24'], ['id' => '42'], ['id' => '24'], ['id' => '24']])->distinctUntilKeyChanged(function ($x) {
return $x['id'];
})->map(function ($x) {
return $x['id'];
});
$subscription = $source->subscribe($stdoutObserver);
示例13: json_decode
})->map(function ($tweet) {
return json_decode($tweet);
});
$endTwitterStream = $allTweets->filter(function ($tweet) {
return is_object($tweet);
})->filter(function ($tweet) {
return trim($tweet->text) == 'exit();';
})->doOnNext(function ($twitter) {
echo 'exit(); found, stopping...', PHP_EOL;
});
$usersTweets = $allTweets->filter(function ($tweet) {
return isset($tweet->user->screen_name);
});
$tweets = $usersTweets->takeUntil($endTwitterStream);
$urls = $tweets->flatMap(function ($tweet) {
return \Rx\Observable::fromArray($tweet->entities->urls);
});
$measurementsSubscription = $urls->filter(function ($url) {
return substr($url->expanded_url, 0, 36) == 'https://atlas.ripe.net/measurements/';
})->map(function ($url) {
return trim(substr($url->expanded_url, 36), '/');
})->flatMap(function ($id) {
return \Rx\React\Http::get("https://atlas.ripe.net/api/v1/measurement/{$id}/");
})->map(function ($data) {
return json_decode($data);
})->subscribeCallback(function ($json) {
echo 'Measurement #', $json->msm_id, ' "', $json->description, '" had ', $json->participant_count, ' nodes involved', PHP_EOL;
}, function (\Rx\React\HttpResponseException $e) {
echo "Error: ", $e->getMessage(), PHP_EOL;
}, function () {
echo "complete", PHP_EOL;
示例14: function
<?php
require_once __DIR__ . '/../bootstrap.php';
//With a result selector
$range = \Rx\Observable::fromArray(range(0, 4));
$source = $range->zip([$range->skip(1), $range->skip(2)], function ($s1, $s2, $s3) {
return $s1 . ':' . $s2 . ':' . $s3;
});
$observer = $createStdoutObserver();
$subscription = $source->subscribe($createStdoutObserver());
示例15: use
<?php
require_once __DIR__ . '/../bootstrap.php';
$count = 0;
$observable = \Rx\Observable::fromArray(range(1, 5))->flatMap(function ($x) use(&$count) {
if (++$count < 2) {
return new \Rx\Observable\ErrorObservable(new \Exception("Something"));
}
return new \Rx\Observable\ReturnObservable($x);
})->retry(3)->take(1);
$observable->subscribe($stdoutObserver);