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.



390
391
392
393
394
395
396
# File 'lib/php_process.rb', line 390

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.



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

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.



387
388
389
# File 'lib/php_process.rb', line 387

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



420
421
422
# File 'lib/php_process.rb', line 420

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



401
402
403
# File 'lib/php_process.rb', line 401

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



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

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