/** * @inheritdoc */ public function rules() { return [[['class_name'], 'required', 'whenClient' => 'function(){return false;}'], [['class_name'], ClassnameValidator::className()], [['clientType'], 'required'], [['clientType'], 'in', 'range' => [self::TYPE_OAUTH1, self::TYPE_OAUTH2, self::TYPE_OPENID]], [['consumerKey', 'consumerSecret'], 'required', 'when' => function ($model) { return $model->clientType === self::TYPE_OAUTH1; }], [['clientId', 'clientSecret'], 'required', 'when' => function ($model) { return $model->clientType === self::TYPE_OAUTH2; }], [['id', 'name', 'title'], 'string']]; }
/** * @inheritdoc */ public function rules() { return [[['serverName', 'serverPort', 'cacheClass', 'keyPrefix'], 'filter', 'filter' => 'trim'], [['serverName', 'cacheClass'], 'required'], [['useMemcached'], 'filter', 'filter' => 'boolval'], [['useMemcached'], 'boolean'], [['cacheClass'], \app\validators\ClassnameValidator::className()]]; }
/** * Override base init function to add event handler that will handle auth clients during configuration editing */ public function init() { parent::init(); $this->on(self::configurationSaveEvent(), function ($event) { /** @var ConfigConfigurationModel $model */ $model = $event->configurableModel; if (YII_CONSOLE === true) { return; } if (intval(Yii::$app->request->post('addAuthClientFlag', 0)) === 1 && isset($_POST['AuthClientConfig'][-1]['class_name']) === true) { // new auth client added $class_name = $_POST['AuthClientConfig'][-1]['class_name']; $validator = new ClassnameValidator(); // Hey, there's no error here - validator should return null if there's no errors if ($validator->validateValue($class_name) === null) { $new = new AuthClientConfig(); $new->class_name = $class_name; $new->determineType(); $model->authClients[] = $new; } else { Yii::$app->session->addFlash('error', Yii::t('app', 'The class you wanted to add as auth client doesn\'t exist.')); } } if (intval(Yii::$app->request->post('removeAuthClientIndex', -1)) >= 0) { $indexToRemove = intval(Yii::$app->request->post('removeAuthClientIndex', -1)); if (isset($model->authClients[$indexToRemove]) === true) { unset($model->authClients[$indexToRemove]); Yii::$app->session->addFlash('info', Yii::t('app', 'Auth client was deleted.')); } else { Yii::$app->session->addFlash('error', Yii::t('app', 'Bad auth client index specified.')); } } $authClientsData = Yii::$app->request->post('AuthClientConfig'); $isValid = true; if (is_array($authClientsData) === true) { foreach ($authClientsData as $index => $data) { if (isset($model->authClients[$index]) === true) { $model->authClients[$index]->setAttributes($data); $model->authClients[$index]->determineType(); if ($model->authClients[$index]->validate() === false) { $isValid = false; } } } } if ($isValid === false) { Yii::$app->session->addFlash('warning', Yii::t('app', 'Please fill in all required information for auth client configuration.')); } }); }
/** * @inheritdoc */ public function rules() { return [[['name', 'class_name'], 'required'], [['params'], 'string'], [['name', 'class_name', 'configuration_model'], 'string', 'max' => 255], [['class_name', 'configuration_model'], app\validators\ClassnameValidator::className()]]; }