Download the PHP package plank/snapshots without Composer

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

PHP Version Support PHP Version Support GitHub Workflow Status

Laravel Snapshots

:warning: Package is under active development. Wait for v1.0.0 for production use. :warning:

Snapshots is a Laravel package that allows you to version the content of your app by replicating database tables and their content. Each snapshot represents a browesable version of your app's content at a specific point in time. By changing the active version of your app, you can view your app's content at a previous version.

The main goal of this package is for it to perform robust versioning of your content, but stay out of your way. You should be able to use it without having to change your existing codebase. It should be easy to install and configure, and it should be easy to use.

Table of Contents

 

Installation

You can install the package via composer:

You can use the package's install command to complete the installation:

Quick Start

Once the installation has completed, to begin using the package:

  1. Make all migrations for versioned content extend Plank\Snapshots\Migrations\SnapshotMigration instead of the framework's Migration class.
  2. Replace references to Illuminate\Database\Schema\Builder with $this->schema or Plank\Snapshots\Facades\SnapshotSchema in those migrations for the versioned content.
  3. Make all models representing versioned content implement Plank\Snapshots\Contracts\Versioned and use the Plank\Snapshots\Concerns\AsVersionedContent trait.
  4. Make all models that are not versioned, but have a relation to versioned content use the Plank\Snapshots\Concerns\InteractsWithVersionedContent trait.
  5. Create a middleware to set the active version of your app based on the request.

Middleware example:

Now, whenever you create a new version, the SnapshotDatabase listener will handle the VersionCreated event and run all of the migrations for the versioned content. It will also copy the content from the previous version of the table into the new version of the table.

 

Configuration

The package's configuration file is located at config/snapshots.php. If you did not publish the config file during installation, you can publish the configuration file using the following command:

Version Model

The model option is the fully qualified class name of the model that will be used to store the versions of your app. The default value is Plank\Snapshots\Models\Version. Any model provided must implement the Plank\Snapshots\Contracts\Version interface.

Version Factory

The factory option is the fully qualified class name of the model factory that will be used to generate Version instances for testing and seeding your application. The default value is Plank\Snapshots\Factories\VersionFactory.

Repository

The repository option is the fully qualified class name of the repository that will be used to retrieve the versions of your app. The default value is Plank\Snapshots\Repository\VersionRepository. Any repository provided must implement the Plank\Snapshots\Contracts\ManagesVersions interface.

Auto Migration

The auto_migrate option determines whether or not the package will automatically create new tables for all of the versioned content when a new version model is created. The package provides the default implementation of Plank\Snapshots\Listeners\SnapshotDatabase, but you can provide your own implementation.

Auto Copy

The auto_copy option determines whether or not the package will automatically copy content to the newly versioned tables when a new version model is created.

The package provides the default implementation of Plank\Snapshots\Listeners\CopyTable, where the data is copied over at the database level.

The package also ships with Plank\Snapshots\Listeners\CopyModels, where the data is copied over at the model level. This is useful if you have custom logic in your models that needs to be run when the data is copied over.

You can also provide your own implementation by setting it in the configuration file.

 

Usage

Versions

Contract and Model

Snapshots are identified by and accessed through a Version model. This model is created by the package or can be overriden by the consumer by creating a class which implements the Plank\Contracts\Version contract, and specifying it as the model in the configuration file.

In applications that use this package, requests should generally specify an "active" Version. The active Version will alter the database tables which versioned content will be queried on.

Events

Repository

The ManagesVersions interface is a minimal interface for a Version repository required for the migrator to function. The package provides a VersionRepository class which implements this interface, but it can be overriden by the consumer by creating a class which implements the Plank\Contracts\ManagesVersions contract, and specifying it as the repository in the configuration file.

The repository is responsible for querying existing versions and managing the active version. It is not used to create new versions, as that is out of scope for the package.

Migrations

SnapshotMigration

This package adds a SnapshotMigration class, to house the migrations for all of your versioned content. It allows the SnapshotMigrator to know which migrations need to be run accross all of the versions of your app.

To use it, simply make the Migration classes extend SnapshotMigration instead of the framework's Migration class.

You will notice that in a SnapshotMigration you have $this->schema available which is the SnapshotBuilder instance. It is a wrapper around the framework's \Illuminate\Database\Schema\Builder class. You can also use the SnapshotSchema facade, however you should only use that inside a SnapshotMigration.

The SnapshotMigrations allow you to declare migrations in the way you are used to, but under the hood it will handle all of the versioning.

You will also notice the SnapshotBlueprint class. This blueprint type exists to allow you to define foreign keys to versioned content from versioned content using the ->onSnapshot() method.

Limitations
  1. Foreign keys for relations from unversioned content to versioned content can not be used. This is due to there being more than one version of the table, and the foreign key will not know which version to reference. Foreign keys from versioned content to unversioned content, and from versioned content to versioned content are still possible.

  2. It is important to note that pivot tables where at least one of the related models is versioned, should also be versioned. This is because the pivot table will need to be copied for each version of the related model.

  3. It is also important to note that if you are using a versioned custom Pivot model, you cannot relate unversioned content to unversioned content through the pivot. So be especially careful with what you are relating through your custom polymorphic pivot models.

 

SnapshotMigrator

This package will replace the framework's migrator with the SnapshotMigrator class. The migrator extends the framework's migrator with the sole purpose of ensuring the migrations for your versioned content are run for every version of your app.

For example, after running migrations in a traditional Laravel Application, you might have the following:

However, in a Laravel Application using Snapshots, you might have the following after the initial migration:

When creating the first Version model – with auto_migrate set to true – assuming the Page content is versioned, the package will re-run your 2023_09_25_000002_create_pages_table migration for the new Version.

The following output is shown as an illustration. The migration is ran in the background, and not output.

Finally, assume you add a new migration 2023_09_25_000003_add_slug_to_pages_table to add a slug column to the pages table, and you run the migrations on deploy.

The migration is applied to all versions of your content to achieve consistency across versions.

 

Models

Versioned Models

This package provides a Plank\Snapshots\Contracts\Versioned interface, and an AsVersionedContent trait. For models whose content should be versioned, have them implement the Versioned interface, and use the AsVersionedContent trait.

This trait ensures queries on the model's table are prefixed with the active version's prefix. It also overrides the pivotted relations to use the versioned pivot table.

Example:

Unversioned Models

For any models that have an association to a versioned model, you can use the Plank\Snapshots\Concerns\InteractsWithVersionedContent trait. This trait ensures that when a versioned model is related through a pivot, the versioned pivot table is used.

Example:

 

Contributing

Please see CONTRIBUTING for details.

 

Credits

 

License

The MIT License (MIT). Please see License File for more information.

 

Security Vulnerabilities

If you discover a security vulnerability within siren, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

 

Check Us Out!

 

Plank focuses on impactful solutions that deliver engaging experiences to our clients and their users. We're committed to innovation, inclusivity, and sustainability in the digital space. Learn more about our mission to improve the web.


All versions of snapshots with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
doctrine/dbal Version ^3.6|^4
illuminate/contracts Version ^10|^11
plank/laravel-hush Version ^1.0
spatie/laravel-package-tools Version ^1.14.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 plank/snapshots contains the following files

Loading the files please wait ....