sokil / php-mongo-yii

Yii 1 PHPMongo Adapter. Part of @PHPMongoKit
http://phpmongokit.github.io/
MIT License
0 stars 2 forks source link

yii2 support #1

Closed sokil closed 7 years ago

sagarguhe commented 7 years ago

:+1:

sagarguhe commented 7 years ago

Yii2 support should be there because there is no good mongo client library for yii2, yii2-mongo is not itself flexible and doesn't support the flexibility of noSQL databases for example: when you want to use multiple collections for same type of document which varies for each user.

sokil commented 7 years ago

implemention for yii2 currently in plans

sagarguhe commented 7 years ago

Great, when it is going to be published?

sokil commented 7 years ago

currently this task is not a priority, but pull requests always welcomes here https://github.com/sokil/php-mongo-yii or here https://github.com/PHPMongoKit/yii2-mongo-odm

sokil commented 7 years ago

by the way why you currently can't use https://github.com/sokil/php-mongo directly in yii2 app?

sagarguhe commented 7 years ago

@sokil I have managed to modify this lib to use on my Yii2, I can contribute to this repository but I am a kind of newbie in using github so I don't know how to make pull request or simple how to contribute to any git repository...

sokil commented 7 years ago

fork this repo, do changes, push to your fork, and create pull request here from https://github.com/sokil/php-mongo-yii/pulls

sokil commented 7 years ago

\CApplicationComponent optional and i don't use it, so i can simply remote it and adapter may be registered inside yii2 service locator, right?

sagarguhe commented 7 years ago

What I did is, I just changed the \CApplicationComponent to yii\base\Component, Yii::app() to Yii::$app and it did work...

sagarguhe commented 7 years ago

but now another problem is coming as I removed the pecl/mongo deprecated package and installed pecl/mongdb 1.2.2, it is giving error Class MongoClient not found... I will open a new issue on php-mongo repo..

sokil commented 7 years ago

no, this lib has no support of new mongo extenstion

sagarguhe commented 7 years ago

ok, I found this issue already there https://github.com/sokil/php-mongo/issues/115

sokil commented 7 years ago

https://github.com/PHPMongoKit/yii2-mongo-odm - check this, written on the fly... )

sagarguhe commented 7 years ago

Ok you removed the Yii2 logger part and made an independent class, great... I am thinking of setting errors key (as it is there in Yii2) if validation failed instead of throwing an exception...

sokil commented 7 years ago

https://github.com/sokil/php-mongo/blob/master/src/Document.php#L610-L628 - Document::validate() throws Exception

Use Document::isValid() && Document::getErrors() to get errors instead of exception

sagarguhe commented 7 years ago

Ok, I would need to check Document::isValid() before saving document with Document::save() to prevent it from throwing exception...

sokil commented 7 years ago

correct. there are two equal cases:

if ($document->isValid())
    $document->save();
} else {
    var_dump($document->getErrors());
}

or

try {
    $document->save();
} catch (\Sokil\Mongo\Document\InvalidDocumentException $e) {
    var_dump($document->getErrors());
}
sokil commented 7 years ago

https://github.com/PHPMongoKit/yii2-mongo-odm - Yii2 adapter for mongo client implemented