/** * Attach two-way sync needed behaviors for REST action * @param ActionEvent $event * @return bool * @throws NotSupportedException */ public function beforeRestAction(ActionEvent $event) { /** @var Action $action */ $action = $event->action; Event::on(BaseActiveRecord::className(), BaseActiveRecord::EVENT_INIT, [$this, 'makeModelSyncable'], null, false); switch (get_class($action)) { case IndexAction::className(): $action->attachBehavior('indexLatest', IndexLatestBehavior::className()); break; case CreateAction::className(): // nothing to attach on create for now // TODO: check is needed to behave something here break; case UpdateAction::className(): $action->attachBehavior('updateConflict', UpdateConflictBehavior::className()); break; default: // TODO: implement custom new so called 'TwoWaySync action' stub for future custom actions // TODO: and add method attachSyncBehaviors() // $action->attachSyncBehaviors(); // throw new NotSupportedException("Not implemented yet"); break; } return $event->isValid; }