PHP Classes

How to Use a PHP Version Manager Class to Execute Different Versions of the Same Class Using the Package PHP Stuff Versioned: Manage and run multiple versions of the same class

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-04-17 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
php-stuff-versioned 1.0Custom (specified...5Tools, Libraries, PHP 7
Description 

Author

This package can manage and run multiple versions of the same class.

It provides a version manager class that can keep track of multiple versions of classes that can be used to execute a given action.

The package can also call a specific version of the same class or call the latest version of the class.

A light library with zero dependency that provides a version manager and interfaces for version control anything and with any desired backend.

Picture of Andrey Postal
  Performance   Level  
Name: Andrey Postal <contact>
Classes: 4 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 1x

Instructions

Documentation

Stuff Versioned

Coverage Status

This is a light library with zero dependency that provides a version manager and interfaces for version control anything and with any desired backend (like file, mysql, mongodb, postgresql...)

Installation

composer require andreypostal/php-stuff-versioned

Available backends

Usage

Create your versions implementing the VersionInterface. This can be used to version stuff like data seed, data migrations, system updates....

The versioning process is controlled by the ID and can be used dynamically, like to perform versioning based on users or organization.

BackendInterface defines the structure needed to persist the versioning progress/history and will be used as checkpoints in the versioning process, ensuring we don't re-execute previous successful versions.

The only actual code shipped by this library is the VersionManager which only control the version list and the execution (run process) ensuring that we do not execute the same version id twice.

The order of version inclusion in the VersionManager maters and old versions should never change position or be removed. If some old version should not be executed on new environments, you should just skip if by returning 'false' in the check process.

Some simple library usage may look like:


$manager = new \Andrey\StuffVersioned\VersionManager(
    new MongoBackend(), // the chosen backend
    $logger, // this is optional
);
$manager->addVersion(new MyVersion_2025_03_01());
$manager->addVersion(new MyVersion_2025_03_02());
// or
$manager = $manager
    ->withVersion(new MyVersion_2025_03_03())
    ->withVersion(new MyVersion_2025_03_04());
    
// New versions should be added here at the end

$manager->run();

And your version implementation may look like:


class MyVersion_2025_03_01 implements \Andrey\StuffVersioned\VersionInterface
{
    public function check(): bool
    {
        return true;
    }

    public function run(): void
    {
        // Create some data    
    }

    public function rollback(): void
    {
        // Delete partially created data    
    }

    public function getId(): string
    {
        return 'MyVersion_2025_03_01';
    }
}


  Files folder image Files (15)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (5 files)
Files folder imagetests (5 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (15)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (15)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file tests.yml Data Auxiliary data

  Files folder image Files (15)  /  src  
File Role Description
  Plain text file BackendInterface.php Class Class source
  Plain text file VersionEntryInterface.php Class Class source
  Plain text file VersionInterface.php Class Class source
  Plain text file VersionManager.php Class Class source
  Plain text file VersionManagerInterface.php Class Class source

  Files folder image Files (15)  /  tests  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Configuration script
  Plain text file InMemoryBackend.php Class Class source
  Plain text file MyBestVersion.php Class Class source
  Plain text file VersionEntry.php Class Class source
  Plain text file VersionManagerTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0