<?php
namespace App\models\Logistic\Api\Custom\Client;
use App\models\Logistic\Api\Custom\AbstractClient;
use App\models\Logistic\Api\Custom\ClientConfig;
use Pheanstalk\Pheanstalk;
class BeanStalk extends AbstractClient{
    protected $xml;
    protected $client;
    protected $clientConfig;
    public function __construct(ClientConfig $config){
        $this->clientConfig=$config;
    }
    public function get(){

    }
    public function send()
    {
        $configInfo = $this->clientConfig->getConfig();
        $client = $this->getClient();
        $client->useTube($configInfo['queue']);
        return $client->put($this->xml);
    }
    protected function getClient(){
        if(empty($this->client)){
            $configInfo = $this->clientConfig->getConfig();
            $beanstalkClient = Pheanstalk::create($configInfo['host'], $configInfo['port']);
            //var_dump($beanstalkClient);
            //$beanstalkClient =new Pheanstalk();

            $this->client=$beanstalkClient;
            //var_dump($this->client);
        }
        return $this->client;
    }
    public function setSendInf(...$sendInf)
    {
        $xml = $sendInf[0];
        $this->xml = $xml;
        return $this;
    }
}
