Sha256: 5eba688ac6490200a73ab7288a5a1a91d3a1094b583faacfbf88b19375400ec1

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module IronWorkerNG
  module Code
    module Runtime
      module PHP
        include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods

        def runtime_bundle(container)
          container.get_output_stream(@dest_dir + '__runner__.php') do |runner|
            runner.write <<PHP_RUNNER
<?php
/* #{IronWorkerNG.full_version} */

function getArgs() {
  global $argv;

  $args = array('task_id' => null, 'dir' => null, 'payload' => array());

  foreach ($argv as $k => $v) {
    if (empty($argv[$k + 1])) continue;

    if ($v == '-id') $args['task_id'] = $argv[$k + 1];
    if ($v == '-d')  $args['dir']     = $argv[$k + 1];

    if ($v == '-payload' && file_exists($argv[$k + 1])) {
      $args['payload'] = file_get_contents($argv[$k + 1]);

      $parsed_payload = json_decode($args['payload']);

      if ($parsed_payload != NULL) {
        $args['payload'] = $parsed_payload;
      }
    }
  }

  return $args;
}

function getPayload() {
  $args = getArgs();

  return $args['payload'];
}

require '#{File.basename(@exec.path)}';
PHP_RUNNER
          end
        end

        def runtime_run_code(local = false)
          <<RUN_CODE
TERM=dumb php __runner__.php "$@"
RUN_CODE
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iron_worker_ng-0.10.4 lib/iron_worker_ng/code/runtime/php.rb
iron_worker_ng-0.10.3 lib/iron_worker_ng/code/runtime/php.rb