1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
<?php
namespace hji\membership\models\webservice\abstracts;
use hji\membership\abstracts\Model;
use hji\membership\models\webservice\interfaces\ISearchable;
use hji\membership\models\webservice\interfaces\IGettable;
use hji\membership\models\webservice\WebServiceOptions;
abstract class WebService extends Model implements ISearchable, IGettable
{
public function search(){}
public function get(){}
protected $path;
protected $rawParameters;
protected $filters;
protected $options;
protected $method;
public function __construct(WebServiceFilters $filters, WebServiceOptions $options)
{
$this->filters = $filters;
$this->options = $options;
}
public function getData()
{
return $this->call();
}
public function setParameters(array $parameters)
{
$this->rawParameters = $parameters;
if ($this->filters && $this->options)
{
if (!empty($parameters))
{
foreach ($parameters as $k => $v)
{
$this->filters->set($k, $v);
$this->options->set($k, $v);
}
}
}
}
function getParameters()
{
$params = array();
if ($this->filters)
{
$params = array_merge($params, $this->filters->getAll());
}
if ($this->options)
{
$params = array_merge($params, $this->options->getAll());
}
return array_filter($params);
}
public function setMethod($method)
{
$this->method = $method;
}
public function call()
{
if (is_callable(array($this, $this->method)))
{
return call_user_func(array($this, $this->method));
}
else
{
throw new \Exception("WebService method {$this->method} does not exist.");
}
}
public function getPath()
{
$path = $this->path;
if ($this->method)
{
$path .= '/' . $this->method;
}
return $path;
}
public function getFilters()
{
return $this->filters;
}
public function getOptions()
{
return $this->options;
}
}