[svn:PHP-Sandwich] rev 1038 - in PHP-Sandwich/trunk: . t
[email protected] 2 May 2005 05:39:29 -0000
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
Author: shughes
Date: Sun May 1 22:39:28 2005
New Revision: 1038
Added:
PHP-Sandwich/trunk/t/15.t (contents, props changed)
Modified:
PHP-Sandwich/trunk/phpfuncs.c
Log:
add variable access via the dimension accessors
Modified: PHP-Sandwich/trunk/phpfuncs.c
==============================================================================
--- PHP-Sandwich/trunk/phpfuncs.c (original)
+++ PHP-Sandwich/trunk/phpfuncs.c Sun May 1 22:39:28 2005
@@ -27,6 +27,59 @@
memset(&swg->ps_stats, 0, sizeof(swg->ps_stats));
}
+static zval *
+perl_dim_read(zval *obj, zval *offset, int type TSRMLS_DC)
+{
+ SV *value;
+ zval *return_value;
+ struct plobj *pl;
+ char *name;
+ pTHX;
+
+ pl = zend_object_store_get_object(obj TSRMLS_CC);
+ aTHX = pl->perl;
+ value = NULL;
+
+ if (Z_TYPE_P(offset) != IS_STRING) {
+ goto err_out;
+ }
+
+ name = Z_STRVAL_P(offset);
+ if (Z_STRLEN_P(offset) < 2) {
+ goto err_out;
+ }
+
+ switch (name[0]) {
+ case '$':
+ value = get_sv(name + 1, FALSE);
+ break;
+ case '@':
+ value = (SV *) get_av(name + 1, FALSE);
+ break;
+ case '%':
+ value = (SV *) get_hv(name + 1, FALSE);
+ break;
+ }
+
+ if (!value) {
+ goto err_out;
+ }
+
+ return_value = SvZval(value);
+ return return_value;
+
+err_out:
+ MAKE_STD_ZVAL(return_value);
+ ZVAL_NULL(return_value);
+ return return_value;
+}
+
+static void
+perl_dim_write(zval *obj, zval *offset, zval *value TSRMLS_DC)
+{
+ return;
+}
+
PHP_METHOD(perl, getvariable)
{
struct plobj *pl;
@@ -241,6 +294,9 @@
memcpy(&plobj_handlers, zend_get_std_object_handlers(),
sizeof(plobj_handlers));
+ plobj_handlers.read_dimension = perl_dim_read;
+ plobj_handlers.write_dimension = perl_dim_write;
+
return SUCCESS;
}
Added: PHP-Sandwich/trunk/t/15.t
==============================================================================
--- (empty file)
+++ PHP-Sandwich/trunk/t/15.t Sun May 1 22:39:28 2005
@@ -0,0 +1,25 @@
+#!/opt/ecelerity/3rdParty/bin/perl
+use strict;
+use Test::More tests => 5;
+
+BEGIN {
+ use_ok 'PHP' or die;
+ use_ok 'PHP::Interpreter' or die;
+}
+
+our @var;
+
+push @var, "hello";
+push @var, "goodbye";
+
+diag "Testing basic function autoloadind";
+ok my $p = PHP::Interpreter->new, "Create new PHP interpreter";
+ok $p->eval(q/
+ function foo() {
+ $perl = Perl::getInstance();
+ $value = $perl['@var'];
+ return $value;
+ }
+/), 'Define PHP function that returns Perl values';
+my @phpval = $p->foo();
+ok $phpval[0] == 'hello', 'Check return value of PHP foo()';