1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\roa\controllers; |
4
|
|
|
|
5
|
|
|
use roaresearch\yii2\roa\actions\{ |
6
|
|
|
ProfileFileStream, |
7
|
|
|
ProfileUpdate, |
8
|
|
|
ProfileView |
9
|
|
|
}; |
10
|
|
|
use Yii; |
11
|
|
|
use yii\{base\Model, filters\VerbFilter, rest\OptionsAction}; |
12
|
|
|
|
13
|
|
|
class ProfileResource extends \yii\rest\Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @inheritdoc |
17
|
|
|
*/ |
18
|
|
|
public $updateScenario = Model::SCENARIO_DEFAULT; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string[] array used in `actions\Update::fileAttributes` |
22
|
|
|
* @see actions\LoadFileTrait::$fileAttributes |
23
|
|
|
*/ |
24
|
|
|
public $updateFileAttributes = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
4 |
|
public function behaviors() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
// content negotiator, autenticator, etc moved by default to |
33
|
|
|
// api container |
34
|
|
|
'verbFilter' => [ |
35
|
|
|
'class' => VerbFilter::class, |
36
|
4 |
|
'actions' => $this->verbs(), |
37
|
|
|
], |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheridoc |
43
|
|
|
*/ |
44
|
4 |
|
protected function verbs() |
45
|
|
|
{ |
46
|
4 |
|
$verbs = ['GET', 'PUT', 'PATCH', 'OPTIONS']; |
47
|
|
|
|
48
|
|
|
return [ |
49
|
4 |
|
'view' => $verbs, |
50
|
|
|
'update' => $verbs, |
51
|
|
|
'options' => $verbs, |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheridoc |
57
|
|
|
*/ |
58
|
4 |
|
public function actions() |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
'view' => ['class' => ProfileView::class], |
62
|
|
|
'update' => [ |
63
|
|
|
'class' => ProfileUpdate::class, |
64
|
4 |
|
'scenario' => $this->updateScenario, |
65
|
4 |
|
'fileAttributes' => $this->updateFileAttributes, |
66
|
|
|
], |
67
|
|
|
'options' => ['class' => OptionsAction::class], |
68
|
|
|
'file-stream' => ['class' => ProfileFileStream::class], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|