Download the PHP package dotkernel/dot-mapper without Composer

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

dot-mapper

[!IMPORTANT] dot-mapper is a wrapper on top of laminas/laminas-db

Dynamic JSON Badge

[!CAUTION]

Security-Only Maintenance Mode

This package is considered feature-complete, and is now in security-only maintenance mode.

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

DotKernel backend abstraction that implements the Data Mapper pattern. It does not offer a full ORM solution but rather a middle-ground solution for entity to database transfer with the possibility to be used with relationships too.

Installation

Run the following command in your project root directory

Entities

Entities are part of the domain model. They model real life objects or concepts. Usually in a web application they model the database objects and their relationships. In DotKernel we like to keep entities simple and as close to the database structure as possible. Usually they will model a table's row and can be composed into more complex objects via object composition To use our mapper package to save entities to the database, you have to implement the EntityInterface interface or better, extend the Entity class. Among some utility methods defined for object property handling, the Entity class defines internally the laminas hydrator that is to be used when fetching or saving data to the backend. The mappers do this automatically when using the CRUD operations.

To set the prefered hydrator, you can extend the Entity class and override the protected $hydrator property with the class name of the desired hydrator. The hydrator has to be registered in the hydrator manager beforehand.

We give below an entity example

entity example

Mappers

DotKernel mappers must implement the MapperInterface which defines the basic CRUD operations along with some specific database functions like transaction management, generated value and so on.

We already provide an abstract mapper implementation for SQL databases. The abstract mapper is based on functions offered by laminas-db. We'll implement other types of backend support in the future.

If you use an SQL database, in order to create a mapper, you should extend the AbstractDbMapper class. You don't have to write any database related code if all you need is CRUD operations. We'll detail later in this lesson how to create more complex mappers.

The following mapper example is all you need if you want to select, insert, update or delete an entity.

example 1

Basic mapper functions

Selecting list of items

Find options(for SQL databases)

Join options

Counting items

Selecting one item/entity

Saving an entity

Deleting an entity

Bulk delete

Bulk update

Creating new empty entities

Other useful functions

Other methods will be described in the advanced mapper usage section. Their availability might be conditioned by the underlying backend engine used.

The Mapper Manager

All defined mappers have to be registered and fetched from the mapper manager. The mapper manager is a special case of service container. It is an instance of the AbstractPluginManager type provided by Laminas Service Manager. The mapper manager is responsible for proper mapper initialization. Another feature is mapper caching - multiple calls to a mapper will result in just one initialization. The mapper manager initializes the mapper following the configuration set including the backend adapters, associated entity, event listeners and so on.

You'll use the mapper manager's single public method: get($name, array $options = null);

To access the mapper manager you can inject it manually in your classes by fetching it from the container.

OR you can implement the MapperManagerAwareInterface along with the MapperManagerAwareTrait. This way you won't need to inject it yourself, and if this is the only dependency needed, you won't have to define a factory class because the mapper manager will be automatically injected by an initializer.

The mapper configuration structure is as follows

Even though it is a regular laminas service plugin manager, in the case of mappers the mapper registration needs to be defined more strictly. Let's see next how to set up a mapper.

Mapper setup

Mapper configuration options

The abstract db mapper support multiple options, the majority can be overriden through configuration. We'll list them below through a configuration example and the explanations

Using the mapper

At this point the mapper is ready to be used if configured correctly and the backend was set up as well. In your class that implements the bussiness logic and has the mapper manager defined you can fetch the mapper from the mapper manager as below

Listening to mapper events

A mapper event listener can be created by implementing the MapperEventListenerInterface. In order to make it easier, we provide an abstract listener and a trait to help you setup the listener.

The mapper event object is defined in the MapperEvent class.

Please note that the provided abstract mappers act also as event listeners to themselfs. This can be usefull for adding additional functionality directly to the mapper.

Mapper events

We list below the mapper event along with some tips on how you could use them and for what purpose. The grouped the events based on the mapper operation that triggers them and for each group we kept the order in which they are triggered.

Select(find) related events

These are triggered when calling the find method of the mapper or the get method

MapperEvent::EVENT_MAPPER_BEFORE_FIND

MapperEvent::EVENT_MAPPER_BEFORE_LOAD

MapperEvent::EVENT_MAPPER_AFTER_LOAD

MapperEvent::EVENT_MAPPER_AFTER_FIND

Save(insert/update) related events

The following events are triggered in the order listed below when calling the save method of a mapper. The save method can act as a create or update function depending on the entity saved(it has an id or not). You can check if it's a create or update operation by reading an event parameter that we'll see below.

MapperEvent::EVENT_MAPPER_BEFORE_SAVE

MapperEvent::EVENT_MAPPER_AFTER_SAVE

MapperEvent::EVENT_MAPPER_AFTER_SAVE_COMMIT

Delete related events

Triggered when an entity is to be deleted by calling the mapper's delete method. It works only with the single entity deletion not with the deleteAll.

MapperEvent::EVENT_MAPPER_BEFORE_DELETE

MapperEvent::EVENT_MAPPER_AFTER_DELETE

MapperEvent::EVENT_MAPPER_AFTER_DELETE_COMMIT

Advanced mapper usage

@ TODO: write more documentation


All versions of dot-mapper with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.0 || ~8.3.0
laminas/laminas-servicemanager Version ^3.22.1
laminas/laminas-paginator Version ^2.18.0
dotkernel/dot-hydrator Version ~2.9.2
dotkernel/dot-helpers Version ^3.4.2
dotkernel/dot-event Version ^3.4.2
laminas/laminas-db Version ^2.19.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 dotkernel/dot-mapper contains the following files

Loading the files please wait ....