php_vm 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/ext/php_vm/php_vm.c +69 -14
  2. data/ext/php_vm/php_vm.h +15 -1
  3. metadata +2 -2
data/ext/php_vm/php_vm.c CHANGED
@@ -472,33 +472,41 @@ zval* get_zval(VALUE self)
472
472
 
473
473
  // module PHPVM
474
474
 
475
- VALUE rb_php_vm_require(VALUE cls, VALUE filepath)
475
+ void php_vm_require(char *token, VALUE filepath)
476
476
  {
477
477
  StringValue(filepath);
478
478
  filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\\"), rb_str_new2("\\\\"));
479
479
  filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\""), rb_str_new2("\\\""));
480
480
 
481
- VALUE code = rb_str_new2("require \"");
481
+ VALUE code = rb_str_new2(token);
482
+ rb_str_cat2(code, " \"");
482
483
  rb_str_cat(code, RSTRING_PTR(filepath), RSTRING_LEN(filepath));
483
484
  rb_str_cat2(code, "\";");
484
485
 
485
486
  php_eval_string(RSTRING_PTR(code), RSTRING_LEN(code));
487
+ }
486
488
 
487
- return Qnil;
489
+ VALUE rb_php_vm_require(VALUE cls, VALUE filepath)
490
+ {
491
+ php_vm_require("require", filepath);
492
+ return Qtrue;
488
493
  }
489
494
 
490
495
  VALUE rb_php_vm_require_once(VALUE cls, VALUE filepath)
491
496
  {
492
- StringValue(filepath);
493
- filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\\"), rb_str_new2("\\\\"));
494
- filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\""), rb_str_new2("\\\""));
495
-
496
- VALUE code = rb_str_new2("require_once \"");
497
- rb_str_cat(code, RSTRING_PTR(filepath), RSTRING_LEN(filepath));
498
- rb_str_cat2(code, "\";");
497
+ php_vm_require("require_once", filepath);
498
+ return Qtrue;
499
+ }
499
500
 
500
- php_eval_string(RSTRING_PTR(code), RSTRING_LEN(code));
501
+ VALUE rb_php_vm_include(VALUE cls, VALUE filepath)
502
+ {
503
+ php_vm_require("include", filepath);
504
+ return Qnil;
505
+ }
501
506
 
507
+ VALUE rb_php_vm_include_once(VALUE cls, VALUE filepath)
508
+ {
509
+ php_vm_require("include_once", filepath);
502
510
  return Qnil;
503
511
  }
504
512
 
@@ -658,7 +666,40 @@ VALUE rb_php_global_class_call(VALUE self)
658
666
  return rb_php_class_get(rb_cPHPClass, callee);
659
667
  }
660
668
 
661
- VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self)
669
+ static VALUE php_global_require_b_proc(RequireArgs *args)
670
+ {
671
+ php_vm_require(args->token, args->filepath);
672
+ return Qnil;
673
+ }
674
+
675
+ static VALUE php_global_require_r_proc(RequireArgs *args, VALUE e)
676
+ {
677
+ rb_funcall(Qnil, rb_intern("require"), 1, args->filepath);
678
+ return Qnil;
679
+ }
680
+
681
+ void php_global_require(char *token, VALUE filepath)
682
+ {
683
+ RequireArgs args;
684
+ args.token = token;
685
+ args.filepath = filepath;
686
+
687
+ rb_rescue(php_global_require_b_proc, (VALUE)&args, php_global_require_r_proc, (VALUE)&args);
688
+ }
689
+
690
+ VALUE rb_php_global_require(VALUE cls, VALUE filepath)
691
+ {
692
+ php_global_require("require", filepath);
693
+ return Qtrue;
694
+ }
695
+
696
+ VALUE rb_php_global_require_once(VALUE cls, VALUE filepath)
697
+ {
698
+ php_global_require("require_once", filepath);
699
+ return Qtrue;
700
+ }
701
+
702
+ VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE cls)
662
703
  {
663
704
  int i;
664
705
 
@@ -686,10 +727,16 @@ VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self)
686
727
  // release
687
728
  free(format);
688
729
  free(argv2);
730
+
689
731
  return Qnil;
690
732
  }
691
733
 
692
- VALUE rb_php_global_array(int argc, VALUE *argv, VALUE self)
734
+ VALUE rb_php_global_print(VALUE cls, VALUE arg)
735
+ {
736
+ return rb_php_global_echo(1, &arg, cls);
737
+ }
738
+
739
+ VALUE rb_php_global_array(int argc, VALUE *argv, VALUE cls)
693
740
  {
694
741
  VALUE result;
695
742
  if (argc==1 && TYPE(argv[0])==T_HASH) {
@@ -892,16 +939,24 @@ void Init_php_vm()
892
939
 
893
940
  rb_define_singleton_method(rb_mPHPVM, "require", rb_php_vm_require, 1);
894
941
  rb_define_singleton_method(rb_mPHPVM, "require_once", rb_php_vm_require_once, 1);
942
+ rb_define_singleton_method(rb_mPHPVM, "include", rb_php_vm_include, 1);
943
+ rb_define_singleton_method(rb_mPHPVM, "include_once", rb_php_vm_include_once, 1);
944
+
895
945
  rb_define_singleton_method(rb_mPHPVM, "exec", rb_php_vm_exec, 1);
896
946
  rb_define_singleton_method(rb_mPHPVM, "get_class", rb_php_vm_get_class, 1);
897
947
  rb_define_singleton_method(rb_mPHPVM, "define_global", rb_php_vm_define_global, 0);
898
948
 
899
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.2.4"));
949
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.2.5"));
900
950
 
901
951
  // module PHPVM::PHPGlobal
902
952
  rb_mPHPGlobal = rb_define_module_under(rb_mPHPVM, "PHPGlobal");
953
+
954
+ rb_define_module_function(rb_mPHPGlobal, "require", rb_php_global_require, 1);
955
+ rb_define_module_function(rb_mPHPGlobal, "require_once", rb_php_global_require_once, 1);
903
956
  rb_define_module_function(rb_mPHPGlobal, "echo", rb_php_global_echo, -1);
957
+ rb_define_module_function(rb_mPHPGlobal, "print", rb_php_global_print, 1);
904
958
  rb_define_module_function(rb_mPHPGlobal, "array", rb_php_global_array, -1);
959
+
905
960
  rb_php_vm_define_global(rb_mPHPVM);
906
961
 
907
962
  // class PHPVM::PHPClass
data/ext/php_vm/php_vm.h CHANGED
@@ -19,6 +19,11 @@ typedef struct {
19
19
  zval *zobj;
20
20
  } PHPNativeResource;
21
21
 
22
+ typedef struct {
23
+ char *token;
24
+ VALUE filepath;
25
+ } RequireArgs;
26
+
22
27
 
23
28
  // PHP
24
29
  extern void php_eval_string(char *code, int code_len TSRMLS_DC);
@@ -42,7 +47,11 @@ extern zend_class_entry* get_zend_class_entry(VALUE self);
42
47
  extern zval* get_zval(VALUE self);
43
48
 
44
49
  // module PHPVM
45
- extern VALUE rb_php_vm_require(VALUE cls, VALUE rbv_filepath);
50
+ extern void php_vm_require(char *construct, VALUE filepath);
51
+ extern VALUE rb_php_vm_require(VALUE cls, VALUE filepath);
52
+ extern VALUE rb_php_vm_require_once(VALUE cls, VALUE filepath);
53
+ extern VALUE rb_php_vm_include(VALUE cls, VALUE filepath);
54
+ extern VALUE rb_php_vm_include_once(VALUE cls, VALUE filepath);
46
55
  extern VALUE rb_php_vm_exec(VALUE cls, VALUE rbv_code);
47
56
  extern VALUE rb_php_vm_get_class(VALUE cls, VALUE rbv_class_name);
48
57
  extern VALUE define_global_constants();
@@ -53,7 +62,12 @@ extern VALUE rb_php_vm_define_global(VALUE cls);
53
62
  // module PHPVM::PHPGlobal
54
63
  extern VALUE rb_php_global_function_call(int argc, VALUE *argv, VALUE self);
55
64
  extern VALUE rb_php_global_class_call(VALUE self);
65
+ extern void php_global_require(char *token, VALUE filepath);
66
+ extern VALUE rb_php_global_require(VALUE cls, VALUE filepath);
67
+ extern VALUE rb_php_global_require_once(VALUE cls, VALUE filepath);
56
68
  extern VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self);
69
+ extern VALUE rb_php_global_print(VALUE self, VALUE arg);
70
+ extern VALUE rb_php_global_array(int argc, VALUE *argv, VALUE self);
57
71
 
58
72
  // class PHPVM::PHPClass
59
73
  extern VALUE rb_php_class_get(VALUE cls, VALUE rbv_name);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php_vm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-27 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: php_vm is a native bridge between Ruby and PHP.
15
15
  email: