Class: Php_process::Proxy_obj

Inherits:
Object
  • Object
show all
Defined in:
lib/php_process.rb

Overview

This object proxies calls to the object it refers to on the PHP-side. It is automatically spawned from “php.new” and should not be spawned manually.

Examples

php = Php_process.new pe = php.new(“PHPExcel”) pe.getProperties.setCreator(“kaspernj”)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Proxy_obj

Sets required instance-variables and defines the finalizer for unsetting on the PHP-side.



413
414
415
416
417
418
419
# File 'lib/php_process.rb', line 413

def initialize(args)
  @args = args
  @args[:php].object_ids[self.__id__] = @args[:id]
  
  #Define finalizer so we can remove the object on PHPs side, when it is collected on the Ruby-side.
  ObjectSpace.define_finalizer(self, @args[:php].method(:objects_unsetter))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Uses ‘method_missing’ to proxy all other calls onto the PHP-process and the PHP-object. Then returns the parsed result.



448
449
450
# File 'lib/php_process.rb', line 448

def method_missing(method_name, *args)
  return @args[:php].send(:type => :object_call, :method => method_name, :args => @args[:php].parse_data(args), :id => @args[:id])
end

Instance Attribute Details

#argsObject (readonly)

Contains the various data about the object like ID and class. It is readable because it needs to be converted to special hashes when used as arguments.



410
411
412
# File 'lib/php_process.rb', line 410

def args
  @args
end

Instance Method Details

#__get_var(name) ⇒ Object

Returns an instance-variable by name.

Examples

proxy_obj = php.new(“stdClass”) proxy_obj.__set_var(“testvar”, 5) proxy_obj.__get_var(“testvar”) #=> 5



443
444
445
# File 'lib/php_process.rb', line 443

def __get_var(name)
  return @args[:php].send(:type => "get_var", :id => @args[:id], :name => name)
end

#__phpclassObject

Returns the PHP-class of the object that this object refers to as a symbol.

Examples

proxy_obj.__phpclass #=> :PHPExcel



424
425
426
# File 'lib/php_process.rb', line 424

def __phpclass
  return @args[:php].func("get_class", self)
end

#__set_var(name, val) ⇒ Object

Sets an instance-variable on the object.

Examples

proxy_obj = php.new(“stdClass”) proxy_obj.__set_var(“testvar”, 5) proxy_obj.__get_var(“testvar”) #=> 5



433
434
435
436
# File 'lib/php_process.rb', line 433

def __set_var(name, val)
  @args[:php].send(:type => "set_var", :id => @args[:id], :name => name, :val => val)
  return nil
end