Skip to content

Commit 68637bb

Browse files
committed
Initial Commit
0 parents  commit 68637bb

File tree

16 files changed

+779
-0
lines changed

16 files changed

+779
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
sudo: required
3+
4+
php:
5+
- 5.6
6+
- 7
7+
- hhvm
8+
9+
matrix:
10+
allow_failures:
11+
- php: hhvm
12+
13+
install:
14+
- composer install
15+
16+
script:
17+
- phpunit

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Voryx LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Stream Component
2+
3+
Provides RxPHP Observables for PHP streams
4+
5+
This library is a wrapper around the [ReactPHP](https://github.com/reactphp/stream) stream library. It uses the [Voryx event-loop](https://github.com/voryx/event-loop) which behaves like the Javascript event-loop. ie. You don't need to start it.
6+
7+
8+
## Usage
9+
10+
### From File
11+
```php
12+
13+
$source = new \Rx\React\FromFileObservable("example.csv");
14+
15+
$source
16+
->cut()
17+
->map(function ($row) {
18+
//Convert csv row to an array
19+
return str_getcsv($row);
20+
})
21+
->map(function (array $row) {
22+
//Strip numbers from the first field
23+
$row[0] = preg_replace('/\d+/u', '', $row[0]);
24+
return $row;
25+
})
26+
->subscribe(new \Rx\Observer\CallbackObserver(
27+
function ($data) {
28+
echo $data[0] . "\n";
29+
},
30+
function ($e) {
31+
echo "error\n";
32+
},
33+
function () {
34+
echo "done\n";
35+
}
36+
));
37+
38+
```

composer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "rx/stream",
3+
"type": "library",
4+
"description": "Async Stream for RxPHP",
5+
"keywords": [
6+
"rxphp",
7+
"reactivex",
8+
"react",
9+
"reactphp",
10+
"stream",
11+
"rx.php"
12+
],
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "David Dan",
17+
"email": "[email protected]",
18+
"role": "Developer"
19+
},
20+
{
21+
"name": "Matt Bonneau",
22+
"email": "[email protected]",
23+
"role": "Developer"
24+
}
25+
],
26+
"autoload": {
27+
"psr-4": {
28+
"Rx\\React\\": "src/"
29+
}
30+
},
31+
"require": {
32+
"voryx/event-loop": "^0.2.0",
33+
"react/stream": "^0.4.3",
34+
"asm89/rx.php": "dev-master"
35+
},
36+
"repositories": [
37+
{
38+
"type": "git",
39+
"url": "https://github.com/voryx/Rx.PHP.git"
40+
}
41+
]
42+
}

examples/fromFile/fromFile.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
include __DIR__ . "/../../vendor/autoload.php";
4+
5+
$source = new \Rx\React\FromFileObservable(__DIR__ . "/../test.csv");
6+
7+
$source
8+
->subscribe(new \Rx\Observer\CallbackObserver(
9+
function ($data) {
10+
echo $data . "\n";
11+
},
12+
function ($e) {
13+
echo "error\n";
14+
},
15+
function () {
16+
echo "done\n";
17+
}
18+
));
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
include __DIR__ . "/../../vendor/autoload.php";
4+
5+
$source = new \Rx\React\FromFileObservable(__DIR__ . "/../test.csv");
6+
7+
$source
8+
->cut()
9+
->subscribe(new \Rx\Observer\CallbackObserver(
10+
function ($data) {
11+
echo $data . "\n";
12+
},
13+
function ($e) {
14+
echo "error\n";
15+
},
16+
function () {
17+
echo "done\n";
18+
}
19+
));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
include __DIR__ . "/../../vendor/autoload.php";
4+
5+
$source = new \Rx\React\FromFileObservable(__DIR__ . "/../test.csv");
6+
7+
$source
8+
->cut()
9+
->map(function ($row) {
10+
return str_getcsv($row);
11+
})
12+
->toArray()
13+
->subscribe(new \Rx\Observer\CallbackObserver(
14+
function (array $array) {
15+
var_dump($array);
16+
},
17+
function ($e) {
18+
echo "error\n";
19+
},
20+
function () {
21+
echo "done\n";
22+
}
23+
));

examples/test.csv

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
playerID,yearID,stint,teamID,lgID,G,AB,R,H,2B,3B,HR,RBI,SB,CS,BB,SO,IBB,HBP,SH,SF,GIDP
2+
abercda01,1871,1,TRO,NA,1,4,0,0,0,0,0,0,0,0,0,0,,,,,
3+
addybo01,1871,1,RC1,NA,25,118,30,32,6,0,0,13,8,1,4,0,,,,,
4+
allisar01,1871,1,CL1,NA,29,137,28,40,4,5,0,19,3,1,2,5,,,,,
5+
allisdo01,1871,1,WS3,NA,27,133,28,44,10,2,2,27,1,1,0,2,,,,,
6+
ansonca01,1871,1,RC1,NA,25,120,29,39,11,3,0,16,6,2,2,1,,,,,
7+
armstbo01,1871,1,FW1,NA,12,49,9,11,2,1,0,5,0,1,0,1,,,,,
8+
barkeal01,1871,1,RC1,NA,1,4,0,1,0,0,0,2,0,0,1,0,,,,,
9+
barnero01,1871,1,BS1,NA,31,157,66,63,10,9,0,34,11,6,13,1,,,,,
10+
barrebi01,1871,1,FW1,NA,1,5,1,1,1,0,0,1,0,0,0,0,,,,,
11+
barrofr01,1871,1,BS1,NA,18,86,13,13,2,1,0,11,1,0,0,0,,,,,
12+
bassjo01,1871,1,CL1,NA,22,89,18,27,1,10,3,18,0,1,3,4,,,,,
13+
battijo01,1871,1,CL1,NA,1,3,0,0,0,0,0,0,0,0,1,0,,,,,
14+
bealsto01,1871,1,WS3,NA,10,36,6,7,0,0,0,1,2,0,2,0,,,,,
15+
beaveed01,1871,1,TRO,NA,3,15,7,6,0,0,0,5,2,0,0,0,,,,,
16+
bechtge01,1871,1,PH1,NA,20,94,24,33,9,1,1,21,4,0,2,2,,,,,
17+
bellast01,1871,1,TRO,NA,29,128,26,32,3,3,0,23,4,4,9,2,,,,,
18+
berkena01,1871,1,PH1,NA,1,4,0,0,0,0,0,0,0,0,0,3,,,,,

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="tests/bootstrap.php">
13+
<testsuites>
14+
<testsuite name="Rx/Stream Tests">
15+
<directory>tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
</phpunit>

0 commit comments

Comments
 (0)