alef 0.76.0

Opinionated polyglot binding generator for Rust libraries
Documentation
<?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

use {{ namespace }}\{{ class_name }};
{% for type_name in imported_types %}use {{ namespace }}\{{ type_name }};
{% endfor %}
{% for line in setup_lines %}
{{ line }}
{% endfor %}
{% if client_factory %}
$apiKey = getenv('{{ api_key_var }}');
if ($apiKey === false || $apiKey === '') {
    throw new RuntimeException('{{ api_key_var }} must be set');
}
$client = {{ class_name }}::{{ client_factory }}($apiKey);
{% endif %}
{% if expects_error %}
try {
    {{ call_expr }};
} catch (Throwable $error) {
    echo $error::class . ': ' . $error->getMessage() . "\n";
}
{% else %}
{% if returns_void %}
{{ call_expr }};
{% elif is_streaming %}
$chunks = iterator_to_array({{ call_expr }});
{% else %}
${{ result_var }} = {{ call_expr }};
{% endif %}
{% if not returns_void and not is_streaming %}
{% if presentation %}
{% for operation in presentation %}
{% if operation.kind == "show" %}
{% if operation.display %}
echo {{ operation.expression }}, PHP_EOL;
{% else %}
var_dump({{ operation.expression }});
{% endif %}
{% else %}
foreach ({{ operation.expression }}{% if operation.optional %} ?? []{% endif %} as ${{ operation.item }}) {
{% for field in operation.fields %}
{% if operation.display %}
    echo {{ field }}, PHP_EOL;
{% else %}
    var_dump({{ field }});
{% endif %}
{% endfor %}
}
{% endif %}
{% endfor %}
{% else %}
var_dump(${{ result_var }});
{% endif %}
{% endif %}
{% endif %}