1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This Driver is based entirely on official documentation of the Mattermost Web
|
4
|
|
|
* Services API and you can extend it by following the directives of the documentation.
|
5
|
|
|
*
|
6
|
|
|
* For the full copyright and license information, please read the LICENSE.txt
|
7
|
|
|
* file that was distributed with this source code. For the full list of
|
8
|
|
|
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
|
9
|
|
|
*
|
10
|
|
|
* God bless this mess.
|
11
|
|
|
*
|
12
|
|
|
* @author Luca Agnello <[email protected]>
|
13
|
|
|
* @link https://api.mattermost.com/
|
14
|
|
|
*/
|
15
|
|
|
|
16
|
|
|
namespace Gnello\Mattermost\Models;
|
17
|
|
|
|
18
|
|
|
use Gnello\Mattermost\Client;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* Class AbstractModel
|
22
|
|
|
*
|
23
|
|
|
* @package Gnello\Mattermost
|
24
|
|
|
*/
|
25
|
|
|
abstract class AbstractModel
|
26
|
|
|
{
|
27
|
|
|
/**
|
28
|
|
|
* @var Client
|
29
|
|
|
*/
|
30
|
|
|
protected $client;
|
31
|
|
|
|
32
|
|
|
/**
|
33
|
|
|
* AbstractModel constructor.
|
34
|
|
|
*
|
35
|
|
|
* @param Client $client
|
36
|
|
|
*/
|
37
|
|
|
public function __construct(Client $client)
|
38
|
|
|
{
|
39
|
|
|
$this->client = $client;
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/**
|
43
|
|
|
* Builds multipart data options.
|
44
|
|
|
*
|
45
|
|
|
* @param array $requestOptions The options to pass to the server.
|
46
|
|
|
* @param array $requiredFields The required fields of the server.
|
47
|
|
|
* @return array
|
48
|
|
|
*/
|
49
|
|
|
protected static function buildMultipartDataOptions(array $requestOptions = [], array $requiredFields = [])
|
50
|
|
|
{
|
51
|
|
|
$multipartDataOptions = [];
|
52
|
|
|
|
53
|
|
|
//required fields
|
54
|
|
|
foreach ($requiredFields as $field) {
|
55
|
|
|
$multipartDataOptions[] = [
|
56
|
|
|
'name' => $field,
|
57
|
|
|
'contents' => empty($requestOptions[$field]) ? null : $requestOptions[$field],
|
58
|
|
|
];
|
59
|
|
|
|
60
|
|
|
unset($requestOptions[$field]);
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
//optional fields
|
64
|
|
|
foreach ($requestOptions as $field => $value) {
|
65
|
|
|
$multipartDataOptions[] = [
|
66
|
|
|
'name' => $field,
|
67
|
|
|
'contents' => empty($value) ? null : $value,
|
68
|
|
|
];
|
69
|
|
|
}
|
70
|
|
|
|
71
|
|
|
return $multipartDataOptions;
|
72
|
|
|
}
|
73
|
|
|
} |