[svn:PHP-Sandwich] rev 1081 - in PHP-Sandwich/trunk: . t
[email protected] 14 Jun 2005 17:45:57 -0000
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
Author: gschlossnagle
Date: Tue Jun 14 10:45:57 2005
New Revision: 1081
Added:
PHP-Sandwich/trunk/t/19.t (contents, props changed)
Modified:
PHP-Sandwich/trunk/PHP.xs
PHP-Sandwich/trunk/phpinterp.c
PHP-Sandwich/trunk/phpinterp.h
Log:
output buffering
Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs (original)
+++ PHP-Sandwich/trunk/PHP.xs Tue Jun 14 10:45:57 2005
@@ -455,7 +455,19 @@ SV* SAND_new(classname, ...)
}
else if(!strcmp(trackvars_key, "FILES")) {
track_vars_array = PG(http_globals)[TRACK_VARS_FILES];
- } else {
+ }
+ else if(!strcmp(trackvars_key, "OUTPUT")) {
+ sandwich_per_interp *interp = (sandwich_per_interp *)SG(server_context);
+ if(interp) {
+ SvREFCNT_inc(trackvars);
+ interp->output_handler = trackvars;
+ }
+ } else if(!strcmp(trackvars_key, "INCLUDE_PATH")) {
+ STRLEN strlen;
+ char *str = SvPV(sv, strlen);
+ zend_alter_ini_entry("include_path", sizeof("include_path"), str, strlen);
+ }
+ else {
/* special case - this isn't an autoglobal - register it and continue */
int old_register_globals = PG(register_globals);
PG(register_globals) = 1;
Modified: PHP-Sandwich/trunk/phpinterp.c
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.c (original)
+++ PHP-Sandwich/trunk/phpinterp.c Tue Jun 14 10:45:57 2005
@@ -1,3 +1,15 @@
+/* vim: set sts=2 ts=2 expandtab bs=2 ai : */
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#ifndef PERL_VERSION
+#include "patchlevel.h"
+#define PERL_REVISION 5
+#define PERL_VERSION PATCHLEVEL
+#define PERL_SUBVERSION SUBVERSION
+#endif
+
#include "phpinterp.h"
#include "phpfuncs.h"
@@ -8,7 +20,28 @@ static pthread_key_t sandwich_per_thread
static int sandwich_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
// FIXME - call out to Perl's selected fh
- fwrite(str, 1, str_length, stdout);
+ SV *oh;
+ sandwich_per_interp *interp = SG(server_context);
+ if(!interp || !interp->output_handler) {
+ fwrite(str, 1, str_length, stdout);
+ return str_length;
+ }
+ oh = interp->output_handler;
+ if (SvROK(oh) && (SvTYPE(SvRV(oh)) == SVt_PVCV)) {
+ dTHX;
+ dSP;
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(SP);
+ XPUSHs(sv_2mortal(newSVpvn(str, str_length)));
+ PUTBACK;
+ call_sv(oh, G_VOID);
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
+ } else {
+ sv_catpvn_mg(SvROK(oh)?SvRV(oh):oh, str, str_length);
+ }
return str_length;
}
Modified: PHP-Sandwich/trunk/phpinterp.h
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.h (original)
+++ PHP-Sandwich/trunk/phpinterp.h Tue Jun 14 10:45:57 2005
@@ -21,6 +21,7 @@
typedef struct {
void *ctx;
int ref;
+ SV *output_handler;
} sandwich_per_interp;
int sandwich_php_interpreter_create();
Added: PHP-Sandwich/trunk/t/19.t
==============================================================================
--- (empty file)
+++ PHP-Sandwich/trunk/t/19.t Tue Jun 14 10:45:57 2005
@@ -0,0 +1,34 @@
+#!/opt/ecelerity/3rdParty/bin/perl
+use strict;
+use Test::More tests => 6;
+
+BEGIN {
+ diag "Testing Output Buffering";
+ use_ok 'PHP' or die;
+ use_ok 'PHP::Interpreter' or die;
+}
+
+my $output;
+ok my $p = PHP::Interpreter->new(
+ {
+ 'BRIC' =>
+ {'special' => 'data',},
+ 'OUTPUT' => \$output
+ }),
+ "Create new PHP interpreter";
+$p->eval(q/print $BRIC['special'];/);
+is $output, 'data', 'check output buffering (scalar pass by ref)';
+
+
+my $output2;
+sub pr { $output2 .= @_[0]; }
+ok my $p = PHP::Interpreter->new(
+ {
+ 'BRIC' =>
+ {'special' => 'data',},
+ 'OUTPUT' => \&pr
+ }),
+ "Create new PHP interpreter";
+
+$p->eval(q/print $BRIC['special'];/);
+is $output2, 'data', 'check output buffering (callback)';