Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

By not declaring $this->client, client is effectively added later on in your objects life, which means property lookups will be slowerproperty lookups will be slower, but more importantly: $this->client will be a public property. If $this->client is public, then you don't have a wrapper because:

By not declaring $this->client, client is effectively added later on in your objects life, which means property lookups will be slower, but more importantly: $this->client will be a public property. If $this->client is public, then you don't have a wrapper because:

By not declaring $this->client, client is effectively added later on in your objects life, which means property lookups will be slower, but more importantly: $this->client will be a public property. If $this->client is public, then you don't have a wrapper because:

added 86 characters in body
Source Link

By not declaring $this->client, client is effectively added later on toin your objectobjects life, resulting in marginally slower codewhich means property lookups will be slower, but more importantly: $this->client will be a public propertiesproperty. If $this->client is public, then you don't have a wrapper because:

By not declaring $this->client, client is effectively added later on to your object, resulting in marginally slower code but more importantly: public properties. If $this->client is public, then you don't have a wrapper because:

By not declaring $this->client, client is effectively added later on in your objects life, which means property lookups will be slower, but more importantly: $this->client will be a public property. If $this->client is public, then you don't have a wrapper because:

added 3524 characters in body
Source Link
class BaseClient
{
    protected $client = null;//declare your properties!!!
    protected $config = null;
    //use type hints, default = null means you don't HAVE to pass the argument
    public function __construct(\SoapClient $client = null)
    {
        $this->client = $client;
    }
    //lazy-loading getter
    protected function getClient()
    {
        if ($this->client === null)
        {//set client only when it's required
            $this->setClient(
                new \SoapClient($this->config['wsdl'], $config['options']
            );
        }
        return $this->client;
    }
    //public to allow injection
    protected function setClient(\SoapClient $client)
    {
        $this->client = $client;
        return $this;//makes your api chainable
    }
}

Declare your properties

From the wrapper tag wiki:

A wrapper is an OOP technique where an object encapsulates (wraps) another object, hiding/protecting the object and controlling all access to it.

By not declaring $this->client, client is effectively added later on to your object, resulting in marginally slower code but more importantly: public properties. If $this->client is public, then you don't have a wrapper because:

A wrapper [...] encapsulates another object, hiding/protecting the object and controlling all access to it.

Thus, $this->client has to be protected or private.
Next.

class BaseClient
{
    protected $client = null;
    protected $config = null;
    //use type hints, default = null means you don't HAVE to pass the argument
    public function __construct(\SoapClient $client = null)
    {
        $this->client = $client;
    }
    //lazy-loading getter
    protected function getClient()
    {
        if ($this->client === null)
        {//set client only when it's required
            $this->setClient(
                new \SoapClient($this->config['wsdl'], $config['options']
            );
        }
        return $this->client;
    }
    //public to allow injection
    protected function setClient(\SoapClient $client)
    {
        $this->client = $client;
        return $this;//makes your api chainable
    }
}
class BaseClient
{
    protected $client = null;//declare your properties!!!
    protected $config = null;
    //use type hints, default = null means you don't HAVE to pass the argument
    public function __construct(\SoapClient $client = null)
    {
        $this->client = $client;
    }
    //lazy-loading getter
    protected function getClient()
    {
        if ($this->client === null)
        {//set client only when it's required
            $this->setClient(
                new \SoapClient($this->config['wsdl'], $config['options']
            );
        }
        return $this->client;
    }
    //public to allow injection
    protected function setClient(\SoapClient $client)
    {
        $this->client = $client;
        return $this;//makes your api chainable
    }
}

Declare your properties

From the wrapper tag wiki:

A wrapper is an OOP technique where an object encapsulates (wraps) another object, hiding/protecting the object and controlling all access to it.

By not declaring $this->client, client is effectively added later on to your object, resulting in marginally slower code but more importantly: public properties. If $this->client is public, then you don't have a wrapper because:

A wrapper [...] encapsulates another object, hiding/protecting the object and controlling all access to it.

Thus, $this->client has to be protected or private.
Next.

added 3524 characters in body
Source Link
Loading
added 3524 characters in body
Source Link
Loading
Source Link
Loading