/
ConfigureApiController.php
139 lines (123 loc) · 2.88 KB
/
ConfigureApiController.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Event;
use Flarum\Api\Controller\AbstractSerializeController;
class ConfigureApiController
{
/**
* @var AbstractSerializeController
*/
public $controller;
/**
* @param AbstractSerializeController $controller
*/
public function __construct(AbstractSerializeController $controller)
{
$this->controller = $controller;
}
/**
* @param string $controller
* @return bool
*/
public function isController($controller)
{
return $this->controller instanceof $controller;
}
/**
* Set the serializer that will serialize data for the endpoint.
*
* @param string $serializer
*/
public function setSerializer($serializer)
{
$this->controller->serializer = $serializer;
}
/**
* Include the given relationship by default.
*
* @param string|array $name
*/
public function addInclude($name)
{
$this->controller->include = array_merge($this->controller->include, (array) $name);
}
/**
* Don't include the given relationship by default.
*
* @param string $name
*/
public function removeInclude($name)
{
array_forget($this->controller->include, $name);
}
/**
* Make the given relationship available for inclusion.
*
* @param string $name
*/
public function addOptionalInclude($name)
{
$this->controller->optionalInclude[] = $name;
}
/**
* Don't allow the given relationship to be included.
*
* @param string $name
*/
public function removeOptionalInclude($name)
{
array_forget($this->controller->optionalInclude, $name);
}
/**
* Set the default number of results.
*
* @param int $limit
*/
public function setLimit($limit)
{
$this->controller->limit = $limit;
}
/**
* Set the maximum number of results.
*
* @param int $max
*/
public function setMaxLimit($max)
{
$this->controller->maxLimit = $max;
}
/**
* Allow sorting results by the given field.
*
* @param string $field
*/
public function addSortField($field)
{
$this->controller->sortFields[] = $field;
}
/**
* Disallow sorting results by the given field.
*
* @param string $field
*/
public function removeSortField($field)
{
array_forget($this->controller->sortFields, $field);
}
/**
* Set the default sort order for the results.
*
* @param array $sort
*/
public function setSort(array $sort)
{
$this->controller->sort = $sort;
}
}