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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Hyde committed Jan 8, 2014
0 parents commit c0076c8
Show file tree
Hide file tree
Showing 29 changed files with 9,366 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/

308 changes: 308 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Apache Avro
Copyright 2010 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

C JSON parsing provided by Jansson and
written by Petri Lehtinen. The original software is
available from http://www.digip.org/jansson/.
33 changes: 33 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
What the Avro PHP library is
============================

A library for using [Avro](http://avro.apache.org/) with PHP.

Requirements
============
* PHP 5
* On 32-bit platforms, the [GMP PHP extension](http://php.net/gmp)
* For testing, [PHPUnit](http://www.phpunit.de/)

Both GMP and PHPUnit are often available via package management
systems as `php5-gmp` and `phpunit`, respectively.

Getting started
===============

Untar the avro-php distribution, untar it, and put it in your include path:

tar xjf avro-php.tar.bz2 # avro-php.tar.bz2 is likely avro-php-1.4.0.tar.bz2
cp avro-php /path/to/where/you/want/it

Require the avro.php file in your source, and you should be good to go:

<?php
require_once('avro-php/avro.php');

If you're pulling from source, put `lib/` in your include path and require `lib/avro.php`:

<?php
require_once('lib/avro.php');

Take a look in `examples/` for usage.
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "centraldesktop/avro-php",
"description": "Composer packaging for vanilla Apache Avro",
"license": "Apache-2.0",
"authors": [
{
"name": "Trey Hyde",
"email": "[email protected]"
}
],
"require": {

},
"autoload": {
"classmap": ["lib/"]

}
}
94 changes: 94 additions & 0 deletions examples/write_read.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env php
<?php
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require_once('../lib/avro.php');

// Write and read a data file

$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 = AvroDataIO::open_file($file_name, 'w', $writers_schema_json);

// Write each datum to the file
foreach ($data as $datum)
$data_writer->append($datum);
// Tidy up
$data_writer->close();

// Open $file_name (by default for reading) using the writer's schema
// included in the file
$data_reader = AvroDataIO::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();

// Create a data string
// Create a string io object.
$io = new AvroStringIO();
// Create a datum writer object
$writers_schema = AvroSchema::parse($writers_schema_json);
$writer = new AvroIODatumWriter($writers_schema);
$data_writer = new AvroDataIOWriter($io, $writer, $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 AvroStringIO($binary_string);
$data_reader = new AvroDataIOReader($read_io, new AvroIODatumReader());
echo "from binary string:\n";
foreach ($data_reader->data() as $datum)
echo var_export($datum, true) . "\n";

/** Output
from file:
array (
'member_id' => 1392,
'member_name' => 'Jose',
)
array (
'member_id' => 1642,
'member_name' => 'Maria',
)
from binary string:
array (
'member_id' => 1392,
'member_name' => 'Jose',
)
array (
'member_id' => 1642,
'member_name' => 'Maria',
)
*/
11 changes: 11 additions & 0 deletions lib/.svn/all-wcprops
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 68
/repos/asf/!svn/ver/1511537/avro/tags/release-1.7.5-rc0/lang/php/lib
END
avro.php
K 25
svn:wc:ra_dav:version-url
V 77
/repos/asf/!svn/ver/1511537/avro/tags/release-1.7.5-rc0/lang/php/lib/avro.php
END
65 changes: 65 additions & 0 deletions lib/.svn/entries
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
10

dir
1511537
https://svn.apache.org/repos/asf/avro/tags/release-1.7.5-rc0/lang/php/lib
https://svn.apache.org/repos/asf



2012-05-18T21:38:30.311419Z
1340267
cutting














13f79535-47bb-0310-9956-ffa450edef68

avro
dir

avro.php
file




2013-08-07T23:34:16.183323Z
6b24ec79f799a019bbc54986663c9e74
2011-11-01T19:32:54.219512Z
1196233
cutting





















5431

Loading

0 comments on commit c0076c8

Please sign in to comment.