Download the PHP package district5/mondoc without Composer

On this page you can find all versions of the php package district5/mondoc. 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 mondoc

District5 - Mondoc

CI

Composer...

Use composer to add this library as a dependency onto your project.

Usage...

Setting up connections...

The MondoConnections object is a singleton. Set this up somewhere in your code to initialise the connection, and within your services you can define protected static function getConnectionId(): string to return the correct identifier for the relevant model.

The data model

Additionally, in the model you can leverage the $mondocFieldAliases property to map fields from the database to the model to keep keys short in storage. This is optional, but can be useful in some cases. An example of this is shown below:

Optional traits...

Traits examples

The service layer

The logic for querying the database is always performed in the service layer. There's only a single required method, getCollectionName, which should return the name of the collection in the database.

Optionally, you can define a getConnectionId method to return the connection ID to use from the MondocConfig connection manager. This is useful if you're using multiple connections, for example, a connection for authentication and a connection for the main application.

All Mondoc native queries automatically convert DateTime objects to UTCDateTime objects when querying a collection.

Please note: in versions prior to 6.3.0 the PaginationTrait required you to pass the filter into each method call. This is no longer required, as the filter is carried through by the MondocPaginationHelper object now.

Nesting objects

You can nest objects in each other. The main model must extend \District5\Mondoc\Db\Model\MondocAbstractModel and have the sub models defined in the $mondocNested array.

Sub models must extend \District5\Mondoc\Db\Model\MondocAbstractSubModel.

When implementing $mondocNested, you declare a single nested model, or an array of nested models. For example:

Please note: in versions prior to 5.1.0 any nested property was required to have BSONDocument or BSONArray as part of the property definition. This is no longer required as the library will automatically inflate the class(es) correctly

Nested objects, regardless of depths, can also take advantage of the $mondocFieldAliases property to map fields from the database to the model. This keeps the keys short in storage, while allowing for longer, more descriptive keys in the model. For the above example, you could have the following:

Finding documents..

Model to array...

You can export a model to an array by calling asArray() on the model. This will return an array of the model's properties.

The properties returned by the asArray() method are the properties and types that have been set on the model, which means they're likely not able to be directly encoded to JSON. To get around this, you can call asJsonEncodableArray() on the model, which will return an array that can be encoded to JSON. Optionally, you can provide a list of fields to omit from the returned array.

Useful information...

To use a pre-determined ObjectId as the document _id, you can call setPresetObjectId against the model. This will force the model to absorb this ObjectId and not generate a new one upon insertion. For example:

Additionally, there's a method called assignDefaultVars which can be used to assign default values to the model's properties. This is useful for setting default values for properties. The call to assignDefaultVars occurs AFTER inflation has occurred, so it's important to note that the properties may already have values assigned. For example:

Converting between types

MongoDB uses BSON types for data. This library holds a MondocTypes helper, which can assist in the conversion of these native types.

Retention of data

When using the MondocRetentionTrait trait, you can set the retention data for a model by calling setMondocRetentionChangeMeta. There is no preset retention data, so you must set this yourself. This is useful for setting things such as the user's name who initiated the change, or similar for compliance and the retention policy. Additionally, the method setMondocRetentionExpiry method is exposed, and can be used to set the expiry date for the retention data. The library does not automatically delete the data when the retention period has expired, but you can use the MondocRetentionService to query for data that has expired, using either getPaginatorForExpiredRetentionForClassName or getPaginatorForExpiredRetentionForObject, and then subsequently the getRetentionPage method.

Exposed methods in the MondocRetentionService:

Within a MondoRetentionModel, the following methods are available:

A working example of using the retention trait is shown below:

Query building

Query building is handled by the MondocBuilder library https://github.com/district-5/php-mondoc-builder.

The query builder does not take into account for the model's properties, but rather the database's properties. This means that it will not listen or adhere to any field mappings that have been set on the model.

For example, this map would require the query builder to use the n key, not name:

Testing

You can run PHPUnit against the library by running composer install and then running phpunit. Before doing so, you'll need to assign the MONGO_CONNECTION_STRING environment variable to a valid MongoDB connection string.


All versions of mondoc with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
ext-mongodb Version *
mongodb/mongodb Version *
district5/date Version *
district5/mondoc-builder Version *
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 district5/mondoc contains the following files

Loading the files please wait ....