File tree Expand file tree Collapse file tree 3 files changed +35
-8
lines changed Expand file tree Collapse file tree 3 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 1616use yii \base \Model ;
1717use yii \db \ActiveRecordInterface ;
1818use yii \helpers \Url ;
19+ use yii \base \InvalidConfigException ;
1920use yii \web \ServerErrorHttpException ;
2021use function array_keys ;
2122use function call_user_func ;
@@ -111,9 +112,16 @@ public function run()
111112
112113 /* @var $model \yii\db\ActiveRecord */
113114 $ 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+
117125 RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
118126 $ model ->load ($ this ->getResourceAttributes (), '' );
119127 if ($ this ->isParentRestrictionRequired ()) {
Original file line number Diff line number Diff line change 1010use Closure ;
1111use Yii ;
1212use yii \base \Model ;
13+ use yii \base \InvalidConfigException ;
1314use yii \web \ForbiddenHttpException ;
1415use yii \web \ServerErrorHttpException ;
1516
@@ -65,12 +66,20 @@ public function run($id):void
6566 throw new ForbiddenHttpException ('Update with relationships not supported yet ' );
6667 }
6768 $ 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+
7179 if ($ this ->checkAccess ) {
7280 call_user_func ($ this ->checkAccess , $ this ->id , $ model );
7381 }
82+
7483 if ($ model ->delete () === false ) {
7584 throw new ServerErrorHttpException ('Failed to delete the object for unknown reason. ' );
7685 }
Original file line number Diff line number Diff line change 1515use Yii ;
1616use yii \base \Model ;
1717use yii \db \ActiveRecord ;
18+ use yii \base \InvalidConfigException ;
1819use yii \web \ServerErrorHttpException ;
1920
2021/**
@@ -98,11 +99,20 @@ public function run($id):Item
9899 {
99100 /* @var $model ActiveRecord */
100101 $ 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+
103112 if ($ this ->checkAccess ) {
104113 call_user_func ($ this ->checkAccess , $ this ->id , $ model );
105114 }
115+
106116 $ originalModel = clone $ model ;
107117 RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
108118 if (empty ($ this ->getResourceAttributes ()) && $ this ->hasResourceRelationships ()) {
You can’t perform that action at this time.
0 commit comments