Download the PHP package josegonzalez/cakephp-version without Composer

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

Build Status Coverage Status Total Downloads Latest Stable Version Documentation Status Gratipay

Version

A CakePHP 4.x plugin that facilitates versioned database entities

Installation

Add the following lines to your application's composer.json:

followed by the command:

composer update

Or run the following command directly without changing your composer.json:

composer require josegonzalez/cakephp-version:dev-master

Usage

In your app's config/bootstrap.php add:

Usage

Run the following schema migration:

Note that the content field must be nullable if you want to be able to version any nullable fields in your application.

You may optionally add a version_id field of type integer to the table which is being versioned. This will store the latest version number of a given page.

If you wish to create the table using cakephp/migrations then you will need to use a migration that looks something like this:

Add the following line to your entities:

And then include the trait in the entity class:

Attach the behavior in the models you want with:

Whenever an entity is persisted - whether via insert or update - that entity is also persisted to the version table. You can access a given revision by executing the following code:

You can optionally retrieve all the versions:

Storing Additional Meta Data

cakephp-version dispatches an event Model.Version.beforeSave which you can optionally handle to attach additional meta-data about the version.

Add the necessary additional fields to your migration, for example:

Then define an event listener to handle the event and pass in additional metadata, for example:

Your event listener can then be attached in your project, for example:

Note that handling this event also allows you to modify/overwrite values generated by the plugin. This can provide useful functionality, but ensure that if your event listener returns array keys called version_id, model, foreign_key, field, content or created that this is the intended behavior.

Storing user_id as Meta Data

To store the user_id as additional meta data is easiest in combination with Muffin/Footprint. The above insertAdditionalData() method could then look like this:

Any controller with the FootprintAwareTrait used will then provide the _footprint data into the model layer for this event callback to use.

Bake Integration

If you load the plugin using 'bootstrap' => true, this plugin can be used to autodetect usage via the properly named database table. To do so, simply create a table with the version schema above named after the table you'd like to revision plus the suffix _versions. For instance, to version the following table:

Create the following table:

You can create a migration for this with the following bake command:

You'll also want to set the content field in this migration to nullable, otherwise you won't be able to version fields that can be nulled.

To track the current version in the posts table, you can create a migration to add the version_id field to the table:

Configuration

There are five behavior configurations that may be used:


All versions of cakephp-version with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
cakephp/orm Version ^5.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 josegonzalez/cakephp-version contains the following files

Loading the files please wait ....