dev-think-one /
laravel-6connex
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace LaravelSixConnex; |
||
| 5 | |||
| 6 | use \LaravelSixConnex\Exceptions\SixConnexException; |
||
| 7 | |||
| 8 | class SixConnexCall implements CallBody |
||
| 9 | { |
||
| 10 | public static string $typeParameter = '_apicall'; |
||
| 11 | |||
| 12 | protected string $type; |
||
| 13 | protected array $options; |
||
| 14 | |||
| 15 | 8 | public function __construct(array $options = [], ?string $type = null) |
|
| 16 | { |
||
| 17 | 8 | $this->options = $options; |
|
| 18 | 8 | $this->setApiCall($type ?? static::TYPE_READ); |
|
| 19 | } |
||
| 20 | |||
| 21 | 8 | public function setApiCall(string $type = 'read'): self |
|
| 22 | { |
||
| 23 | 8 | if (!in_array($type, [ |
|
| 24 | 8 | static::TYPE_READ, |
|
| 25 | 8 | static::TYPE_READALL, |
|
| 26 | 8 | static::TYPE_CREATE, |
|
| 27 | 8 | static::TYPE_UPDATE, |
|
| 28 | 8 | static::TYPE_DELETE, |
|
| 29 | 8 | ])) { |
|
| 30 | 1 | throw new SixConnexException('Not valid ' . static::$typeParameter); |
|
| 31 | } |
||
| 32 | 8 | $this->type = $type; |
|
| 33 | |||
| 34 | 8 | return $this; |
|
| 35 | } |
||
| 36 | |||
| 37 | 1 | public function options(): array |
|
| 38 | { |
||
| 39 | 1 | return $this->options; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param $key |
||
| 44 | * @param null $value |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 45 | * |
||
| 46 | * @return $this |
||
| 47 | */ |
||
| 48 | 5 | public function addOption($key, $value = null): self |
|
| 49 | { |
||
| 50 | 5 | if (is_array($key)) { |
|
| 51 | 2 | $this->options = array_merge($this->options, $key); |
|
| 52 | } else { |
||
| 53 | 4 | $this->options[ $key ] = $value; |
|
| 54 | } |
||
| 55 | |||
| 56 | 5 | return $this; |
|
| 57 | } |
||
| 58 | |||
| 59 | 1 | public function overrideOptions(array $options): self |
|
| 60 | { |
||
| 61 | 1 | $this->options = $options; |
|
| 62 | |||
| 63 | 1 | return $this; |
|
| 64 | } |
||
| 65 | |||
| 66 | 4 | public function getCallBody(): array |
|
| 67 | { |
||
| 68 | 4 | return array_merge($this->options, [ |
|
| 69 | 4 | static::$typeParameter => $this->type, |
|
| 70 | 4 | ]); |
|
| 71 | } |
||
| 72 | } |
||
| 73 |