Example #1
0
function method_map($json_spec)
{
    $ret = array();
    $special_map = array('60,30' => 'basic_cancel_from_server', '60,80' => 'basic_ack_from_server', '60,120' => 'basic_nack_from_server');
    foreach ($json_spec['classes'] as $c) {
        foreach ($c['methods'] as $m) {
            if (isset($special_map[$c['id'] . ',' . $m['id']]) && protocol_version($json_spec) == '091') {
                $ret[$c['id'] . "," . $m['id']] = $special_map[$c['id'] . ',' . $m['id']];
            } else {
                $ret[$c['id'] . "," . $m['id']] = $c['name'] . '_' . to_snake_case($m['name']);
            }
        }
    }
    return export_property($ret);
}
$classBody = '';
$classBody .= 'protected $method_map = ' . method_map($json_spec) . ";\n\n\n\n";
$classBody .= 'public function get_method($method_sig)' . "\n{\n";
$classBody .= indent('return $this->method_map[$method_sig];') . "\n";
$classBody .= "}\n\n\n\n";
$classBody .= 'public function valid_method($method_sig)' . "\n{\n";
$classBody .= indent('return array_key_exists($method_sig, $this->method_map);') . "\n";
$classBody .= "}\n";
$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 .= "class MethodMap" . protocol_version($json_spec) . "\n";
$out .= "{\n\n";
$out .= indent($classBody) . "\n";
$out .= "}\n";
file_put_contents(__DIR__ . '/../PhpAmqpLib/Helper/Protocol/MethodMap' . protocol_version($json_spec) . '.php', $out);
Example #2
0
$out .= "{\n";
$out .= "\tprotected \$wait = " . method_waits($json_spec) . ";\n\n";
$out .= "\tpublic function get_wait(\$method) {\n";
$out .= "\t\t return \$this->wait[\$method];\n";
$out .= "\t}\n";
$out .= "}\n";
file_put_contents(__DIR__ . '/../PhpAmqpLib/Helper/Protocol/Wait' . protocol_version($json_spec) . '.php', $out);
function method_map($json_spec)
{
    $ret = array();
    foreach ($json_spec['classes'] as $c) {
        foreach ($c['methods'] as $m) {
            $ret[$c['id'] . "," . $m['id']] = $c['name'] . '_' . to_snake_case($m['name']);
        }
    }
    return var_export($ret, true);
}
$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 .= "class MethodMap" . protocol_version($json_spec) . "\n";
$out .= "{\n";
$out .= "\tprotected \$method_map = " . method_map($json_spec) . ";\n\n";
$out .= "\tpublic function get_method(\$method_sig) {\n";
$out .= "\t\t return \$this->method_map[\$method_sig];\n";
$out .= "\t}\n";
$out .= "\tpublic function valid_method(\$method_sig) {\n";
$out .= "\t\treturn array_key_exists(\$method_sig, \$this->method_map);\n";
$out .= "\t}\n";
$out .= "}\n";
file_put_contents(__DIR__ . '/../PhpAmqpLib/Helper/Protocol/MethodMap' . protocol_version($json_spec) . '.php', $out);