Skip to content

Commit e95d702

Browse files
committed
initial
0 parents  commit e95d702

14 files changed

+647
-0
lines changed

.gitignore

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

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: php
2+
php:
3+
- nightly
4+
- hhvm
5+
- 7.1
6+
- 7.0
7+
- 5.6
8+
- 5.5
9+
- 5.4
10+
11+
sudo: false
12+
13+
before_script:
14+
- composer install --dev --no-interaction
15+
16+
matrix:
17+
allow_failures:
18+
- php: hhvm
19+
- php: nightly
20+
fast_finish: true
21+
22+
script:
23+
- ./vendor/bin/phpunit -v --configuration phpunit.xml --coverage-text ./tests/
24+
25+
cache:
26+
directories:
27+
- $HOME/.composer/cache

LICENSE

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

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# phperf/pipeline
2+
3+
Data processing pipeline
4+
5+
[![Build Status](https://travis-ci.org/phperf/pipeline.svg?branch=master)](https://travis-ci.org/phperf/pipeline)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phperf/pipeline/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phperf/pipeline/?branch=master)
7+
[![Code Climate](https://codeclimate.com/github/phperf/pipeline/badges/gpa.svg)](https://codeclimate.com/github/phperf/pipeline)
8+
9+
## Installation
10+
11+
```
12+
composer require phperf/pipeline
13+
```
14+
15+
## Usage
16+
17+
TBD

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "phperf/pipeline",
3+
"description": "Data processing pipeline",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Viacheslav Poturaev",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Phperf\\Pipeline\\": "src/"
17+
}
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^4.0"
21+
}
22+
}

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
colors="true"
4+
processIsolation="false"
5+
stopOnFailure="false"
6+
syntaxCheck="false"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader">
11+
12+
<testsuites>
13+
<testsuite name="Tests">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist processUncoveredFilesFromWhitelist="true">
19+
<directory suffix=".php">./src/</directory>
20+
</whitelist>
21+
</filter>
22+
23+
</phpunit>

src/Page/PageIterator.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Phperf\Pipeline\Page;
4+
5+
use ArrayIterator;
6+
use Iterator;
7+
8+
class PageIterator implements Iterator
9+
{
10+
private $iterators;
11+
/**
12+
* @var Iterator
13+
*/
14+
private $currentIterator;
15+
16+
function __construct(Iterator $iterators)
17+
{
18+
$this->iterators = $iterators;
19+
}
20+
21+
/**
22+
* (PHP 5 &gt;= 5.0.0)<br/>
23+
* Return the current element
24+
* @link http://php.net/manual/en/iterator.current.php
25+
* @return mixed Can return any type.
26+
*/
27+
public function current()
28+
{
29+
return $this->currentIterator->current();
30+
}
31+
32+
/**
33+
* (PHP 5 &gt;= 5.0.0)<br/>
34+
* Move forward to next element
35+
* @link http://php.net/manual/en/iterator.next.php
36+
* @return void Any returned value is ignored.
37+
*/
38+
public function next()
39+
{
40+
$this->currentIterator->next();
41+
}
42+
43+
/**
44+
* (PHP 5 &gt;= 5.0.0)<br/>
45+
* Return the key of the current element
46+
* @link http://php.net/manual/en/iterator.key.php
47+
* @return mixed scalar on success, or null on failure.
48+
*/
49+
public function key()
50+
{
51+
//echo 'k';
52+
return $this->currentIterator->key();
53+
}
54+
55+
/**
56+
* (PHP 5 &gt;= 5.0.0)<br/>
57+
* Checks if current position is valid
58+
* @link http://php.net/manual/en/iterator.valid.php
59+
* @return boolean The return value will be casted to boolean and then evaluated.
60+
* Returns true on success or false on failure.
61+
*/
62+
public function valid()
63+
{
64+
$v = $this->currentIterator->valid();
65+
if (!$v) {
66+
do {
67+
$this->iterators->next();
68+
if ($this->iterators->valid()) {
69+
$this->currentIterator = $this->iterators->current();
70+
$this->currentIterator->rewind();
71+
}
72+
} while ($this->iterators->valid() && !$this->currentIterator->valid());
73+
74+
if (!$this->currentIterator->valid()) {
75+
return false;
76+
} else {
77+
return true;
78+
}
79+
}
80+
81+
return $v;
82+
}
83+
84+
/**
85+
* (PHP 5 &gt;= 5.0.0)<br/>
86+
* Rewind the Iterator to the first element
87+
* @link http://php.net/manual/en/iterator.rewind.php
88+
* @return void Any returned value is ignored.
89+
*/
90+
public function rewind()
91+
{
92+
$this->iterators->rewind();
93+
if (!$this->iterators->valid()) {
94+
$this->currentIterator = new ArrayIterator(array());
95+
} else {
96+
$this->currentIterator = $this->iterators->current();
97+
}
98+
$this->currentIterator->rewind();
99+
}
100+
101+
}

src/Rows/ClosureIterator.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Phperf\Pipeline\Rows;
4+
5+
use Closure;
6+
use Iterator;
7+
8+
class ClosureIterator implements Iterator
9+
{
10+
/**
11+
* @var callable
12+
*/
13+
private $source;
14+
private $currentIterator;
15+
16+
public function __construct(Closure $source)
17+
{
18+
$this->source = $source;
19+
}
20+
21+
/**
22+
* (PHP 5 &gt;= 5.0.0)<br/>
23+
* Return the current element
24+
* @link http://php.net/manual/en/iterator.current.php
25+
* @return mixed Can return any type.
26+
*/
27+
public function current()
28+
{
29+
return $this->currentIterator;
30+
}
31+
32+
/**
33+
* (PHP 5 &gt;= 5.0.0)<br/>
34+
* Move forward to next element
35+
* @link http://php.net/manual/en/iterator.next.php
36+
* @return void Any returned value is ignored.
37+
*/
38+
public function next()
39+
{
40+
$c = $this->source;
41+
$this->currentIterator = $c();
42+
}
43+
44+
/**
45+
* (PHP 5 &gt;= 5.0.0)<br/>
46+
* Return the key of the current element
47+
* @link http://php.net/manual/en/iterator.key.php
48+
* @return mixed scalar on success, or null on failure.
49+
*/
50+
public function key()
51+
{
52+
return '';
53+
}
54+
55+
/**
56+
* (PHP 5 &gt;= 5.0.0)<br/>
57+
* Checks if current position is valid
58+
* @link http://php.net/manual/en/iterator.valid.php
59+
* @return boolean The return value will be casted to boolean and then evaluated.
60+
* Returns true on success or false on failure.
61+
*/
62+
public function valid()
63+
{
64+
return (bool)$this->currentIterator;
65+
}
66+
67+
/**
68+
* (PHP 5 &gt;= 5.0.0)<br/>
69+
* Rewind the Iterator to the first element
70+
* @link http://php.net/manual/en/iterator.rewind.php
71+
* @return void Any returned value is ignored.
72+
*/
73+
public function rewind()
74+
{
75+
$c = $this->source;
76+
$this->currentIterator = $c();
77+
}
78+
79+
}

0 commit comments

Comments
 (0)