idealo/php-rdkafka-ffi

View on GitHub
src/RdKafka/FFI/CallbackProxy.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types=1);

namespace RdKafka\FFI;

abstract class CallbackProxy
{
    protected \Closure $callback;

    protected function __construct(callable $callback)
    {
        if ($callback instanceof \Closure) {
            $this->callback = $callback;
        } else {
            $this->callback = \Closure::fromCallable($callback);
        }
    }

    public static function create(callable $callback): \Closure
    {
        return \Closure::fromCallable(new static($callback));
    }
}