Download the PHP package kuzdo/mongoyii-php7 without Composer

On this page you can find all versions of the php package kuzdo/mongoyii-php7. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mongoyii-php7

MongoYii-php7

A PHP7 edition of mongoyii designed for and working with the new MongoDB driver

About this Documentation

This is not a complete rewrite of the old documentation, instead it will only detail the new features/ideas behind the PHP7 extension.

Please read the old documentation first if you are new to mongoyii.

Test Application

There is a new test application for this extension which is a rewrite of the old test appliction.

You can find it over here.

Running the inbuilt tests are the same as before.

Issues/Bugs & Questions

Please use the new Github issue tracker for all your questions and bug reports. If you post in the forums please link it in the Github issue tracker.

You can access the Github issue tracker here.

Versioning

This extension, like the previous, uses semantic versioning 2.0.0.

Licence

The licence for this extension remains the same as well, BSD 3 clause. To make it short and to the point: do whatever you want with it.

Note About Changes

Before I go into what has changed in this extension it is good to note that many of the changes are not because of my wanting to make them but because the MongoDB driver and PHPLib they have released has changed the workings so dramatically from the old drivers that I was forced to conform to this new standard of working.

There are some parts of the driver and it's PHPLib you will like and others you definitely wont.

Installling

All installling is now done through composer. I would NOT recommend installing manually since this extension requires both the driver and the PHPLib MongoDB has released to go with it (which is only on composer as well).

To install simply do (for dev-master):

composer require sammaye/mongoyii-php7:*

You can find the packagist repository here.

Namespacing

This extension is fully namespaced as:

sammaye\mongoyii

Do not worry! This does not make for too many changes for old applications. It took me about 3 hours to rewrite my test application.

For example, here is how to declare a new model (taken from my test application):

And that will give you all the same stuff as before.

Now let me show you an example of configuring the session and cache component in your main.php (again, taken from my test application):

So you see use of the namespaces is very easy to get to grips with.

As a final example, let's take a behaviour:

So, you see: using namespaces in this extension is very easy. If ever in doubt which namespace to use look up the file in your project and look at the first line where it says something like:

Add the class name to that and you have your namespace class.

Declaring the Extension

This is easily the part that has changed the most. To start off, why don't I show an example I use:

Now, let's break this down:

And that is basically it. The write concern, read concern, and other properties are now done per database as you see instead of on client level.

If you have other databases in your configuration and want to set a specific one as default you can add the active option as shown:

The Client __get Only Gets a Database?

Yes, this is the biggest change between the old driver and the new one.

There is now a clear separation between the client, database, and collection.

So to get the database, ready for fetching a collection you now need to do:

Authentication

In the new PHP driver there is no auth() function. You must athenticate within the uri of the mongodb component. You will decide how best to sort out your authentication database but I decided to put all users into the admin database. This makes it incredibly easy to authenticate to one database and then switch as I need.

Using Multiple Databases

As you can see, this extension takes multiple databases into account.

If you are using authentication make sure you either layout your users in a way that means you only need one socket connection (like I have above) or make a new component for each time you need to authenticate. You cannot authenticate AFTER connecting anymore.

As for recoding the Document's getDbConnection() you now use getCollection() like so (due to the separation I mentioned above):

And you are done...

If you really know what you are doing you can actually set a database as active making it default for a set of procedures:

But this is for advanced users only!

Querying

This is the biggest change away from Yii1. Everything else remains the same and does not require documenting.

Basically, due to how the new driver no longer uses cursors but instead streams I have recoded the EMongoDBCriteria object to be Query (like in Yii2) and it even works similar to how it does in Yii2.

However, it is good to note that the Document functions of find() and findOne() return the same as they do in normal Yii1. The return there has not changed.

It is good to note that the way to query has changed though, in accordance with the driver:

This is due to how MongoDB uses eager loaded streams. As such the entire query must be defined BEFORE forming the PHP "cursor" object now.

A good place to understand how to query using the new driver is to look at the Github documentation for the MongoDB PHPLib.

Scopes

Due to the change in the EMongoCriteria you may need to rewrite model scopes for them to work. A good example would be:

There is not a lot of changes you will see publicly, the biggest one is that I do not use the project word anymore for SELECT in SQL. MongoDB still does but I don't.

Why No EMongoCriteria?

This was a decision put forward by the need to produce clean and workable querying.

I decided, in the end, to make my querying more like Yii2. This actually means you can do this now:

So, it is a break from Yii1 to Yii2 but it is a good break.

Query Logging

Query logging is now much more extensive. Instead of just logging queries through the models it will now log all queries thanks to a small rewrite which should have been in the original extension.

Now, whenever you get the collection from the MongoDB component in your configuration it will return my own custom Collection class which has logging tied into it.

Hopefully, this should take some of the guess work out of building applications.

Notes About Quirks

Subdocuments

The MongoDB driver's PHPLib returns subdocuments as ArrayObjects. This means you need to type cast them via (array)$subdoc first before you use them in display and forms etc.

BSON Serialisation

Make sure you do not use ObjectID as your yii session ID. This is because of this issue whereby you cannot serialise BSON objects yet.

As an exmaple, here is a potential UserIdentity authenticate() method you can use (taken from my example application too):

Notice the line: $this->_id = (String)$record->_id; it is extremely important or else nothing will work!

DBRef is Deprecated

Yep, it is. If you are using it you will need to get rid of it before using this extension. There is simply no functionality for handling it in the new driver.

Stuff Not Done

GridFS

Not my fault. It is actually not there yet in the PHPLib!

And We Are... Done!

That should be it. Everything else is pretty much the same, cool, huh?

Please, do let me know if I have left anything out or need to explain something better.


All versions of mongoyii-php7 with dependencies

PHP Build Version
Package Version
Requires ext-mongodb Version *
mongodb/mongodb Version ^1.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kuzdo/mongoyii-php7 contains the following files

Loading the files please wait ....