$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"; $out .= 'use PhpAmqpLib\\Wire\\AMQPReader;' . "\n\n"; $out .= 'class Protocol' . protocol_version($json_spec) . "\n"; $out .= "{\n"; $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;';
$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 .= $argumentWriter->call_write_argument($json_spec['domains'], $arg); } $out .= $argumentWriter->write_bits(); $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"; } } } $out .= "}\n"; file_put_contents(__DIR__ . '/../PhpAmqpLib/Helper/Protocol/Protocol' . protocol_version($json_spec) . '.php', $out);