Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

RestoreResource::verbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace roaresearch\yii2\roa\controllers;
4
5
use roaresearch\yii2\roa\actions\Restore;
6
7
/**
8
 * Resource to handle restoration of soft deleted records.
9
 *
10
 * ```php
11
 * class ShopRestoreResource extends RestoreRestource
12
 * {
13
 *     public function baseQuery(): ActiveQuery
14
 *     {
15
 *         returns Shop::find()->andWhere(['isDeleted' => false]);
16
 *     }
17
 * }
18
 * ```
19
 *
20
 * The verb GET works on both collections and records to give reading access.
21
 *
22
 * By default the verb DELETE is enabled and its meant to permanently delete
23
 * a record but can be disabled by unsetting the verb.
24
 *
25
 * The verbs POST, PATCH and PUT work only on records to restore them.
26
 */
27
class RestoreResource extends Resource
28
{
29
    /**
30
     * @inheritdoc
31
     */
32
    protected function verbs()
33
    {
34
        $verbs = parent::verbs();
35
        unset($verbs['create']);
36
37
        return $verbs;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function actions()
44
    {
45
        $actions = parent::actions();
46
        unset($actions['create']);
47
        $actions['update'] = [
48
            'class' => Restore::class,
49
            'modelClass' => $this->modelClass,
50
            'findModel' => [$this, 'findModel'],
51
        ];
52
53
        return $actions;
54
    }
55
}
56