PassageProxy.php 1008 字节
<?php

namespace Lackoxygen\TiktokShop\Passage;

use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Exception\{ClientException, ExpiredException};

class PassageProxy
{
    protected string $passage;

    protected Config $config;

    protected function __construct(string $passage, Config $config)
    {
        $this->passage = $passage;

        $this->config = $config;
    }

    public static function proxy(string $passage, Config $config): PassageProxy
    {
        return new self($passage, $config);
    }

    /**
     * @throws ClientException
     * @throws ExpiredException
     */
    public function __call($name, $arguments): ResultSet
    {
        /**
         * @var Passage $passage
         */
        $passage = new $this->passage($this->config, $name);

        $result = call_user_func_array([$passage, $name], $arguments);

        if (!is_null($result)) {
            return new ResultSet($result);
        }

        return new ResultSet($passage());
    }
}