BeSimpleSoap/src/BeSimple/SoapClient/SoapRequest.php

198 lines
3.9 KiB
PHP
Raw Normal View History

2011-09-03 21:15:51 +02:00
<?php
/*
* This file is part of the BeSimpleSoapClient.
2011-09-03 21:15:51 +02:00
*
* (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.
*/
2011-09-04 00:42:51 +02:00
namespace BeSimple\SoapClient;
2011-09-03 21:15:51 +02:00
/**
* @author Francis Besset <francis.besset@gmail.com>
*/
class SoapRequest
{
protected $function;
protected $arguments;
protected $options;
2011-09-04 23:42:03 +02:00
protected $headers;
2011-09-03 21:15:51 +02:00
2011-09-04 23:42:03 +02:00
public function __construct($function = null, array $arguments = array(), array $options = array(), array $headers = array())
2011-09-03 21:15:51 +02:00
{
$this->function = $function;
$this->arguments = $arguments;
$this->options = $options;
2011-09-04 23:42:03 +02:00
$this->setHeaders($headers);
2011-09-03 21:15:51 +02:00
}
/**
* @return string The function name
*/
public function getFunction()
{
return $this->function;
}
/**
* @param string The function name
*
* @return SoapRequest
*/
public function setFunction($function)
{
$this->function = $function;
return $this;
}
/**
* @return array An array with all arguments
*/
public function getArguments()
{
return $this->arguments;
}
/**
* @param string The name of the argument
* @param mixed The default value returned if the argument is not exists
*
* @return mixed
*/
public function getArgument($name, $default = null)
{
return $this->hasArgument($name) ? $this->arguments[$name] : $default;
}
/**
* @param string The name of the argument
*
* @return boolean
*/
public function hasArgument($name)
{
return isset($this->arguments[$name]);
}
/**
* @param array An array with arguments
*
* @return SoapRequest
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
/**
* @param string The name of argument
* @param mixed The value of argument
*
* @return SoapRequest
*/
public function addArgument($name, $value)
{
$this->arguments[$name] = $value;
return $this;
}
/**
* @return array An array with all options
*/
public function getOptions()
{
return $this->options;
}
/**
* @param string The name of the option
* @param mixed The default value returned if the option is not exists
*
* @return mixed
*/
public function getOption($name, $default = null)
{
return $this->hasOption($name) ? $this->options[$name] : $default;
}
/**
* @param string The name of the option
*
* @return boolean
*/
public function hasOption($name)
{
return isset($this->options[$name]);
}
/**
* @param array An array with options
*
* @return SoapRequest
*/
public function setOptions(array $options)
{
$this->options = $options;
return $this;
}
2011-09-04 23:42:03 +02:00
/**
* @return array|null
2011-09-04 23:42:03 +02:00
*/
public function getHeaders()
{
return empty($this->headers) ? null : $this->headers;
2011-09-04 23:42:03 +02:00
}
/**
* @param array $headers
*
* @return SoapRequest
*/
public function setHeaders(array $headers)
{
$this->headers = array();
foreach ($headers as $header) {
$this->addHeader($header);
}
return $this;
}
/**
* @param \SoapHeader $header
*
* @return SoapRequest
*/
public function addHeader(\SoapHeader $header)
{
$this->headers[] = $header;
return $this;
}
2011-09-03 21:15:51 +02:00
/**
* @param string The name of option
* @param mixed The value of option
*
* @return SoapRequest
*/
public function addOption($name, $value)
{
$this->options[$name] = $value;
return $this;
}
}