BeSimpleSoap/src/BeSimple/SoapClient/SoapClientBuilder.php

115 lines
2.5 KiB
PHP
Raw Normal View History

2011-10-09 20:17:50 +02:00
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapClient;
use BeSimple\SoapCommon\AbstractSoapBuilder;
/**
* @author Francis Besset <francis.besset@gmail.com>
* @author Christian Kerl <christian-kerl@web.de>
2011-10-09 20:17:50 +02:00
*/
class SoapClientBuilder extends AbstractSoapBuilder
{
protected $soapOptionAuthentication = array();
2011-10-09 20:17:50 +02:00
/**
* @return SoapClientBuilder
*/
static public function createWithDefaults()
{
return parent::createWithDefaults()
->withUserAgent('BeSimpleSoap')
;
}
2011-10-10 00:21:23 +02:00
/**
* @return SoapClient
*/
public function build()
{
$this->validateOptions();
2011-10-11 21:50:07 +02:00
return new SoapClient($this->wsdl, $this->getSoapOptions());
}
public function getSoapOptions()
{
return parent::getSoapOptions() + $this->soapOptionAuthentication;
2011-10-10 00:21:23 +02:00
}
/**
* @return SoapClientBuilder
*/
2011-10-09 20:17:50 +02:00
public function withTrace($trace = true)
{
2011-10-10 00:02:20 +02:00
$this->soapOptions['trace'] = $trace;
2011-10-09 20:17:50 +02:00
return $this;
}
2011-10-10 00:21:23 +02:00
/**
* @return SoapClientBuilder
*/
2011-10-09 20:17:50 +02:00
public function withExceptions($exceptions = true)
{
2011-10-10 00:02:20 +02:00
$this->soapOptions['exceptions'] = $exceptions;
2011-10-09 20:17:50 +02:00
return $this;
}
2011-10-10 00:21:23 +02:00
/**
* @return SoapClientBuilder
*/
2011-10-09 20:17:50 +02:00
public function withUserAgent($userAgent)
{
2011-10-10 00:02:20 +02:00
$this->soapOptions['user_agent'] = $userAgent;
2011-10-09 20:17:50 +02:00
return $this;
}
2011-10-10 00:21:23 +02:00
/**
* @return SoapClientBuilder
*/
public function withBasicAuthentication($username, $password)
{
$this->soapOptionAuthentication = array(
'authentication' => SOAP_AUTHENTICATION_BASIC,
'login' => $username,
2011-10-11 21:50:07 +02:00
'password' => $password,
);
return $this;
}
/**
* @return SoapClientBuilder
*/
2011-10-11 21:50:07 +02:00
public function withDigestAuthentication($certificate, $passphrase = null)
{
$this->soapOptionAuthentication = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'local_cert' => $certificate,
);
2011-10-11 21:50:07 +02:00
if ($passphrase) {
$this->soapOptionAuthentication['passphrase'] = $passphrase;
}
return $this;
}
2011-10-10 00:21:23 +02:00
protected function validateOptions()
{
$this->validateWsdl();
}
2011-10-09 20:17:50 +02:00
}