当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayHelper::isAssociative方法代码示例

本文整理汇总了PHP中yii\helpers\ArrayHelper::isAssociative方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::isAssociative方法的具体用法?PHP ArrayHelper::isAssociative怎么用?PHP ArrayHelper::isAssociative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\ArrayHelper的用法示例。


在下文中一共展示了ArrayHelper::isAssociative方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionEditable

 public function actionEditable()
 {
     if (Yii::$app->request->post('hasEditable') && Yii::$app->request->post('Order')) {
         $posted = Yii::$app->request->post('Order');
         if ($id = Yii::$app->request->post('editableKey')) {
         } else {
             if ($posted['order_id']) {
                 $id = $posted['order_id'];
             }
         }
         $model = $this->findModel($id);
         $this->setSubData();
         if (!ArrayHelper::isAssociative($posted, true)) {
             $post['Order'] = current($posted);
         } else {
             $post['Order'] = $posted;
         }
         $post['Order'] = $this->checkPermission($post['Order']);
         if ($model->load($post) && $model->save()) {
             echo \yii\helpers\Json::encode(['output' => $value, 'message' => '']);
         } else {
             echo \yii\helpers\Json::encode(['output' => '', 'message' => '']);
         }
         return;
     }
 }
开发者ID:sap55,项目名称:yii2-order-management,代码行数:26,代码来源:OrderController.php

示例2: findAll

 public static function findAll($condition = null, $order = null)
 {
     $query = static::find();
     if ($condition == null) {
         if ($order !== null) {
             $query = $query->orderBy($order);
         }
         return $query->all();
     }
     if (ArrayHelper::isAssociative($condition)) {
         // hash condition
         $ret = $query->andWhere($condition);
         if ($order !== null) {
             $ret = $ret->orderBy($order);
         }
         return $ret->all();
     } else {
         // query by primary key(s)
         $primaryKey = static::primaryKey();
         if (isset($primaryKey[0])) {
             $ret = $query->andWhere([$primaryKey[0] => $condition]);
             if ($order !== null) {
                 $ret = $ret->orderBy($order);
             }
             return $ret->all();
         } else {
             throw new InvalidConfigException(get_called_class() . ' must have a primary key.');
         }
     }
 }
开发者ID:dw250100785,项目名称:lulucms,代码行数:30,代码来源:BaseActiveRecord.php

示例3: findQuery

 public static function findQuery($condition = null, $orderBy = null, $with = null, $params = [])
 {
     $query = static::find();
     if ($with !== null) {
         if (is_string($with)) {
             $query->innerJoinWith($with);
         } else {
             if (isset($with['type'])) {
                 $type = $with['type'];
             }
             if (isset($with[1])) {
                 $type = $with[1];
             } else {
                 $type = 'INNER JOIN';
             }
             $query->joinWith($with[0], true, $type);
         }
     }
     if ($condition !== null && !empty($condition)) {
         if (!ArrayHelper::isAssociative($condition)) {
             // query by primary key
             $primaryKey = static::primaryKey();
             if (isset($primaryKey[0])) {
                 $condition = [$primaryKey[0] => $condition];
             } else {
                 throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.');
             }
         }
         $query->andWhere($condition);
     }
     if ($orderBy != null) {
         $query->orderBy($orderBy);
     }
     return $query;
 }
开发者ID:merlinxie,项目名称:lulublog,代码行数:35,代码来源:BaseActiveRecord.php

示例4: findAll

 /**
  * @inheritdoc
  */
 public static function findAll($condition)
 {
     $query = static::find();
     if (ArrayHelper::isAssociative($condition)) {
         return $query->andWhere($condition)->all();
     } else {
         return static::mget((array) $condition);
     }
 }
开发者ID:MiladAlshomary,项目名称:yii2-parse,代码行数:12,代码来源:ActiveRecord.php

示例5: identifiedBy

 /**
  * @param $condition
  *
  * @return mixed
  * @throws InvalidConfigException
  */
 public function identifiedBy($condition)
 {
     /** @var ActiveQuery $this */
     if (!ArrayHelper::isAssociative($condition)) {
         $primaryKey = call_user_func([$this->modelClass, 'primaryKey']);
         if (isset($primaryKey[0])) {
             $condition = [$primaryKey[0] => $condition];
         } else {
             throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.');
         }
     }
     return $this->andWhere($condition);
 }
开发者ID:voodoo-mobile,项目名称:yii2-core,代码行数:19,代码来源:ActiveQueryTrait.php

示例6: parse

 /**
  * Parse a workflow defined as a PHP Array.
  *
  * The workflow definition passed as argument is turned into an array that can be
  * used by the WorkflowFileSource components. 
  * 
  * @param string $wId
  * @param array $definition
  * @param raoul2000\workflow\source\file\WorkflowFileSource $source
  * @return array The parse workflow array definition
  * @throws WorkflowValidationException
  */
 public function parse($wId, $definition, $source)
 {
     if (empty($wId)) {
         throw new WorkflowValidationException("Missing argument : workflow Id");
     }
     if (!\is_array($definition)) {
         throw new WorkflowValidationException("Workflow definition must be provided as an array");
     }
     if (!ArrayHelper::isAssociative($definition)) {
         throw new WorkflowValidationException("Workflow definition must be provided as associative array");
     }
     $initialStatusId = null;
     $normalized = [];
     $startStatusIdIndex = [];
     $endStatusIdIndex = [];
     foreach ($definition as $id => $targetStatusList) {
         list($workflowId, $statusId) = $source->parseStatusId($id, $wId);
         $absoluteStatusId = $workflowId . WorkflowFileSource::SEPARATOR_STATUS_NAME . $statusId;
         if ($workflowId != $wId) {
             throw new WorkflowValidationException('Status must belong to workflow : ' . $absoluteStatusId);
         }
         if (count($normalized) == 0) {
             $initialStatusId = $absoluteStatusId;
             $normalized['initialStatusId'] = $initialStatusId;
             $normalized[WorkflowFileSource::KEY_NODES] = [];
         }
         $startStatusIdIndex[] = $absoluteStatusId;
         $endStatusIds = [];
         if (\is_string($targetStatusList)) {
             $ids = array_map('trim', explode(',', $targetStatusList));
             $endStatusIds = $this->normalizeStatusIds($ids, $wId, $source);
         } elseif (\is_array($targetStatusList)) {
             if (ArrayHelper::isAssociative($targetStatusList, false)) {
                 throw new WorkflowValidationException("Associative array not supported (status : {$absoluteStatusId})");
             }
             $endStatusIds = $this->normalizeStatusIds($targetStatusList, $wId, $source);
         } elseif ($targetStatusList === null) {
             $endStatusIds = [];
         } else {
             throw new WorkflowValidationException('End status list must be an array for status  : ' . $absoluteStatusId);
         }
         if (count($endStatusIds)) {
             $normalized[WorkflowFileSource::KEY_NODES][$absoluteStatusId] = ['transition' => array_fill_keys($endStatusIds, [])];
             $endStatusIdIndex = \array_merge($endStatusIdIndex, $endStatusIds);
         } else {
             $normalized[WorkflowFileSource::KEY_NODES][$absoluteStatusId] = null;
         }
     }
     $this->validate($wId, $source, $initialStatusId, $startStatusIdIndex, $endStatusIdIndex);
     return $normalized;
 }
开发者ID:project-ufa,项目名称:yii2-workflow,代码行数:63,代码来源:MinimalArrayParser.php

示例7: findByCondition

 /**
  * Finds Entity instance(s) by the given condition.
  * This method is internally called by [[findOne()]] and [[findAll()]].
  * @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
  * @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
  * @throws InvalidConfigException if there is no primary key defined
  * @internal
  */
 protected function findByCondition($condition)
 {
     $query = $this->find();
     if (!ArrayHelper::isAssociative($condition)) {
         // query by primary key
         $primaryKey = $this->primaryKey();
         if (isset($primaryKey[0])) {
             $condition = [$primaryKey[0] => $condition];
         } else {
             throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.');
         }
     }
     return $query->andWhere($condition);
 }
开发者ID:paper-cube,项目名称:active-data-mapper,代码行数:22,代码来源:BaseRepository.php

示例8: checkAccess

 public static function checkAccess($acl, $reference = null)
 {
     // 1) All users
     if (is_null($acl) or $acl == '*') {
         return true;
     }
     // 2) Authenticated users
     if ($acl == '@') {
         return !Yii::$app->user->isGuest;
     }
     $user_id = Yii::$app->user->identity->getId();
     $username = Yii::$app->user->identity->username;
     if (is_array($acl) && ArrayHelper::isAssociative($acl)) {
         if (self::checkAccess('@')) {
             // 3) List of users
             if (array_key_exists('users', $acl) && is_array($acl['users'])) {
                 return in_array($username, $acl['users']);
             } else {
                 // 4) Current user id equals to specified attribute of model
                 $keys = array_keys($acl);
                 $className = array_shift($keys);
                 $attribute = array_shift($acl);
                 if (class_exists($className)) {
                     if (is_null($reference)) {
                         return false;
                     }
                     if ($reference instanceof $className) {
                         return $reference->getAttribute($attribute) == $user_id;
                     } else {
                         try {
                             $whereCondition = [$className::primaryKey()[0] => $reference, $attribute => $user_id];
                             return $className::find()->where($whereCondition)->count() > 0;
                         } catch (Exception $e) {
                             Yii::warning('Invalid configuration: ' . $e->getMessage(), 'file-processor');
                             return false;
                         }
                     }
                 } else {
                     // throw new Exception; // maybe
                     return false;
                 }
             }
         }
     }
     // 5) Defined function
     if (is_callable($acl)) {
         return call_user_func($acl, $reference, $user_id);
     }
     return false;
 }
开发者ID:arhiopterecs,项目名称:yii2-file-processor,代码行数:50,代码来源:AccessControl.php

示例9: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  * @throws \RuntimeException
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'text/csv; charset=UTF-8');
     $handle = fopen('php://temp/maxmemory:' . intval($this->maxMemory), 'w+');
     $response->stream = $handle;
     if ($this->includeColumnNames && $this->checkAllRows) {
         $columns = $this->getColumnNames($response->data);
         if (empty($columns)) {
             return;
         }
         $outputHeader = false;
         $this->put($handle, $columns);
     } else {
         $outputHeader = true;
     }
     if (!$response->data instanceof \Traversable && !is_array($response->data)) {
         throw new \InvalidArgumentException('Response data must be traversable.');
     }
     foreach ($response->data as $row) {
         if ($outputHeader && $this->includeColumnNames && !$this->checkAllRows && \yii\helpers\ArrayHelper::isAssociative($row)) {
             $this->put($handle, array_keys($row));
             $outputHeader = false;
         }
         if ($row instanceof Arrayable) {
             $row = $row->toArray();
         }
         $rowData = [];
         if (isset($columns)) {
             // Map columns.
             foreach ($columns as $column) {
                 if (array_key_exists($column, $row)) {
                     $rowData[] = isset($row[$column]) ? $row[$column] : $this->nullValue;
                 } else {
                     $rowData[] = $this->missingValue;
                 }
             }
         } else {
             foreach ($row as $column => $value) {
                 $rowData[] = isset($value) ? $value : $this->nullValue;
             }
         }
         $this->put($handle, $rowData);
     }
     rewind($handle);
 }
开发者ID:sam-it,项目名称:yii2-csv-formatter,代码行数:50,代码来源:CsvResponseFormatter.php

示例10: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     Yii::setAlias('@crud-buttons', dirname(__FILE__));
     if (!$this->i18n) {
         $this->i18n = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@crud-buttons/messages'];
     }
     Yii::$app->i18n->translations['crud-buttons'] = $this->i18n;
     parent::init();
     if (!$this->actionId) {
         $this->actionId = Yii::$app->controller->action->id;
     }
     $actions = ['index', 'create', 'update', 'delete', 'multi-update', 'multi-delete'];
     if (!$this->actions && $this->actions !== false) {
         $this->actions = array_combine($actions, $actions);
     } elseif ($this->actions && !ArrayHelper::isAssociative($this->actions)) {
         $this->actions = array_combine($this->actions, $this->actions);
     }
 }
开发者ID:dizews,项目名称:yii2-crud-buttons,代码行数:21,代码来源:CrudButtons.php

示例11: getQuery

 /**
  * Get ActiveQuery object
  *
  * @param array $params Condition array
  * @param integer $limit Limit
  * @param integer $page Page
  *
  * @return \yii\redis\ActiveQuery
  */
 public static function getQuery($params = [], $limit = 0, $page = 0)
 {
     $query = static::find();
     if ($params) {
         if (is_array($params)) {
             if (ArrayHelper::isAssociative($params)) {
                 $query = static::findByCondition($params);
             } else {
                 if (ArrayHelper::isAssociative($params, false)) {
                     foreach ($params as $key => $value) {
                         $data = [];
                         $type = 'and';
                         if (is_array($value)) {
                             if (isset($value[0]) && 2 === count($value)) {
                                 $value = [$value[0], $key, $value];
                             }
                             $data = $value;
                             $type = 'or' === $key ? 'or' : $type;
                         } else {
                             $data[$key] = $value;
                         }
                         switch ($type) {
                             case 'and':
                                 $query->andWhere($data);
                                 break;
                             case 'or':
                                 $query->orWhere($data);
                                 break;
                         }
                     }
                 } else {
                     $query = static::findByCondition($params);
                 }
             }
         } else {
             $query = static::findByCondition($params);
         }
     }
     if ((int) $limit) {
         $query->limit((int) $limit)->offset((int) $limit * (int) $page);
     }
     return $query;
 }
开发者ID:phantom-d,项目名称:yii2-file-daemon,代码行数:52,代码来源:ActiveRecord.php

示例12: __get

 /**
  * @param string $name
  *
  * @return mixed|ArrayObject
  */
 public function __get($name)
 {
     $value = ArrayHelper::getValue($this->data, $name, null);
     if (ArrayHelper::isAssociative($value)) {
         return new ArrayObject($value);
     } else {
         if (ArrayHelper::isIndexed($value)) {
             $objects = [];
             foreach ($value as $item) {
                 if (is_array($item)) {
                     $objects[] = new ArrayObject($item);
                 } else {
                     $objects[] = $item;
                 }
             }
             return $objects;
         }
     }
     return $value;
 }
开发者ID:voodoo-mobile,项目名称:yii2-core,代码行数:25,代码来源:ArrayObject.php

示例13: 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);
     }
 }
开发者ID:tuyakhov,项目名称:yii2-json-api,代码行数:26,代码来源:JsonApiResponseFormatter.php

示例14: run

 /**
  * Renders the language drop down if there are currently more than one languages in the app.
  * If you pass an associative array of language names along with their code to the URL manager
  * those language names will be displayed in the drop down instead of their codes.
  */
 public function run()
 {
     $languages = isset(Yii::$app->getUrlManager()->languages) ? Yii::$app->getUrlManager()->languages : [];
     if (count($languages) > 1) {
         $items = [];
         $currentUrl = preg_replace('/' . Yii::$app->language . '\\//', '', Yii::$app->getRequest()->getUrl(), 1);
         $isAssociative = ArrayHelper::isAssociative($languages);
         foreach ($languages as $language => $code) {
             $url = $code . $currentUrl;
             if ($isAssociative) {
                 $item = ['label' => $language, 'url' => $url];
             } else {
                 $item = ['label' => $code, 'url' => $url];
             }
             if ($code === Yii::$app->language) {
                 $item['options']['class'] = 'disabled';
             }
             $items[] = $item;
         }
         $this->dropdown['items'] = $items;
         parent::run();
     }
 }
开发者ID:loveorigami,项目名称:yii2-i18n-url,代码行数:28,代码来源:LanguageSwitcher.php

示例15: actionEditable

 public function actionEditable()
 {
     if (Yii::$app->request->post('hasEditable') && Yii::$app->request->post('AuthItem')) {
         $posted = Yii::$app->request->post('AuthItem');
         if ($id = Yii::$app->request->post('editableKey')) {
         } else {
             if ($posted['attribute_name']) {
                 $id = $posted['attribute_name'];
             }
         }
         $model = AuthItem::findOne($id);
         if (!ArrayHelper::isAssociative($posted, true)) {
             $post['AuthItem'] = current($posted);
         } else {
             $post['AuthItem'] = $posted;
         }
         if ($model->load($post) && $model->save()) {
             echo \yii\helpers\Json::encode(['output' => Yii::t('order', "Click for edit"), 'message' => '']);
         } else {
             echo \yii\helpers\Json::encode(['output' => Yii::t('order', "Error"), 'message' => '']);
         }
         return;
     }
 }
开发者ID:sap55,项目名称:yii2-order-management,代码行数:24,代码来源:SettingController.php


注:本文中的yii\helpers\ArrayHelper::isAssociative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。