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


PHP ArrayHelper::isIndexed方法代码示例

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


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

示例1: validateAttribute

 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     if (!is_array($model->{$attribute}) || !ArrayHelper::isIndexed($model->{$attribute}, true)) {
         $model->addError($attribute, 'invalid data.');
         return;
     }
     $config = [];
     if (is_string($this->embedded)) {
         $config['class'] = $this->embedded;
     } else {
         $config = $this->embedded;
     }
     $items = [];
     foreach ($model->{$attribute} as $i => $data) {
         /* @var $embedded \yii\base\Model */
         $embedded = Yii::createObject($config);
         $embedded->scenario = $model->scenario;
         $embedded->setAttributes($data);
         if (!$embedded->validate()) {
             $items[] = $data;
             foreach ($embedded->getErrors() as $key => $errors) {
                 $errorKey = "{$attribute}.{$i}.{$key}";
                 foreach ($errors as $error) {
                     $model->addError($errorKey, $error);
                 }
             }
             return;
         } else {
             $items[] = $embedded->toArray();
         }
         $embedded = null;
     }
     $model->{$attribute} = $items;
 }
开发者ID:mole-chen,项目名称:yii2,代码行数:37,代码来源:EmbedManyValidator.php

示例2: getRequestArray

 /**
  * Parses POST data into array of JSON-PRC batch requests
  * @return array
  * @throws \yii\web\BadRequestHttpException
  */
 protected function getRequestArray()
 {
     $requestArray = Yii::$app->request->getBodyParams();
     if (!is_array($requestArray)) {
         throw new \yii\web\BadRequestHttpException('Invalid JSON-RPC request.');
     }
     if (!ArrayHelper::isIndexed($requestArray)) {
         $requestArray = array($requestArray);
     }
     return $requestArray;
 }
开发者ID:eugene-khorev,项目名称:yii2-json-rpc-controller,代码行数:16,代码来源:Action.php

示例3: modsClass

 public static function modsClass($bem, $mods)
 {
     $classes = [];
     $mods = ArrayHelper::getValue($mods, '__monster__mods__', []);
     $isIndexed = ArrayHelper::isIndexed($mods);
     foreach ($mods as $key => $value) {
         if ($value === true) {
             $classes[] = "{$bem}_{$key}";
         } elseif ($isIndexed) {
             $classes[] = "{$bem}_{$value}";
         } else {
             $classes[] = "{$bem}_{$key}_{$value}";
         }
     }
     return implode(' ', $classes);
 }
开发者ID:DevGroup-ru,项目名称:dotplant-monster,代码行数:16,代码来源:ViewHelpers.php

示例4: init

 /**
  * Initialize the queue.
  * @return void
  */
 public function init()
 {
     parent::init();
     $this->queue = \yii\di\Instance::ensure($this->queue, Queue::className());
     $this->_hasEventHandlers = !\yii\helpers\ArrayHelper::isIndexed($this->events, true);
     if ($this->_hasEventHandlers) {
         foreach ($this->events as $attr => $handler) {
             if (is_callable($handler)) {
                 if (!isset($this->_serializer)) {
                     $this->_serializer = new \SuperClosure\Serializer();
                 }
                 $this->events[$attr] = $this->_serializer->serialize($handler);
             }
         }
     }
 }
开发者ID:voodoo-mobile,项目名称:yii2-queue,代码行数:20,代码来源:DeferredEventBehavior.php

示例5: normalizeListItem

 public static function normalizeListItem($items = [])
 {
     if (ArrayHelper::isIndexed($items, true)) {
         return $items;
     }
     $data = [];
     foreach ($items as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $_k => $_v) {
                 $data[] = ['value' => $_k, 'text' => $_v, 'group' => $key];
             }
         } else {
             $data[] = ['value' => $key, 'text' => $value];
         }
     }
     return $data;
 }
开发者ID:dextercool,项目名称:yii2-easyui,代码行数:17,代码来源:Easyui.php

示例6: registerClientPlugins

 public function registerClientPlugins($clientPlugins, $excludedPlugins)
 {
     if (is_array($clientPlugins)) {
         if (ArrayHelper::isIndexed($clientPlugins, true)) {
             // sequential array = list of plugins to be included
             // use default configurations for every plugin
             $this->registerPlugins($clientPlugins);
         } else {
             // associative array = custom plugins and options included
             foreach ($clientPlugins as $key => $value) {
                 if (is_numeric($key)) {
                     $pluginName = $value;
                     if (!$this->isPluginExcluded($pluginName, $excludedPlugins)) {
                         $this->registerPlugin($pluginName);
                     }
                 } else {
                     $pluginName = $key;
                     if (!$this->isPluginExcluded($pluginName, $excludedPlugins)) {
                         $pluginOptions = $value;
                         $issetJs = isset($pluginOptions['js']);
                         $issetCss = isset($pluginOptions['css']);
                         if ($issetJs) {
                             $this->addJs($pluginOptions['js']);
                         } else {
                             if ($this->isPluginJsFileExist($pluginName)) {
                                 $this->addJs($this->getDefaultJsUrl($pluginName));
                             } else {
                                 throw new Exception("you must set 'js' [and 'css'] for plugin '{$pluginName}'");
                             }
                         }
                         if ($issetCss) {
                             $this->addCss($pluginOptions['css']);
                         } else {
                             if ($this->isPluginCssFileExist($pluginName)) {
                                 $this->addCss($this->getDefaultCssUrl($pluginName));
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $this->registerPlugins(array_diff($this->froalaPlugins, $excludedPlugins ?: []), false, true);
     }
 }
开发者ID:dungphanxuan,项目名称:yii2-froalaeditor,代码行数:45,代码来源:FroalaEditorAsset.php

示例7: normalizeVariationConfig

 /**
  * @param array $variationConfig
  * @return array
  */
 public static function normalizeVariationConfig($variationConfig)
 {
     $config = array();
     $arrayIndexed = ArrayHelper::isIndexed($variationConfig);
     $argumentCount = count($variationConfig);
     $defaultResizeMode = self::default_resize_mod();
     if ($arrayIndexed) {
         $config['width'] = $variationConfig[0];
         $config['height'] = $variationConfig[1];
         if ($argumentCount > 2) {
             $config['mode'] = in_array($variationConfig[2], array('inset', 'outbound')) ? $variationConfig[2] : $defaultResizeMode;
         }
         if ($argumentCount > 3) {
             $config['quality'] = is_numeric($variationConfig[3]) ? $variationConfig[3] : self::default_quality();
         }
     } else {
         $config['width'] = $variationConfig['width'];
         $config['height'] = $variationConfig['height'];
         $config['mode'] = in_array($variationConfig['mode'], array('inset', 'outbound')) ? $variationConfig['mode'] : $defaultResizeMode;
         if (isset($variationConfig['quality'])) {
             $config['quality'] = is_numeric($variationConfig['quality']) ? $variationConfig['quality'] : self::default_quality();
         }
         if (isset($variationConfig['watermark'])) {
             $default_watermark_config = array('position' => WatermarkFilter::WM_POSITION_BOTTOM_RIGHT, 'margin' => 5);
             if (is_array($variationConfig['watermark'])) {
                 if (isset($variationConfig['watermark']['path'])) {
                     $config['watermark'] = ArrayHelper::merge($default_watermark_config, $variationConfig['watermark']);
                 }
             } else {
                 $config['watermark'] = ArrayHelper::merge($default_watermark_config, ['path' => $variationConfig['watermark']]);
             }
         }
         // fill color for resize mode fill in (inset variation)
         // crop
         // rotate
         // etc
     }
     if (!isset($config['mode'])) {
         $config['mode'] = $defaultResizeMode;
     }
     if (!isset($config['quality'])) {
         $config['quality'] = self::default_quality();
     }
     return $config;
 }
开发者ID:arhiopterecs,项目名称:yii2-file-processor,代码行数:49,代码来源:VariationHelper.php

示例8: actionRouteToUrl

 public function actionRouteToUrl()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     $route = \Yii::$app->request->get('route');
     if ($route === null) {
         throw new NotAcceptableHttpException();
     }
     if (is_string($route)) {
         switch ($route) {
             case 'home':
                 return ['success' => true, 'url' => Url::home()];
             default:
                 throw new NotSupportedException();
         }
     } else {
         if (ArrayHelper::isIndexed($route)) {
             $url = Url::to($route);
         } else {
             $url = Url::to(array_merge([ArrayHelper::getValue($route, 'route', '')], ArrayHelper::getValue($route, 'params', [])));
         }
         return ['success' => true, 'url' => $url];
     }
 }
开发者ID:omnilight,项目名称:yz2-admin,代码行数:23,代码来源:GeneralController.php

示例9: offsetExists

 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Whether a offset exists
  * @link http://php.net/manual/en/arrayaccess.offsetexists.php
  *
  * @param mixed $offset <p>
  *                      An offset to check for.
  *                      </p>
  *
  * @return boolean true on success or false on failure.
  * </p>
  * <p>
  * The return value will be casted to boolean if non-boolean was returned.
  */
 public function offsetExists($offset)
 {
     return ArrayHelper::isIndexed($this->data) && count($this->data) > $offset;
 }
开发者ID:voodoo-mobile,项目名称:yii2-core,代码行数:18,代码来源:ArrayObject.php

示例10: buildBatchKeyArgument

 /**
  * Resolve the keys into `BatchGetItem` eligible argument.
  * @param string $table The name of the table.
  * @param array  $keys  The keys.
  * @return array
  */
 private function buildBatchKeyArgument($table, $keys)
 {
     $tableDescription = $this->db->createCommand()->describeTable($table)->execute();
     $keySchema = $tableDescription['Table']['KeySchema'];
     if (ArrayHelper::isIndexed($keys)) {
         $isScalar = is_string($keys[0]) || is_numeric($keys[0]);
         if ($isScalar) {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfScalar($keySchema, $keys);
         } elseif (ArrayHelper::isIndexed($keys[0])) {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfIndexedArray($keySchema, $keys);
         } else {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfAssociativeArray($keySchema, $keys);
         }
     } else {
         return $this->buildBatchGetItemFromAssociativeArray($keySchema, $keys);
     }
 }
开发者ID:setyolegowo,项目名称:yii2-dynamodb,代码行数:23,代码来源:QueryBuilder.php

示例11: init

 /**
  * Initialize the queue.
  * @throws \Exception
  */
 public function init()
 {
     parent::init();
     $queueName = $this->queue;
     $this->queue = Yii::$app->get($queueName);
     if (!$this->queue instanceof \UrbanIndo\Yii2\Queue\Queue) {
         throw new \Exception("Can not found queue component named '{$queueName}'");
     }
     $this->_hasEventHandlers = !\yii\helpers\ArrayHelper::isIndexed($this->events, true);
     if ($this->_hasEventHandlers) {
         foreach ($this->events as $attr => $handler) {
             if (is_callable($handler)) {
                 if (!isset($this->_serializer)) {
                     $this->_serializer = new \SuperClosure\Serializer();
                 }
                 $this->events[$attr] = $this->_serializer->serialize($handler);
             }
         }
     }
 }
开发者ID:tajhulfaijin,项目名称:yii2-queue,代码行数:24,代码来源:DeferredEventBehavior.php

示例12: init

 /**
  * @throws InvalidConfigException
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!empty($this->dbList)) {
         if (!ArrayHelper::isIndexed($this->dbList)) {
             throw new InvalidConfigException('Property dbList must be as indexed array');
         }
         foreach ($this->dbList as $dbAlias) {
             /**
              * @var Connection $db
              */
             $db = Instance::ensure($dbAlias, Connection::className());
             $this->dbInfo[$dbAlias]['driverName'] = $db->driverName;
             $this->dbInfo[$dbAlias]['dsn'] = $db->dsn;
             $this->dbInfo[$dbAlias]['host'] = $this->getDsnAttribute('host', $db->dsn);
             $this->dbInfo[$dbAlias]['port'] = $this->getDsnAttribute('port', $db->dsn);
             $this->dbInfo[$dbAlias]['dbName'] = $this->getDsnAttribute('dbname', $db->dsn);
             $this->dbInfo[$dbAlias]['username'] = $db->username;
             $this->dbInfo[$dbAlias]['password'] = $db->password;
             $this->dbInfo[$dbAlias]['prefix'] = $db->tablePrefix;
         }
     }
     $this->path = Yii::getAlias($this->path);
     if (!StringHelper::endsWith($this->path, '/', false)) {
         $this->path .= '/';
     }
     if (!is_dir($this->path)) {
         throw new InvalidConfigException('Path is not directory');
     }
     if (!is_writable($this->path)) {
         throw new InvalidConfigException('Path is not writable! Check chmod!');
     }
     $this->fileList = FileHelper::findFiles($this->path, ['only' => ['*.sql', '*.gz']]);
 }
开发者ID:beaten-sect0r,项目名称:yii2-db-manager,代码行数:38,代码来源:Module.php

示例13: isCorrectFormat

 /**
  * Deterime an array is on correct format or not that mentiond on `$marks`
  * definition section.
  * 
  * @param array $marks Array of points for check to be on correct format.
  * @return boolean Whether the array is on correct format
  */
 private function isCorrectFormat($marks)
 {
     if (!is_array($marks) || empty($marks)) {
         return false;
     } elseif (ArrayHelper::isIndexed($marks, true)) {
         if (count($marks) == 2 && isset($marks[0]) && isset($marks[1]) && is_numeric($marks[0]) && is_numeric($marks[1])) {
             return true;
         } else {
             foreach ($marks as $mark) {
                 if (!$this->isCorrectFormat($mark)) {
                     return false;
                 }
             }
             return true;
         }
     } elseif (count($marks) == 2 && isset($marks['latitude']) && isset($marks['longitude']) && is_numeric($marks['latitude']) && is_numeric($marks['longitude'])) {
         return true;
     }
     return false;
 }
开发者ID:meysampg,项目名称:yii2-gmapmarker,代码行数:27,代码来源:GMapMarker.php

示例14: updateItemSelectedAction

 /**
  * Builds a DynamoDB command for batch delete item.
  *
  * @param string $table   The name of the table to be created.
  * @param array  $keys    The keys of the row to get.
  * This can be
  * 1) indexed array of scalar value for table with single key,
  *
  * e.g. ['value1', 'value2', 'value3', 'value4']
  *
  * 2) indexed array of array of scalar value for table with multiple key,
  *
  * e.g. [
  *  ['value11', 'value12'],
  *  ['value21', 'value22'],
  *  ['value31', 'value32'],
  *  ['value41', 'value42'],
  * ]
  *
  * The first scalar will be the primary (or hash) key, the second will be the
  * secondary (or range) key.
  *
  * 3) indexed array of associative array
  *
  * e.g. [
  *  ['attribute1' => 'value11', 'attribute2' => 'value12'],
  *  ['attribute1' => 'value21', 'attribute2' => 'value22'],
  *  ['attribute1' => 'value31', 'attribute2' => 'value32'],
  *  ['attribute1' => 'value41', 'attribute2' => 'value42'],
  * ]
  *
  * 4) or associative of scalar values.
  *
  * e.g. [
  *  'attribute1' => ['value11', 'value21', 'value31', 'value41']
  *  'attribute2' => ['value12', 'value22', 'value32', 'value42']
  * ].
  *
  * @param array  $updates Update hash key-value of the model.
  * @param string $action  Action of the method, either 'PUT'|'ADD'|'DELETE'.
  * @param array  $options Additional options for the final argument.
  * @return array
  */
 public function updateItemSelectedAction($table, array $keys, array $updates, $action, array $options = [])
 {
     $name = 'UpdateItem';
     $argument['TableName'] = $table;
     if (ArrayHelper::isIndexed($keys)) {
         $argument['Key'] = $this->buildBatchKeyArgument($table, $keys);
     } else {
         $argument['Key'] = $this->paramToExpressionAttributeValues($keys);
     }
     $value_map = $this->paramToExpressionAttributeValues($updates);
     foreach ($value_map as $key => $value) {
         $argument['AttributeUpdates'][$key] = ['Value' => $value, 'Action' => $action];
     }
     $argument = array_merge($argument, $options);
     return [$name, $argument];
 }
开发者ID:urbanindo,项目名称:yii2-dynamodb,代码行数:59,代码来源:QueryBuilder.php

示例15: batchInsertStat

 /**
  * 批量插入
  *
  * @param array $stat 字段值必须跟数据库中的字段顺序完全一样
  * ~~
  * [field1val,field2val,field3val...]
  * ~~
  * @return int|false
  * @throws \yii\db\Exception
  */
 public function batchInsertStat($stat)
 {
     // 若不是索引数组返回false
     if (arr_null($stat) || !ArrayHelper::isIndexed($stat)) {
         return false;
     }
     try {
         $db = self::getDb();
         // 事物控制
         $transaction = $db->beginTransaction();
         // 已数组的形式返回表的字段(字段的默认顺序)
         $columns = $this->getColumns();
         $result = self::find()->createCommand($db)->batchInsert(self::tableName(), $columns, $stat)->execute();
     } catch (Exception $ex) {
         $transaction->rollBack();
         return false;
     }
     if ($result) {
         $transaction->commit();
         return $result;
     } else {
         $transaction->rollBack();
         return false;
     }
 }
开发者ID:songhongyu,项目名称:datecenter,代码行数:35,代码来源:BaseEmailStat.php


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