Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit dfdaaa8

Browse files
tPl0chmdio
authored andcommitted
Ported changes from wikimedia (incl. logical types) and CI integration (#5)
1 parent 922a5d9 commit dfdaaa8

34 files changed

+3220
-215
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor/
2-
2+
composer.lock
3+
!bin/php
4+
!build/.gitkeep

.travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
dist: trusty
2+
sudo: required
3+
language: php
4+
5+
php:
6+
- '7.1'
7+
- '7.2'
8+
- '7.3'
9+
10+
before_script:
11+
- composer self-update
12+
- composer update
13+
14+
script:
15+
- COMPOSER=composer PHP=php make phpunit
16+
17+
after_script:
18+
- make clean
19+
20+
branches:
21+
only:
22+
- master
23+
- '/^ft-.*/'
24+
- '/^\d+\.\d+\.\d+$/'
25+
26+
cache:
27+
directories:
28+
- $HOME/.composer/cache/files

Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG PHP_VERSION=7.1
2+
3+
FROM php:${PHP_VERSION}-cli-alpine
4+
5+
ARG XDEBUG_VERSION=2.7.0RC1
6+
7+
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
8+
&& apk add --no-cache --virtual .runtime-deps git libzip-dev \
9+
&& docker-php-ext-install zip \
10+
&& pecl install xdebug-$XDEBUG_VERSION \
11+
&& docker-php-ext-enable xdebug \
12+
&& echo "xdebug.max_nesting_level=15000" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
13+
&& echo "xdebug.remote_enable=true" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
14+
&& echo "xdebug.remote_host=localhost" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
15+
&& echo "xdebug.idekey=PHPSTORM" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
16+
&& echo "xdebug.remote_handler=dbgp" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
17+
&& echo "xdebug.remote_autostart=1" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
18+
&& echo "xdebug.remote_connect_back=0" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
19+
&& apk del .build-deps

Makefile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# no buildin rules and variables
2+
MAKEFLAGS =+ -rR --warn-undefined-variables
3+
4+
.PHONY: composer-install composer-update examples docker run
5+
6+
COMPOSER ?= bin/composer.phar
7+
COMPOSER_VERSION ?= 1.8.3
8+
PHP ?= bin/php
9+
PHP_VERSION ?= 7.2
10+
XDEBUG_VERSION ?= 2.7.0RC1
11+
12+
export
13+
14+
docker:
15+
docker build \
16+
--build-arg PHP_VERSION=$(PHP_VERSION) \
17+
--build-arg XDEBUG_VERSION=$(XDEBUG_VERSION) \
18+
-t avro-php:$(PHP_VERSION) \
19+
-f Dockerfile \
20+
.
21+
22+
composer-install:
23+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(COMPOSER) install --no-interaction --no-progress --no-suggest --no-scripts
24+
25+
composer-update:
26+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(COMPOSER) update --no-interaction --no-progress --no-suggest --no-scripts
27+
28+
phpunit:
29+
@mkdir -p build/tmp build/share/test/schemas build/build/interop/data
30+
@chmod -R a+w build
31+
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit --coverage-text test/AllTests.php
32+
33+
run:
34+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(ARGS)
35+
36+
examples:
37+
PHP_VERSION=$(PHP_VERSION) $(PHP) examples/*
38+
39+
install-phars:
40+
curl https://getcomposer.org/download/$(COMPOSER_VERSION)/composer.phar -o bin/composer.phar -LR -z bin/composer.phar
41+
chmod a+x bin/composer.phar
42+
43+
install: install-phars docker composer-install
44+
45+
clean:
46+
rm -r build/*

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A library for using [Avro](http://avro.apache.org/) with PHP.
55

66
Requirements
77
============
8-
* PHP >= 5.5
8+
* PHP >= 7.1
99
* On 32-bit platforms, the [GMP PHP extension](http://php.net/gmp)
1010
* For testing, [PHPUnit](http://www.phpunit.de/)
1111

bin/php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
command -v docker >/dev/null 2>&1 || { echo "docker is required to run this binary. Aborting." >&2; exit 1; }
6+
7+
USER=${USER:-$( id -un )}
8+
GROUP=${GROUP:-$( id -gn )}
9+
COMPOSER_HOME=${COMPOSER_HOME:-${HOME}/.composer}
10+
PHP_VERSION=${PHP_VERSION:-7.1}
11+
DOCKER_OPTS=${DOCKER_OPTS:-'-it'}
12+
13+
exec docker run ${DOCKER_OPTS} --rm \
14+
-u $( id -u ${USER} ):$( id -g ${USER} ) \
15+
-v "${PWD}":"${PWD}" \
16+
-v "${COMPOSER_HOME}":/tmp/composer \
17+
-w ${PWD} \
18+
-e PHP_IDE_CONFIG="serverName=avro-php" \
19+
-e COMPOSER_HOME="/tmp/composer" \
20+
--net=host --sig-proxy=true --pid=host \
21+
--entrypoint="php" \
22+
avro-php:${PHP_VERSION} "${@}"

build/.gitkeep

Whitespace-only changes.

composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"description": "Composer packaging for vanilla Apache Avro, with fixes",
44
"license": "Apache-2.0",
55
"require": {
6-
"php": ">=5.5.0"
6+
"php": ">=7.1"
7+
},
8+
"require-dev": {
9+
"phpunit/phpunit": "^5.0"
10+
},
11+
"suggest": {
12+
"ext-gmp": "Large integer support for 32-bit platforms."
713
},
814
"autoload": {
915
"classmap": ["lib/"]

lib/avro.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
*/
3333
class AvroException extends Exception {}
3434

35+
/**
36+
* Unimplemented feature exception.
37+
* @package Avro
38+
*/
39+
class AvroNotImplementedException extends AvroException {}
40+
3541
/**
3642
* Library-level class for PHP Avro port.
3743
*
@@ -113,7 +119,7 @@ private static function check_64_bit()
113119
}
114120

115121
/**
116-
* @returns boolean true if the PHP GMP extension is used and false otherwise.
122+
* @return boolean true if the PHP GMP extension is used and false otherwise.
117123
* @internal Requires Avro::check_64_bit() (exposed via Avro::check_platform())
118124
* to have been called to set Avro::$biginteger_mode.
119125
*/
@@ -161,7 +167,7 @@ private static function set_endianness()
161167
}
162168

163169
/**
164-
* @returns boolean true if the host platform is big endian
170+
* @return boolean true if the host platform is big endian
165171
* and false otherwise.
166172
* @uses self::set_endianness()
167173
*/
@@ -174,7 +180,7 @@ private static function is_big_endian_platform()
174180
}
175181

176182
/**
177-
* @returns boolean true if the host platform is little endian,
183+
* @return boolean true if the host platform is little endian,
178184
* and false otherwise.
179185
* @uses self::is_bin_endian_platform()
180186
*/

lib/avro/data_file.php

+33-23
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ class AvroDataIO
8686
private static $metadata_schema;
8787

8888
/**
89-
* @returns the initial "magic" segment of an Avro container file header.
89+
* @return string the initial "magic" segment of an Avro container file header.
9090
*/
9191
public static function magic() { return ('Obj' . pack('c', self::VERSION)); }
9292

9393
/**
94-
* @returns int count of bytes in the initial "magic" segment of the
94+
* @return int count of bytes in the initial "magic" segment of the
9595
* Avro container file header
9696
*/
9797
public static function magic_size() { return strlen(self::magic()); }
9898

9999

100100
/**
101-
* @returns AvroSchema object of Avro container file metadata.
101+
* @return AvroSchema object of Avro container file metadata.
102102
*/
103103
public static function metadata_schema()
104104
{
@@ -111,7 +111,7 @@ public static function metadata_schema()
111111
* @param string $file_path file_path of file to open
112112
* @param string $mode one of AvroFile::READ_MODE or AvroFile::WRITE_MODE
113113
* @param string $schema_json JSON of writer's schema
114-
* @returns AvroDataIOWriter instance of AvroDataIOWriter
114+
* @return AvroDataIOWriter instance of AvroDataIOWriter
115115
*
116116
* @throws AvroDataIOException if $writers_schema is not provided
117117
* or if an invalid $mode is given.
@@ -122,7 +122,6 @@ public static function open_file($file_path, $mode=AvroFile::READ_MODE,
122122
$schema = !is_null($schema_json)
123123
? AvroSchema::parse($schema_json) : null;
124124

125-
$io = false;
126125
switch ($mode)
127126
{
128127
case AvroFile::WRITE_MODE:
@@ -144,7 +143,7 @@ public static function open_file($file_path, $mode=AvroFile::READ_MODE,
144143
}
145144

146145
/**
147-
* @returns array array of valid codecs
146+
* @return array array of valid codecs
148147
*/
149148
private static function valid_codecs()
150149
{
@@ -153,7 +152,7 @@ private static function valid_codecs()
153152

154153
/**
155154
* @param string $codec
156-
* @returns boolean true if $codec is a valid codec value and false otherwise
155+
* @return boolean true if $codec is a valid codec value and false otherwise
157156
*/
158157
public static function is_valid_codec($codec)
159158
{
@@ -163,7 +162,7 @@ public static function is_valid_codec($codec)
163162
/**
164163
* @param AvroIO $io
165164
* @param AvroSchema $schema
166-
* @returns AvroDataIOWriter
165+
* @return AvroDataIOWriter
167166
*/
168167
protected static function open_writer($io, $schema)
169168
{
@@ -174,7 +173,7 @@ protected static function open_writer($io, $schema)
174173
/**
175174
* @param AvroIO $io
176175
* @param AvroSchema $schema
177-
* @returns AvroDataIOReader
176+
* @return AvroDataIOReader
178177
*/
179178
protected static function open_reader($io, $schema)
180179
{
@@ -209,12 +208,12 @@ class AvroDataIOReader
209208
/**
210209
* @var string
211210
*/
212-
private $sync_marker;
211+
public $sync_marker;
213212

214213
/**
215214
* @var array object container metadata
216215
*/
217-
private $metadata;
216+
public $metadata;
218217

219218
/**
220219
* @var int count of items in block
@@ -278,30 +277,28 @@ private function read_header()
278277

279278
/**
280279
* @internal Would be nice to implement data() as an iterator, I think
281-
* @returns \Generator
280+
* @return array of data from object container.
282281
*/
283282
public function data()
284283
{
284+
$data = array();
285285
while (true)
286286
{
287287
if (0 == $this->block_count)
288288
{
289-
if ($this->is_eof()) {
289+
if ($this->is_eof())
290290
break;
291-
}
292291

293-
if ($this->skip_sync()) {
294-
if ($this->is_eof()) {
292+
if ($this->skip_sync())
293+
if ($this->is_eof())
295294
break;
296-
}
297-
}
298295

299296
$this->read_block_header();
300297
}
301-
$data = $this->datum_reader->read($this->decoder);
298+
$data []= $this->datum_reader->read($this->decoder);
302299
$this->block_count -= 1;
303-
yield $data;
304300
}
301+
return $data;
305302
}
306303

307304
/**
@@ -312,6 +309,10 @@ public function close() { return $this->io->close(); }
312309

313310
/**
314311
* @uses AvroIO::seek()
312+
* @param $offset
313+
* @param $whence
314+
* @return bool
315+
* @throws AvroNotImplementedException
315316
*/
316317
private function seek($offset, $whence)
317318
{
@@ -320,6 +321,9 @@ private function seek($offset, $whence)
320321

321322
/**
322323
* @uses AvroIO::read()
324+
* @param $len
325+
* @return string
326+
* @throws AvroNotImplementedException
323327
*/
324328
private function read($len) { return $this->io->read($len); }
325329

@@ -328,6 +332,9 @@ private function read($len) { return $this->io->read($len); }
328332
*/
329333
private function is_eof() { return $this->io->is_eof(); }
330334

335+
/**
336+
* @return bool
337+
*/
331338
private function skip_sync()
332339
{
333340
$proposed_sync_marker = $this->read(AvroDataIO::SYNC_SIZE);
@@ -342,7 +349,7 @@ private function skip_sync()
342349
/**
343350
* Reads the block header (which includes the count of items in the block
344351
* and the length in bytes of the block)
345-
* @returns int length in bytes of the block.
352+
* @return int length in bytes of the block.
346353
*/
347354
private function read_block_header()
348355
{
@@ -359,7 +366,7 @@ private function read_block_header()
359366
class AvroDataIOWriter
360367
{
361368
/**
362-
* @returns string a new, unique sync marker.
369+
* @return string a new, unique sync marker.
363370
*/
364371
private static function generate_sync_marker()
365372
{
@@ -411,6 +418,7 @@ private static function generate_sync_marker()
411418
* @param AvroIO $io
412419
* @param AvroIODatumWriter $datum_writer
413420
* @param AvroSchema $writers_schema
421+
* @throws AvroDataIOException
414422
*/
415423
public function __construct($io, $datum_writer, $writers_schema=null)
416424
{
@@ -470,7 +478,7 @@ public function close()
470478

471479
/**
472480
* Flushes biffer to AvroIO object container.
473-
* @returns mixed value of $io->flush()
481+
* @return mixed value of $io->flush()
474482
* @see AvroIO::flush()
475483
*/
476484
private function flush()
@@ -522,13 +530,15 @@ private function write_header()
522530
/**
523531
* @param string $bytes
524532
* @uses AvroIO::write()
533+
* @return int
525534
*/
526535
private function write($bytes) { return $this->io->write($bytes); }
527536

528537
/**
529538
* @param int $offset
530539
* @param int $whence
531540
* @uses AvroIO::seek()
541+
* @return bool
532542
*/
533543
private function seek($offset, $whence)
534544
{

0 commit comments

Comments
 (0)