Class: Phuby::Runtime
- Inherits:
-
Object
- Object
- Phuby::Runtime
- Includes:
- Singleton
- Defined in:
- lib/phuby/runtime.rb,
ext/phuby/phuby_runtime.c
Defined Under Namespace
Classes: NotStartedError
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #eval(string_or_io, filename = nil) ⇒ Object
-
#initialize ⇒ Runtime
constructor
A new instance of Runtime.
- #php(&block) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #with_events(event) {|_self| ... } ⇒ Object
Constructor Details
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
8 9 10 |
# File 'lib/phuby/runtime.rb', line 8 def events @events end |
Class Method Details
.php(&block) ⇒ Object
10 11 12 |
# File 'lib/phuby/runtime.rb', line 10 def self.php &block instance.php(&block) end |
Instance Method Details
#[](key) ⇒ Object
48 49 50 51 |
# File 'lib/phuby/runtime.rb', line 48 def [] key raise NotStartedError, "please start the runtime" unless @mutex.locked? get key end |
#[]=(key, value) ⇒ Object
53 54 55 56 |
# File 'lib/phuby/runtime.rb', line 53 def []= key, value raise NotStartedError, "please start the runtime" unless @mutex.locked? set key, value end |
#eval(string_or_io, filename = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/phuby/runtime.rb', line 31 def eval string_or_io, filename = nil raise NotStartedError, "please start the runtime" unless @mutex.locked? if string_or_io.respond_to? :read native_eval_io string_or_io, filename || string_or_io.path else native_eval string_or_io, filename || __FILE__ end end |
#php(&block) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/phuby/runtime.rb', line 41 def php &block start block.call(self) ensure stop end |
#start ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'ext/phuby/phuby_runtime.c', line 108
static VALUE start(VALUE self)
{
VALUE mutex = rb_iv_get(self, "@mutex");
rb_funcall(mutex, rb_intern("lock"), 0);
/* FIXME:
* I got these from the book. I don't know wtf they're for yet. */
int argc = 1;
char *argv[2] = { "embed4", NULL };
/* end FIXME */
php_embed_module.ub_write = phuby_ub_write;
php_embed_module.header_handler = phuby_header_handler;
php_embed_module.send_headers = phuby_send_headers;
php_embed_module.flush = phuby_flush;
php_embed_init(argc, argv);
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "RubyProxy", php_ruby_functions);
php_ruby_proxy = zend_register_internal_class(&ce);
SG(headers_sent) = 0;
SG(request_info).no_headers = 0;
return Qnil;
}
|
#started? ⇒ Boolean
20 21 22 |
# File 'lib/phuby/runtime.rb', line 20 def started? @mutex.locked? end |
#stop ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'ext/phuby/phuby_runtime.c', line 136
static VALUE stop(VALUE self)
{
php_embed_shutdown();
VALUE mutex = rb_iv_get(self, "@mutex");
rb_funcall(mutex, rb_intern("unlock"), 0);
return Qnil;
}
|
#with_events(event) {|_self| ... } ⇒ Object
24 25 26 27 28 29 |
# File 'lib/phuby/runtime.rb', line 24 def with_events event old = @events @events = event yield self @events = old end |