<?php

namespace Plainwork\Core;

class ObjectProxy
{
    private string $className;
    private $objectMethodCaller;

    public function __construct(string $className, callable $objectMethodCaller)
    {
        $this->className = $className;
        $this->objectMethodCaller = $objectMethodCaller;
    }

    public function _exists()
    {
        return class_exists($this->className);
    }

    // public function __toString()
    // {
        // return $this->className;
    // }

    // public function __invoke()
    // {
        // return ($this->objectMethodCaller)($this->className, ...func_get_args());
    // }

    // public function __invoke(&...$args)
    public function __invoke(...$args)
    {
        return ($this->objectMethodCaller)($this->className, ...$args);
    }

    public function __call($methodName, $args)
    {
        return ($this->objectMethodCaller)([$this->className, $methodName], ...$args);
    }
}
