Skip to content

Commit 889962d

Browse files
authored
fix: missing interfaces/exceptions in arrow-ext (#2294)
- updated ext-php-rs
1 parent 0ba2e22 commit 889962d

10 files changed

Lines changed: 133 additions & 16 deletions

File tree

src/extension/arrow-ext/Cargo.lock

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension/arrow-ext/php/Flow/Arrow/OutputStream.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Flow\Arrow;
66

7+
if (\extension_loaded('arrow')) {
8+
return;
9+
}
10+
711
interface OutputStream
812
{
913
public function append(string $data) : self;

src/extension/arrow-ext/php/Flow/Arrow/Parquet/Exception.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Flow\Arrow\Parquet;
66

7-
final class Exception extends \RuntimeException
7+
if (\extension_loaded('arrow')) {
8+
return;
9+
}
10+
11+
final class Exception extends \Exception
812
{
913
}

src/extension/arrow-ext/php/Flow/Arrow/RandomAccessFile.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Flow\Arrow;
66

7+
if (\extension_loaded('arrow')) {
8+
return;
9+
}
10+
711
interface RandomAccessFile
812
{
913
public function read(int $length, int $offset) : string;

src/extension/arrow-ext/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,24 @@ pub extern "C" fn php_module_info(_module: *mut ModuleEntry) {
2121
info_table_end!();
2222
}
2323

24+
pub unsafe extern "C" fn module_startup(_type: i32, _module_number: i32) -> i32 {
25+
if let Err(e) = stream::output_stream::register() {
26+
eprintln!("arrow: failed to register Flow\\Arrow\\OutputStream: {e}");
27+
return -1;
28+
}
29+
if let Err(e) = stream::random_access_file::register() {
30+
eprintln!("arrow: failed to register Flow\\Arrow\\RandomAccessFile: {e}");
31+
return -1;
32+
}
33+
if let Err(e) = parquet::exception::register() {
34+
eprintln!("arrow: failed to register Flow\\Arrow\\Parquet\\Exception: {e}");
35+
return -1;
36+
}
37+
0
38+
}
39+
2440
#[php_module]
41+
#[php(startup = "module_startup")]
2542
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
2643
module
2744
.info_function(php_module_info)

src/extension/arrow-ext/src/parquet/exception.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
use ext_php_rs::builders::ClassBuilder;
2+
use ext_php_rs::error::Result;
13
use ext_php_rs::exception::PhpException;
4+
use ext_php_rs::flags::ClassFlags;
25
use ext_php_rs::zend::{ce, ClassEntry};
36

7+
fn noop(_ce: &'static mut ClassEntry) {}
8+
9+
pub fn register() -> Result<()> {
10+
ClassBuilder::new("Flow\\Arrow\\Parquet\\Exception")
11+
.extends((ce::exception, "Exception"))
12+
.flags(ClassFlags::Final)
13+
.registration(noop)
14+
.register()?;
15+
16+
Ok(())
17+
}
18+
419
fn parquet_exception_ce() -> &'static ClassEntry {
520
ClassEntry::try_find("Flow\\Arrow\\Parquet\\Exception")
621
.unwrap_or_else(|| ce::exception())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
pub mod output_stream;
12
pub mod php_destination_stream;
23
pub mod php_source_stream;
4+
pub mod random_access_file;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use ext_php_rs::args::Arg;
2+
use ext_php_rs::builders::{ClassBuilder, FunctionBuilder};
3+
use ext_php_rs::error::Result;
4+
use ext_php_rs::flags::{ClassFlags, DataType, MethodFlags};
5+
use ext_php_rs::zend::ClassEntry;
6+
7+
fn noop(_ce: &'static mut ClassEntry) {}
8+
9+
pub fn register() -> Result<()> {
10+
ClassBuilder::new("Flow\\Arrow\\OutputStream")
11+
.flags(ClassFlags::Interface)
12+
.registration(noop)
13+
.method(
14+
FunctionBuilder::new_abstract("append")
15+
.arg(Arg::new("data", DataType::String))
16+
.returns(DataType::Object(Some("self")), false, false),
17+
MethodFlags::Public | MethodFlags::Abstract,
18+
)
19+
.register()?;
20+
21+
Ok(())
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use ext_php_rs::args::Arg;
2+
use ext_php_rs::builders::{ClassBuilder, FunctionBuilder};
3+
use ext_php_rs::error::Result;
4+
use ext_php_rs::flags::{ClassFlags, DataType, MethodFlags};
5+
use ext_php_rs::zend::ClassEntry;
6+
7+
fn noop(_ce: &'static mut ClassEntry) {}
8+
9+
pub fn register() -> Result<()> {
10+
ClassBuilder::new("Flow\\Arrow\\RandomAccessFile")
11+
.flags(ClassFlags::Interface)
12+
.registration(noop)
13+
.method(
14+
FunctionBuilder::new_abstract("read")
15+
.arg(Arg::new("length", DataType::Long))
16+
.arg(Arg::new("offset", DataType::Long))
17+
.returns(DataType::String, false, false),
18+
MethodFlags::Public | MethodFlags::Abstract,
19+
)
20+
.method(
21+
FunctionBuilder::new_abstract("size")
22+
.returns(DataType::Long, false, true),
23+
MethodFlags::Public | MethodFlags::Abstract,
24+
)
25+
.register()?;
26+
27+
Ok(())
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
arrow extension registers OutputStream, RandomAccessFile interfaces and Parquet\Exception class
3+
--SKIPIF--
4+
<?php if (!extension_loaded("arrow")) die("skip arrow extension not loaded"); ?>
5+
--FILE--
6+
<?php
7+
var_dump(interface_exists('Flow\Arrow\OutputStream', false));
8+
var_dump(interface_exists('Flow\Arrow\RandomAccessFile', false));
9+
var_dump(class_exists('Flow\Arrow\Parquet\Exception', false));
10+
var_dump(is_subclass_of('Flow\Arrow\Parquet\Exception', \Exception::class));
11+
12+
$r = new ReflectionClass('Flow\Arrow\OutputStream');
13+
var_dump($r->isInterface());
14+
var_dump($r->hasMethod('append'));
15+
16+
$r = new ReflectionClass('Flow\Arrow\RandomAccessFile');
17+
var_dump($r->isInterface());
18+
var_dump($r->hasMethod('read'));
19+
var_dump($r->hasMethod('size'));
20+
?>
21+
--EXPECT--
22+
bool(true)
23+
bool(true)
24+
bool(true)
25+
bool(true)
26+
bool(true)
27+
bool(true)
28+
bool(true)
29+
bool(true)
30+
bool(true)

0 commit comments

Comments
 (0)