File tree 3 files changed +35
-8
lines changed
3 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 16
16
use yii \base \Model ;
17
17
use yii \db \ActiveRecordInterface ;
18
18
use yii \helpers \Url ;
19
+ use yii \base \InvalidConfigException ;
19
20
use yii \web \ServerErrorHttpException ;
20
21
use function array_keys ;
21
22
use function call_user_func ;
@@ -111,9 +112,16 @@ public function run()
111
112
112
113
/* @var $model \yii\db\ActiveRecord */
113
114
$ model = new $ this ->modelClass ();
114
- $ model ->setScenario (is_callable ($ this ->scenario ) ?
115
- call_user_func ($ this ->scenario , $ this ->id , $ model ) : $ this ->scenario
116
- );
115
+
116
+ if (is_string ($ this ->scenario )) {
117
+ $ scenario = $ this ->scenario ;
118
+ } elseif (is_callable ($ this ->scenario )) {
119
+ $ scenario = call_user_func ($ this ->scenario , $ this ->id , $ model );
120
+ } else {
121
+ throw new InvalidConfigException ('The "scenario" property must be defined either as a string or as a callable. ' );
122
+ }
123
+ $ model ->setScenario ($ scenario );
124
+
117
125
RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
118
126
$ model ->load ($ this ->getResourceAttributes (), '' );
119
127
if ($ this ->isParentRestrictionRequired ()) {
Original file line number Diff line number Diff line change 10
10
use Closure ;
11
11
use Yii ;
12
12
use yii \base \Model ;
13
+ use yii \base \InvalidConfigException ;
13
14
use yii \web \ForbiddenHttpException ;
14
15
use yii \web \ServerErrorHttpException ;
15
16
@@ -65,12 +66,20 @@ public function run($id):void
65
66
throw new ForbiddenHttpException ('Update with relationships not supported yet ' );
66
67
}
67
68
$ model = $ this ->isParentRestrictionRequired () ? $ this ->findModelForParent ($ id ) : $ this ->findModel ($ id );
68
- $ model ->setScenario (is_callable ($ this ->scenario ) ?
69
- call_user_func ($ this ->scenario , $ this ->id , $ model ) : $ this ->scenario
70
- );
69
+
70
+ if (is_string ($ this ->scenario )) {
71
+ $ scenario = $ this ->scenario ;
72
+ } elseif (is_callable ($ this ->scenario )) {
73
+ $ scenario = call_user_func ($ this ->scenario , $ this ->id , $ model );
74
+ } else {
75
+ throw new InvalidConfigException ('The "scenario" property must be defined either as a string or as a callable. ' );
76
+ }
77
+ $ model ->setScenario ($ scenario );
78
+
71
79
if ($ this ->checkAccess ) {
72
80
call_user_func ($ this ->checkAccess , $ this ->id , $ model );
73
81
}
82
+
74
83
if ($ model ->delete () === false ) {
75
84
throw new ServerErrorHttpException ('Failed to delete the object for unknown reason. ' );
76
85
}
Original file line number Diff line number Diff line change 15
15
use Yii ;
16
16
use yii \base \Model ;
17
17
use yii \db \ActiveRecord ;
18
+ use yii \base \InvalidConfigException ;
18
19
use yii \web \ServerErrorHttpException ;
19
20
20
21
/**
@@ -98,11 +99,20 @@ public function run($id):Item
98
99
{
99
100
/* @var $model ActiveRecord */
100
101
$ model = $ this ->isParentRestrictionRequired () ? $ this ->findModelForParent ($ id ) : $ this ->findModel ($ id );
101
- $ model ->scenario = is_callable ($ this ->scenario ) ?
102
- call_user_func ($ this ->scenario , $ this ->id , $ model ) : $ this ->scenario ;
102
+
103
+ if (is_string ($ this ->scenario )) {
104
+ $ scenario = $ this ->scenario ;
105
+ } elseif (is_callable ($ this ->scenario )) {
106
+ $ scenario = call_user_func ($ this ->scenario , $ this ->id , $ model );
107
+ } else {
108
+ throw new InvalidConfigException ('The "scenario" property must be defined either as a string or as a callable. ' );
109
+ }
110
+ $ model ->setScenario ($ scenario );
111
+
103
112
if ($ this ->checkAccess ) {
104
113
call_user_func ($ this ->checkAccess , $ this ->id , $ model );
105
114
}
115
+
106
116
$ originalModel = clone $ model ;
107
117
RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
108
118
if (empty ($ this ->getResourceAttributes ()) && $ this ->hasResourceRelationships ()) {
You can’t perform that action at this time.
0 commit comments