$methods = ''; foreach ($json_spec['classes'] as $c) { foreach ($c['methods'] as $m) { $methods .= "\n"; if ($m['id'] % 10 == 0) { $methodBody = '$args = new AMQPWriter();' . "\n"; foreach ($m['arguments'] as $arg) { $methodBody .= $argumentWriter->call_write_argument($json_spec['domains'], $arg); } $methodBody .= $argumentWriter->write_bits(); $methodBody .= 'return array(' . $c['id'] . ", " . $m['id'] . ', $args);'; $methods .= '/**' . "\n"; $methods .= ' * @return array' . "\n"; $methods .= ' */' . "\n"; $methods .= 'public function ' . method_name($c['name'], $m['name']) . "("; $methods .= add_method_arguments($m['arguments']); $methods .= ")\n{\n"; $methods .= indent($methodBody) . "\n"; $methods .= "}\n"; } else { $methodBody = '$ret = array();' . "\n"; foreach ($m['arguments'] as $arg) { $methodBody .= '$ret[] = ' . call_read_argument($json_spec['domains'], $arg); } $methodBody .= 'return $ret;'; $methods .= '/**' . "\n"; $methods .= ' * @param AMQPReader $args' . "\n"; $methods .= ' * @return array' . "\n"; $methods .= ' */' . "\n"; $methods .= 'public static function ' . method_name($c['name'], $m['name']) . '($args)' . "\n{\n"; $methods .= indent($methodBody) . "\n";
return sprintf("AMQP\\x%02x\\x%02x\\x%02x\\x%02x", 0, $json_spec['major-version'], $json_spec['minor-version'], $json_spec['revision']); } else { return sprintf("AMQP\\x%02x\\x%02x\\x%02x\\x%02x", 1, 1, $json_spec['major-version'], $json_spec['minor-version']); } } $out = "<?php\n\n"; $out .= "/* This file was autogenerated by spec/parser.php - Do not modify */\n\n"; $out .= "namespace PhpAmqpLib\\Helper\\Protocol;\n\n"; $out .= "use PhpAmqpLib\\Wire\\AMQPWriter;\n\n"; $out .= "class Protocol" . protocol_version($json_spec) . "\n"; $out .= "{\n"; foreach ($json_spec['classes'] as $c) { foreach ($c['methods'] as $m) { if ($m['id'] % 10 == 0) { $out .= "\n\tpublic function " . method_name($c['name'], $m['name']) . "("; $out .= add_method_arguments($m['arguments']); $out .= ") {\n"; $out .= "\t\t\$args = new AMQPWriter();\n"; foreach ($m['arguments'] as $arg) { $out .= call_write_argument($json_spec['domains'], $arg); } $out .= "\t\treturn array(" . $c['id'] . ", " . $m['id'] . ", \$args);\n"; $out .= "\t}\n"; } else { $out .= "\n\tpublic static function " . method_name($c['name'], $m['name']) . "(\$args) {\n"; $out .= "\t\t\$ret = array();\n"; foreach ($m['arguments'] as $arg) { $out .= "\t\t\$ret[] = " . call_read_argument($json_spec['domains'], $arg); } $out .= "\t\treturn \$ret;\n"; $out .= "\t}\n";