定制 nealio82/avro-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nealio82/avro-php

最新稳定版本:0.1.2

Composer 安装命令:

composer require nealio82/avro-php

包简介

Implementation of Apache's Avro PHP library with Composer support, PSR-4 autoloading, namespaces, and type hinted method parameters

README 文档

README

This is a package based on the Apache AVRO PHP library (v 1.8.1).

The core logic remains the same but I've added Composer support, PSR-4 autoloading, method type-hinting, fixed property accessors with encapsulation where I've found errors (private/public member access), and some other tidy-ups.

Usage

Installation

$ composer require nealio82/avro-php

Usage

Based on the official library's example:

<?php

use Avro\DataIO\DataIO;
use Avro\DataIO\DataIOReader;
use Avro\DataIO\DataIOWriter;
use Avro\Datum\IODatumReader;
use Avro\Datum\IODatumWriter;
use Avro\IO\StringIO;
use Avro\Schema\Schema;

require_once('vendor/autoload.php');

$writers_schema_json = <<<_JSON
{
 "name":"member",
 "type":"record",
 "fields":
    [
        {"name":"member_id", "type":"int"},
        {"name":"member_name", "type":"string"}
    ]
}
_JSON;

$jose = array('member_id' => 1392, 'member_name' => 'Jose');
$maria = array('member_id' => 1642, 'member_name' => 'Maria');
$data = array($jose, $maria);


$file_name = 'data.avr';

// Open $file_name for writing, using the given writer's schema
$data_writer = DataIO::open_file($file_name, 'w', $writers_schema_json);
// Write each datum to the file
foreach ($data as $datum) {
    $data_writer->append($datum);
}
$data_writer->close();


// Open $file_name (by default for reading) using the writer's schema
// included in the file
$data_reader = DataIO::open_file($file_name);
echo "from file:\n";
// Read each datum
foreach ($data_reader->data() as $datum) {
    echo var_export($datum, true) . "\n";
}
$data_reader->close();


$io = new StringIO();

$writers_schema = Schema::parse($writers_schema_json);
$data_writer = new DataIOWriter($io, new IODatumWriter($writers_schema), $writers_schema);

foreach ($data as $datum) {
    $data_writer->append($datum);
}
$data_writer->close();


$binary_string = $io->string();

// Load the string data string
$read_io = new StringIO($binary_string);
$data_reader = new DataIOReader($read_io, new IODatumReader());
echo "from binary string:\n";
foreach ($data_reader->data() as $datum) {
    echo var_export($datum, true) . "\n";
}

统计信息

  • 总下载量: 78.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 8
  • Watchers: 0
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-01-30