Module: PHP

Defined in:
lib/php.rb,
lib/php/version.rb,
lib/php/generator.rb,
lib/php/syntax/loop.rb,
lib/php/syntax/node.rb,
lib/php/syntax/block.rb,
lib/php/syntax/class.rb,
lib/php/syntax/method.rb,
lib/php/syntax/comment.rb,
lib/php/syntax/literal.rb,
lib/php/syntax/program.rb,
lib/php/syntax/constant.rb,
lib/php/syntax/variable.rb,
lib/php/syntax/function.rb,
lib/php/syntax/operator.rb,
lib/php/syntax/interface.rb,
lib/php/syntax/statement.rb,
lib/php/syntax/namespace.rb,
lib/php/syntax/identifier.rb,
lib/php/syntax/expression.rb

Defined Under Namespace

Modules: VERSION Classes: Block, Class, Comment, Constant, Expression, Function, Generator, Identifier, Interface, Literal, Loop, Method, Namespace, Node, Operator, Program, Statement, Variable

Class Method Summary

Class Method Details

+ (Object) dump(input, options = {}) + (Object) dump(options = {}, &block) { ... }

This method returns an undefined value.

Outputs the given block of code translated into PHP code.

Overloads:

  • + (Object) dump(input, options = {})

    Parameters:

    • (String) input
    • (Hash{Symbol => Object}) options
  • + (Object) dump(options = {}, &block) { ... }

    Parameters:

    • (Hash{Symbol => Object}) options

    Yields:



76
77
78
# File 'lib/php.rb', line 76

def self.dump(input = nil, options = {}, &block)
  puts self.generate(input, options, &block).to_s
end

+ eval(options = {}, &block) { ... }

This method returns an undefined value.

Evaluates a given block of code by invoking the php executable.

Parameters:

  • (Hash{Symbol => Object}) options (defaults to: {})

Options Hash (options):

  • (IO) :stdout — default: $stdout
  • (IO) :stderr — default: $stderr

Yields:



47
48
49
# File 'lib/php.rb', line 47

def self.eval(options = {}, &block)
  self.exec(self.generate(&block), options)
end

+ (Process::Status) exec(program, options = {})

Executes a PHP program by invoking the php executable.

Parameters:

  • (Program, String, #to_s) program
  • (Hash{Symbol => Object}) options (defaults to: {})

Options Hash (options):

  • (IO) :stdout — default: $stdout
  • (IO) :stderr — default: $stderr

Returns:

  • (Process::Status)


59
60
61
62
# File 'lib/php.rb', line 59

def self.exec(program, options = {})
  require 'open4' unless defined?(Open4)
  Open4::spawn('php', {:stdin => program.to_s, :stdout => $stdout, :stderr => $stderr}.merge(options))
end

+ (Object) generate(input, options = {}) + (Object) generate(options = {}, &block) { ... }

Translates the given block of code into abstract PHP code.

Overloads:

  • + (Object) generate(input, options = {})

    Parameters:

    • (String) input
    • (Hash{Symbol => Object}) options
  • + (Object) generate(options = {}, &block) { ... }

    Parameters:

    • (Hash{Symbol => Object}) options

    Yields:

Returns:



92
93
94
95
96
97
98
# File 'lib/php.rb', line 92

def self.generate(input = nil, options = {}, &block)
  if php = PHP::Generator.process(input, options, &block)
    PHP::Program.new(php)
  else
    PHP::Program.new
  end
end

+ (String) version

Returns the current PHP version by invoking the php executable.

Examples:

  PHP.version   #=> "5.3.1"

Returns:

  • (String)


33
34
35
36
37
# File 'lib/php.rb', line 33

def self.version
  version = ''
  self.exec('<?php echo phpversion();', :stdout => version)
  version.size > 0 ? version : nil
end