本文整理汇总了PHP中yii\helpers\ArrayHelper::keyExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::keyExists方法的具体用法?PHP ArrayHelper::keyExists怎么用?PHP ArrayHelper::keyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::keyExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initUserAttributes
/**
* @inheritdoc
*/
protected function initUserAttributes()
{
$data = [];
foreach (explode(" ", $this->scope) as $scope) {
if (in_array($scope, $this->_userinfoscopes)) {
$api = $this->api($scope, 'GET');
if (ArrayHelper::getValue($api, 'status') !== "ok") {
Yii:
trace("Server error: " . print_r($api, true));
throw new InvalidResponseException($api, "error", print_r($api, true));
}
$apiData = ArrayHelper::getValue($api, 'data', []);
if ($scope === "profile") {
if (ArrayHelper::getValue($apiData, 'blacklisted') !== false || ArrayHelper::getValue($apiData, 'quarantine') !== false || ArrayHelper::getValue($apiData, 'verified') !== true) {
Yii::trace("OAuth Failed. Provider V. Data: " . print_r($api, true), 'oauth');
throw new UserNotAllowedException("User is blacklisted, quarantined or not verified");
}
if (ArrayHelper::keyExists('enlid', $apiData)) {
if (ArrayHelper::getValue($apiData, 'enlid') === "null") {
Yii:
trace("enlid is null", 'oauth');
throw new UserNotAllowedException("Userprofile incomplete");
} else {
$data['id'] = ArrayHelper::getValue($data, 'enlid');
}
}
}
$data = array_merge($data, $apiData);
}
}
return $data;
}
示例2: getFilter
/**
* @param $name
* @return Filter
*/
public function getFilter($name)
{
if (!ArrayHelper::keyExists($name, $this->_filters)) {
$this->addFilter($name);
}
return $this->_filters[$name];
}
示例3: __get
/**
* Check whether we have a plugin installed with that name previous firing up the call
*
* @param string $name
*
* @return mixed|void
*/
public function __get($name)
{
if (ArrayHelper::keyExists($name, $this->getInstalledPlugins())) {
return $this->getPlugin($name);
}
return parent::__get($name);
}
示例4: getWidget
/**
* @param $name
* @return VisioWidget
*/
public function getWidget($name)
{
if (!ArrayHelper::keyExists($name, $this->_widgets)) {
$this->addWidget($name);
}
return $this->_widgets[$name];
}
示例5: addOriginalText
/**
* Add Original Text
* @param string $text
* @param int $yandexSiteID
* @throws InvalidParamException
* @return string|bool
*/
public function addOriginalText($text, $yandexSiteID)
{
/** @var Cache $cache */
$cache = \Yii::$app->get($this->cacheComponent);
$cacheKey = "Yandex_OT_sent:" . $this->clientID . "_" . $this->clientSecret;
$sent = $cache->get($cacheKey);
if ($sent === false) {
$sent = 0;
}
if ($sent >= self::YANDEX_OT_DAILY_LIMIT) {
throw new InvalidParamException("Daily limit exceeded!");
}
$validator = new StringValidator(['min' => self::YANDEX_OT_MIN, 'max' => self::YANDEX_OT_MAX, 'enableClientValidation' => false]);
if (!$validator->validate($text, $error)) {
throw new InvalidParamException($error);
}
$text = urlencode(htmlspecialchars($text));
$text = "<original-text><content>{$text}</content></original-text>";
$response = $this->apiClient->rawApi("hosts/{$yandexSiteID}/original-texts/", "POST", $text);
$success = ArrayHelper::keyExists('id', $response) && ArrayHelper::keyExists('link', $response);
if ($success) {
$sent++;
$cache->set($cacheKey, $sent, 60 * 60 * 24);
}
return $success;
}
示例6: getSelect2Type
public function getSelect2Type()
{
if (ArrayHelper::keyExists('ajax', $this->pluginOptions) and $this->pluginOptions['ajax']) {
return 'ajax';
}
return false;
}
示例7: init
public function init()
{
parent::init();
if (!ArrayHelper::keyExists('url', $this->clientOptions)) {
throw \yii\base\InvalidConfigException('Url key is missing in clientOptions');
}
}
示例8: setDefault
/**
* 设置 summernote 配置默认值
*/
public function setDefault()
{
$ary = ['lang' => SELF::LANG_DEFAULT, 'height' => SELF::HEIGHT_DEFAULT];
foreach ($ary as $k => $v) {
$this->clientOptions[$k] = ArrayHelper::keyExists($k, $this->clientOptions) ? $this->clientOptions[$k] : $v;
}
}
示例9: markAs
/**
* отметить как
* @param $status
*/
public function markAs($status)
{
if (!ArrayHelper::keyExists($status, self::statusNames())) {
throw new \BadMethodCallException("{$status} not found in status_array");
}
$this->status = $status;
$this->save();
}
示例10: requiredCheck
private function requiredCheck()
{
foreach ($this->_requiredOptions as $key) {
if (!ArrayHelper::keyExists($key, $this->_playerOptions, false)) {
throw new InvalidConfigException("JWPlayer Widget: player options missing '{$key}'");
}
}
}
示例11: getActiveUsers
public static function getActiveUsers()
{
$array_ids = static::find()->select(['user_id'])->where('user_id > 0')->asArray()->all();
$ids = \yii\helpers\ArrayHelper::getColumn($array_ids, 'user_id');
$users = UserModels::find()->select(['id', 'username'])->where(['IN', 'id', $ids])->asArray()->all();
if (!ArrayHelper::keyExists('0', $users, false)) {
$users = [0 => ['id' => '0', 'username' => 'Ninguno']];
}
return $users;
}
示例12: jsonController
/**
* Возвращает ответ контроллера
*
* @param mixed $data возвращаемые данные
* [
* 'status' => boolean
* 'data' => данные при положительном срабатывании или сообщение об ошибке
* ]
*
* @return \yii\web\Response json
*/
public function jsonController($data)
{
if ($data['status']) {
if (ArrayHelper::keyExists('data', $data)) {
return self::jsonSuccess($data['data']);
} else {
return self::jsonSuccess();
}
} else {
return self::jsonError($data['data']);
}
}
示例13: initSortable
/**
* Inits sortable behavior
*/
protected function initSortable()
{
$route = ArrayHelper::getValue($this->sortable, 'url', false);
if ($route) {
$url = Url::toRoute($route);
if (ArrayHelper::keyExists('class', $this->itemOptions)) {
$this->itemOptions['class'] = sprintf('%s %s', $this->itemOptions['class'], self::SORTABLE_ITEM_CLASS);
} else {
$this->itemOptions['class'] = self::SORTABLE_ITEM_CLASS;
}
$options = json_encode(ArrayHelper::getValue($this->sortable, 'options', []));
$view = $this->getView();
$view->registerJs("jQuery('#{$this->id}').SortableListView('{$url}', {$options});");
$view->registerJs("jQuery('#{$this->id}').on('sortableSuccess', function() {jQuery.pjax.reload(" . json_encode($this->clientOptions) . ")})", \yii\web\View::POS_END);
ListViewSortableAsset::register($view);
}
}
示例14: format
/**
* Formats response data in JSON format.
* @link http://jsonapi.org/format/upcoming/#document-structure
* @param Response $response
*/
public function format($response)
{
$response->getHeaders()->set('Content-Type', 'application/vnd.api+json; charset=UTF-8');
if ($response->data !== null) {
$options = $this->encodeOptions;
if ($this->prettyPrint) {
$options |= JSON_PRETTY_PRINT;
}
if ($response->isClientError || $response->isServerError) {
if (ArrayHelper::isAssociative($response->data)) {
$response->data = [$response->data];
}
$apiDocument = ['errors' => $response->data];
} elseif (ArrayHelper::keyExists('data', $response->data)) {
$apiDocument = $response->data;
} else {
$apiDocument = ['meta' => $response->data];
}
$response->content = Json::encode($apiDocument, $options);
}
}
示例15: indexDataProvider
public function indexDataProvider()
{
$params = \Yii::$app->request->queryParams;
$model = new $this->modelClass();
$modelAttr = $model->attributes;
$order = isset($params['order']) ? ArrayHelper::keyExists($params['order'], $this->orderParams, false) ? $params['order'] : 'id' : 'id';
$sort = isset($params['sort']) && ($params['sort'] = 'asc') ? 'ASC' : 'DESC';
$search = [];
if (!empty($params)) {
foreach ($params as $key => $value) {
if (!is_scalar($key) or !is_scalar($value)) {
throw new BadRequestHttpException('Bad Request');
}
if (!in_array(strtolower($key), $this->reservedParams) && ArrayHelper::keyExists($key, $modelAttr, false)) {
$search[$key] = $value;
}
}
}
//return $model->find()->where($search)->orderBy([$order => $sort])->limit(10)->all();
return $model->find()->where($search)->orderBy($order . ' ' . $sort)->limit(20)->all();
}