Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implement GettextMessageSource #12

Closed
qiangxue opened this Issue Mar 25, 2013 · 0 comments

Comments

2 participants
Owner

qiangxue commented Mar 25, 2013

Similar to that in 1.1.

@ghost ghost assigned resurtm May 6, 2013

@qiangxue qiangxue closed this May 21, 2013

qiangxue pushed a commit that referenced this issue Jul 10, 2014

Merge pull request #12 from AbrahamGreyson/master
Guide-zh-CN/concept-autoloading.md proofread.

im-kulikov added a commit to im-kulikov/yii2 that referenced this issue Feb 2, 2015

Work around #6506: About yii2-mongodb find()->one
Dotdeb now has php5-mongo_1%3a1.6.0-1~dotdeb.2_amd64.deb for Debian 7

Stack trace:
```php
PHP Warning 'yii\base\ErrorException' with message 'Invalid argument supplied for foreach()'

in /project/vendor/composer/yiisoft/yii2/db/BaseActiveRecord.php:1047

Stack trace:
#0 /project/vendor/composer/yiisoft/yii2/db/BaseActiveRecord.php(1047): yii\base\ErrorHandler->handleError(2, 'Invalid argumen...', '/project...', 1047, Array)
#1 /project/vendor/composer/yiisoft/yii2/db/ActiveQueryTrait.php(132): yii\db\BaseActiveRecord::populateRecord(Object(app\models\Setting), NULL)
#2 /project/vendor/composer/yiisoft/yii2-mongodb/ActiveQuery.php(215): yii\mongodb\ActiveQuery->createModels(Array)
#3 /project/vendor/composer/yiisoft/yii2-mongodb/ActiveQuery.php(154): yii\mongodb\ActiveQuery->populate(Array)
#4 /project/app/components/Settings.php(31): yii\mongodb\ActiveQuery->one()
#5 /project/vendor/composer/yiisoft/yii2/base/Object.php(107): app\components\Settings->init()
#6 [internal function]: yii\base\Object->__construct(Array)
#7 /project/vendor/composer/yiisoft/yii2/di/Container.php(362): ReflectionClass->newInstanceArgs(Array)
#8 /project/vendor/composer/yiisoft/yii2/di/Container.php(147): yii\di\Container->build('app\\components\\...', Array, Array)
#9 /project/vendor/composer/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('app\\components\\...', Array, Array)
#10 /project/vendor/composer/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::createObject(Array)
#11 /project/vendor/composer/yiisoft/yii2/base/Application.php(302): yii\di\ServiceLocator->get('settings')
#12 /project/vendor/composer/yiisoft/yii2/web/Application.php(63): yii\base\Application->bootstrap()
#13 /project/vendor/composer/yiisoft/yii2/base/Application.php(267): yii\web\Application->bootstrap()
#14 /project/vendor/composer/yiisoft/yii2/base/Object.php(107): yii\base\Application->init()
#15 /project/vendor/composer/yiisoft/yii2/base/Application.php(206): yii\base\Object->__construct(Array)
#16 /project/web/index.php(40): yii\base\Application->__construct(Array)
#17 {main}
```

I found the following code in `mongo-php-driver` (maybe it will help):

`v1.5.8` - https://github.com/mongodb/mongo-php-driver/blob/1.5.8/cursor.c#L234:

```c
	if (!cursor->started_iterating) {
		MONGO_METHOD(MongoCursor, doQuery, return_value, getThis());
		cursor->started_iterating = 1;
	}
```

`v1.6.0` - https://github.com/mongodb/mongo-php-driver/blob/1.6.0/cursor.c#L240:

```c
	if (!cursor->started_iterating) {
		php_mongo_runquery(cursor TSRMLS_CC);
		if (EG(exception)) {
			RETURN_NULL();
		}
		cursor->started_iterating = 1;
	}
```
Now, in Yii (don't pretend to be correct, but in that case - it works ;) ):

https://github.com/yiisoft/yii2/blob/master/extensions/mongodb/Query.php#L147-L172
```php
    protected function fetchRowsInternal($cursor, $all, $indexBy)
    {
        $result = [];
        if ($all) {
            foreach ($cursor as $row) {
                if ($indexBy !== null) {
                    if (is_string($indexBy)) {
                        $key = $row[$indexBy];
                    } else {
                        $key = call_user_func($indexBy, $row);
                    }
                    $result[$key] = $row;
                } else {
                    $result[] = $row;
                }
            }
        } else {
            if ($cursor->hasNext()) {
                $result = $cursor->getNext();
            } else {
                $result = false;
            }
        }
        return $result;
    }
```

I replace with:

```php
    protected function fetchRowsInternal($cursor, $all, $indexBy)
    {
        $result = [];

        foreach ($cursor as $row) {
            // if we need all - no changes:
            if ($all) {
                if ($indexBy !== null) {
                    if (is_string($indexBy)) {
                        $key = $row[$indexBy];
                    } else {
                        $key = call_user_func($indexBy, $row);
                    }
                    $result[$key] = $row;
                } else {
                    $result[] = $row;
                }
            // otherwise get one and break:
            } else {
                $result = $row;

                break;
            }
        }

        return $result;
    }
```

wangjun083 pushed a commit to wangjun083/yii2 that referenced this issue Oct 24, 2015

Merge pull request #12 from shi-yang/master
Create tutorial-performance-tuning.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment