Download the PHP package prewk/snapper-php without Composer

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

Snapper 🐡 Coverage Status Build Status

Converts rows from a relational database into serialization snapshots that can be deserialized into new rows at a later time with complex relationships preserved.

Example

From database into the serializer

Out from the serializer

Deserialize into database again

How to serialize?

How to deserialize?

Ingredient types

Value

Pass through the value of the field.

Raw

Force the value of the field.

Ref

The field is a foreign key that references another table. The optional method takes arguments that, when equal to the encountered field value, is considered non-references and are just passed through like Value.

Morph

Specify a polymorphic relation using two fields, one type (foo_type) and one id (foo_id), and map values in foo_type against other tables.

Requires both fields to be present to function properly, supports optional values that when matched ignores the foreign relation and just passes though the value.

Match

Look at the given field (type in the example above) and become different ingredients depending on its value.

If no match is successful and no default is provided, the field will not be included.

Json

Define references nested in JSON.

On string and integer refs inside the JSON

The library is built for the normal scenario of integer keys (AUTO_INCREMENT), but when serializing references they will be converted to UUIDS (v4). They are strings that look like this: a0ff60f5-87fe-4d4e-855b-8993f1c3b065.

This poses a problem in JSON when..

..gets serialized into..

..and back into a integer key:

"456" is not strictly equal to 456. Therefore, the deserialization logic is as follows:

  1. If the id returned from the inserter is numeric then all "UUID" will be replaced with INSERT_ID
  2. All UUID will be replaced with INSERT_ID

Circular

If two of your tables contain circular references to each other, wrap one of the references with a Circular ingredient. Specify a valid fallback as optional value and specify that value as a fallback Raw ingredient.

The resulting serialization will start with an INSERT op containing the fallback value, and end with an UPDATE op with the real reference.

Events

onDeps

Override recipes/updaters/inserters

Recipe JSON

Recipes can be converted to/from JSON which can be useful.

Validation

Validate a serialization

Check a serialization for unresolvable references

Validate a JSON recipe

Recipes can be validated with a JSON schema validator.

Batched inserts/updates

The insert/update closures will be called with batches of rows that each can be executed in one SQL operation if you want to optimize:

The following rules apply for the return value from inserters:

The batch grouping logic considers one of the following conditions as "start a new batch of operations":

Id manifest

The result of a compilation ($serializer->compile()) is a Serialization. It has two methods:

Why?

The library is useful for providing snapshot functionality to multi-tenant services where a user owns one or more complex sets of data with complex internal relationships.

Howtos

I don't want to create table X, it already exists

The deserializer doesn't care about the inserter closure's internal logic, it only requires you to return the primary key:

I need row metadata to be serialized

Just use $recipe->value() in the recipe and feed whatever fields you want to the Serializer and it'll end up in the snapshot.

When deserializing, pick and choose which fields to insert into the database in your inserter.

I have composite keys

Unsupported at the moment, a workaround is adding a unique id and pretending that's the primary key.

License

MIT


All versions of snapper-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7
illuminate/support Version 5.*
marcj/topsort Version ^1.1
ramsey/uuid Version ^3.7
prewk/option Version 1.*
prewk/snapper-schema Version 2.1.2
prewk/result Version 1.*
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 prewk/snapper-php contains the following files

Loading the files please wait ....