<?php

namespace crmeb\utils;

use Pheanstalk\Pheanstalk;

/**
 * Beanstalkd client
 */
class Beanstalk {
    protected static $inst;

    protected $talk;

    protected $config = [];

    protected function __construct()
    {
        $this->config = config('beanstalk');
        $this->talk = Pheanstalk::create($this->config['addr'], $this->config['port']);
    }

    public static function instance()
    {
        if (is_null(self::$inst)) {
            self::$inst = new static();
        }
        return self::$inst;
    }

    public static function __callStatic($name, $arguments)
    {
        return self::instance()->talk->{$name}(...$arguments);
    }
}