1 | <?php |
||
31 | class ApiVersion extends \yii\base\Module implements UrlRuleCreator |
||
32 | { |
||
33 | const STABILITY_DEVELOPMENT = 'development'; |
||
34 | const STABILITY_STABLE = 'stable'; |
||
35 | const STABILITY_DEPRECATED = 'deprecated'; |
||
36 | const STABILITY_OBSOLETE = 'obsolete'; |
||
37 | |||
38 | /** |
||
39 | * @var string subfix used to create the default classes |
||
40 | */ |
||
41 | public $controllerSubfix = 'Resource'; |
||
42 | |||
43 | /** |
||
44 | * @var string full class name which will be used as default for routing. |
||
45 | */ |
||
46 | public $urlRuleClass = ResourceUrlRule::class; |
||
47 | |||
48 | /** |
||
49 | * @var string date in Y-m-d format for the date at which this version |
||
50 | * became stable |
||
51 | */ |
||
52 | public $releaseDate; |
||
53 | |||
54 | /** |
||
55 | * @var string date in Y-m-d format for the date at which this version |
||
56 | * became deprecated |
||
57 | */ |
||
58 | public $deprecationDate; |
||
59 | |||
60 | /** |
||
61 | * @var string date in Y-m-d format for the date at which this version |
||
62 | * became obsolete |
||
63 | */ |
||
64 | public $obsoleteDate; |
||
65 | |||
66 | /** |
||
67 | * @var string URL where the api documentation can be found. |
||
68 | */ |
||
69 | public $apidoc = null; |
||
70 | |||
71 | /** |
||
72 | * @var array|ResponseFormatterInterface[] response formatters which will |
||
73 | * be attached to `Yii::$app->response->formatters`. By default just enable |
||
74 | * HAL responses. |
||
75 | */ |
||
76 | public $responseFormatters = [ |
||
77 | Response::FORMAT_JSON => [ |
||
78 | 'class' => JsonResponseFormatter::class, |
||
79 | 'contentType' => JsonResponseFormatter::CONTENT_TYPE_HAL_JSON, |
||
80 | ], |
||
81 | Response::FORMAT_XML => [ |
||
82 | 'class' => XmlResponseFormatter::class, |
||
83 | 'contentType' => 'application/hal+xml', |
||
84 | ], |
||
85 | ]; |
||
86 | |||
87 | /** |
||
88 | * @var string the stability level |
||
89 | */ |
||
90 | protected $stability = self::STABILITY_DEVELOPMENT; |
||
91 | |||
92 | /** |
||
93 | * @return string the stability defined for this version. |
||
94 | */ |
||
95 | public function getStability(): string |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public $defaultRoute = 'index'; |
||
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | public $controllerMap = ['index' => ApiVersionController::class]; |
||
109 | |||
110 | /** |
||
111 | * @var string[] list of 'patternRoute' => 'resource' pairs to connect a |
||
112 | * route to a resource. if no key is used, then the value will be the |
||
113 | * pattern too. |
||
114 | * |
||
115 | * Special properties: |
||
116 | * |
||
117 | * - urlRule array the configuration for how the routing url rules will be |
||
118 | * created before attaching them to urlManager. |
||
119 | * |
||
120 | * ```php |
||
121 | * [ |
||
122 | * 'profile', // resources\ProfileResource |
||
123 | * 'profile/history', // resources\profile\HistoryResource |
||
124 | * 'profile/image' => [ |
||
125 | * 'class' => resources\profile\ImageResource::class, |
||
126 | * 'urlRule' => ['class' => 'roaresearch\yii2\\roa\\urlRules\\File'], |
||
127 | * ], |
||
128 | * 'post' => ['class' => resources\post\PostResource::class], |
||
129 | * 'post/<post_id:[\d]+>/reply', // resources\post\ReplyResource |
||
130 | * ] |
||
131 | * ``` |
||
132 | */ |
||
133 | public $resources = []; |
||
134 | |||
135 | /** |
||
136 | * @return string[] gets the list of routes allowed for this api version. |
||
137 | */ |
||
138 | public function getRoutes(): array |
||
148 | |||
149 | /** |
||
150 | * @return array stability, life cycle and resources for this version. |
||
151 | */ |
||
152 | public function getFactSheet(): array |
||
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | public function init() |
||
205 | |||
206 | /** |
||
207 | * @inheritdoc |
||
208 | */ |
||
209 | public function beforeAction($action) |
||
221 | |||
222 | /** |
||
223 | * @return array list of configured urlrules by default |
||
|
|||
224 | */ |
||
225 | protected function defaultUrlRules() |
||
236 | |||
237 | /** |
||
238 | * @inheritdoc |
||
239 | */ |
||
240 | public function createUrlRules(CompositeUrlRule $urlRule): array |
||
280 | |||
281 | /** |
||
282 | * Converts a ROA route to an MVC route to be handled by `$controllerMap` |
||
283 | * |
||
284 | * @param string $roaRoute |
||
285 | * @return string |
||
286 | */ |
||
287 | private function buildControllerRoute(string $roaRoute): string |
||
298 | |||
299 | /** |
||
300 | * Converts an MVC route to the default controller class. |
||
301 | * |
||
302 | * @param string $controllerRoute |
||
303 | * @return string |
||
304 | */ |
||
305 | private function buildControllerClass(string $controllerRoute): string |
||
321 | |||
322 | /** |
||
323 | * @param string $date in 'Y-m-d' format |
||
324 | * @return ?int unix timestamp |
||
325 | */ |
||
326 | private function calcTime($date): ?int |
||
339 | |||
340 | /** |
||
341 | * @return string HTTP Url linking to this module |
||
342 | */ |
||
343 | public function getSelfLink(): string |
||
347 | } |
||
348 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.