mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-27 04:10:30 +08:00
code style. FOREACH
This commit is contained in:
@@ -156,7 +156,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||
}
|
||||
$models = $this->createModels($result['hits']['hits']);
|
||||
if ($this->asArray && !$this->indexBy) {
|
||||
foreach($models as $key => $model) {
|
||||
foreach ($models as $key => $model) {
|
||||
if ($pk === '_id') {
|
||||
$model['_source']['_id'] = $model['_id'];
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||
$this->findWith($this->with, $models);
|
||||
}
|
||||
if (!$this->asArray) {
|
||||
foreach($models as $model) {
|
||||
foreach ($models as $model) {
|
||||
$model->afterFind();
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||
/** @var ActiveRecord $modelClass */
|
||||
$modelClass = $this->modelClass;
|
||||
$pk = $modelClass::primaryKey()[0];
|
||||
foreach($models as $key => $model) {
|
||||
foreach ($models as $key => $model) {
|
||||
if ($pk === '_id') {
|
||||
$model['_source']['_id'] = $model['_id'];
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||
$this->findWith($this->with, $models);
|
||||
}
|
||||
if (!$this->asArray) {
|
||||
foreach($models as $model) {
|
||||
foreach ($models as $model) {
|
||||
$model->afterFind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
$command = static::getDb()->createCommand();
|
||||
$result = $command->mget(static::index(), static::type(), $primaryKeys, $options);
|
||||
$models = [];
|
||||
foreach($result['docs'] as $doc) {
|
||||
foreach ($result['docs'] as $doc) {
|
||||
if ($doc['exists']) {
|
||||
$model = static::instantiate($doc);
|
||||
static::populateRecord($model, $doc);
|
||||
@@ -422,7 +422,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
return 0;
|
||||
}
|
||||
$bulk = '';
|
||||
foreach($primaryKeys as $pk) {
|
||||
foreach ($primaryKeys as $pk) {
|
||||
$action = Json::encode([
|
||||
"update" => [
|
||||
"_id" => $pk,
|
||||
@@ -441,7 +441,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
$response = static::getDb()->post($url, [], $bulk);
|
||||
$n=0;
|
||||
$errors = [];
|
||||
foreach($response['items'] as $item) {
|
||||
foreach ($response['items'] as $item) {
|
||||
if (isset($item['update']['error'])) {
|
||||
$errors[] = $item['update'];
|
||||
} elseif ($item['update']['ok']) {
|
||||
@@ -480,7 +480,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
return 0;
|
||||
}
|
||||
$bulk = '';
|
||||
foreach($primaryKeys as $pk) {
|
||||
foreach ($primaryKeys as $pk) {
|
||||
$action = Json::encode([
|
||||
"update" => [
|
||||
"_id" => $pk,
|
||||
@@ -489,7 +489,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
],
|
||||
]);
|
||||
$script = '';
|
||||
foreach($counters as $counter => $value) {
|
||||
foreach ($counters as $counter => $value) {
|
||||
$script .= "ctx._source.$counter += $counter;\n";
|
||||
}
|
||||
$data = Json::encode([
|
||||
@@ -504,7 +504,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
$response = static::getDb()->post($url, [], $bulk);
|
||||
$n=0;
|
||||
$errors = [];
|
||||
foreach($response['items'] as $item) {
|
||||
foreach ($response['items'] as $item) {
|
||||
if (isset($item['update']['error'])) {
|
||||
$errors[] = $item['update'];
|
||||
} elseif ($item['update']['ok']) {
|
||||
@@ -543,7 +543,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
return 0;
|
||||
}
|
||||
$bulk = '';
|
||||
foreach($primaryKeys as $pk) {
|
||||
foreach ($primaryKeys as $pk) {
|
||||
$bulk .= Json::encode([
|
||||
"delete" => [
|
||||
"_id" => $pk,
|
||||
@@ -558,7 +558,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
$response = static::getDb()->post($url, [], $bulk);
|
||||
$n=0;
|
||||
$errors = [];
|
||||
foreach($response['items'] as $item) {
|
||||
foreach ($response['items'] as $item) {
|
||||
if (isset($item['delete']['error'])) {
|
||||
$errors[] = $item['delete'];
|
||||
} elseif ($item['delete']['found'] && $item['delete']['ok']) {
|
||||
|
||||
@@ -63,7 +63,7 @@ class Connection extends Component
|
||||
|
||||
public function init()
|
||||
{
|
||||
foreach($this->nodes as $node) {
|
||||
foreach ($this->nodes as $node) {
|
||||
if (!isset($node['http_address'])) {
|
||||
throw new InvalidConfigException('Elasticsearch node needs at least a http_address configured.');
|
||||
}
|
||||
@@ -245,7 +245,7 @@ class Connection extends Component
|
||||
return mb_strlen($data, '8bit');
|
||||
},
|
||||
CURLOPT_HEADERFUNCTION => function($curl, $data) use (&$headers) {
|
||||
foreach(explode("\r\n", $data) as $row) {
|
||||
foreach (explode("\r\n", $data) as $row) {
|
||||
if (($pos = strpos($row, ':')) !== false) {
|
||||
$headers[strtolower(substr($row, 0, $pos))] = trim(substr($row, $pos + 1));
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class QueryBuilder extends \yii\base\Object
|
||||
private function buildHashCondition($condition)
|
||||
{
|
||||
$parts = [];
|
||||
foreach($condition as $attribute => $value) {
|
||||
foreach ($condition as $attribute => $value) {
|
||||
if ($attribute == '_id') {
|
||||
if ($value == null) { // there is no null pk
|
||||
$parts[] = ['script' => ['script' => '0==1']];
|
||||
|
||||
Reference in New Issue
Block a user