Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87041b6
commit f7f55e1
Showing
18 changed files
with
482 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7 | ||
- hhvm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Wikibase\JsonDumpReader; | ||
|
||
use RuntimeException; | ||
|
||
/** | ||
* Package public | ||
* @since 1.0.0 | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class DumpReadingException extends RuntimeException { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Wikibase\JsonDumpReader\Iterator; | ||
|
||
use Iterator; | ||
|
||
/** | ||
* Package private | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class ObjectDumpIterator implements Iterator { | ||
|
||
/** | ||
* @var callable|null | ||
*/ | ||
private $errorReporter = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $current = null; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $key = 0; | ||
|
||
/** | ||
* @var Iterator | ||
*/ | ||
private $stringIterator; | ||
|
||
public function __construct( Iterator $stringIterator ) { | ||
$this->stringIterator = $stringIterator; | ||
} | ||
|
||
/** | ||
* @param callable|null $errorReporter | ||
*/ | ||
public function onError( callable $errorReporter = null ) { | ||
$this->errorReporter = $errorReporter; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function current() { | ||
return $this->current; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function next() { | ||
$data = $this->getNextFromString(); | ||
|
||
$this->current = $data; | ||
$this->key++; | ||
|
||
return $this->current; | ||
} | ||
|
||
private function getNextFromString() { | ||
while ( true ) { | ||
$jsonString = $this->stringIterator->current(); | ||
$this->stringIterator->next(); | ||
|
||
if ( $jsonString === null ) { | ||
return null; | ||
} | ||
|
||
$data = json_decode( $jsonString, true ); | ||
if ( $data === null ) { | ||
$this->reportError( json_last_error_msg() ); | ||
} | ||
else { | ||
return $data; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private function reportError( $errorMessage ) { | ||
if ( $this->errorReporter !== null ) { | ||
call_user_func( $this->errorReporter, $errorMessage ); | ||
} | ||
} | ||
|
||
public function key() { | ||
return $this->key; | ||
} | ||
|
||
public function valid() { | ||
return $this->current !== null; | ||
} | ||
|
||
public function rewind() { | ||
$this->current = null; | ||
$this->key = -1; | ||
$this->stringIterator->rewind(); | ||
$this->next(); | ||
} | ||
|
||
} |
Oops, something went wrong.