Skip to content

Instantly share code, notes, and snippets.

@dakur
Last active November 14, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakur/ae791a1a309bf2f1ea3e80e7fd00bff0 to your computer and use it in GitHub Desktop.
Save dakur/ae791a1a309bf2f1ea3e80e7fd00bff0 to your computer and use it in GitHub Desktop.

Joomla version faker

Installation

  1. Clone this repository.
  2. Run composer install in project root.
  3. Make /data folder writable.

Usage

  • Request GET / for obtaining current fake version.
  • Request PATCH / for increasing current version.
{
"require": {
"slim/slim": "^3.11",
"league/flysystem": "^1.0"
}
}
<?php
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;
require_once __DIR__ . '/vendor/autoload.php';
final class Faker
{
const DATA_DIRECTORY = '/data';
const CURRENT_VERSION_FILE_NAME = 'current-version';
/** @var Filesystem */
private $fileSystem;
/** @var App */
private $app;
public function __construct()
{
$this->fileSystem = new Filesystem(new Local(__DIR__ . self::DATA_DIRECTORY));
$this->app = new App();
}
public function fake()
{
$fileSystem = $this->fileSystem;
// get current version
$this->app->get('/', function (Request $request, Response $response, $args) use ($fileSystem) {
if ( ! $fileSystem->has(self::CURRENT_VERSION_FILE_NAME)) {
return $response->withStatus(500)->write('Current version is not available.');
}
$currentVersion = $fileSystem->read(self::CURRENT_VERSION_FILE_NAME);
if ($currentVersion === '') {
return $response->withStatus(500)->write('Version sequence was not started. Request PATCH / first.');
}
return $response->write('0.0.' . $currentVersion);
});
// increase current version
$this->app->patch('/', function (Request $request, Response $response, $args) use ($fileSystem) {
if ( ! $fileSystem->has(self::CURRENT_VERSION_FILE_NAME)) {
$currentVersion = 1;
$fileSystem->write(self::CURRENT_VERSION_FILE_NAME, $currentVersion);
} else {
$currentVersion = $fileSystem->read(self::CURRENT_VERSION_FILE_NAME);
if ($currentVersion === '') {
$currentVersion = 0;
}
$currentVersion = ((int) $currentVersion) + 1;
$fileSystem->update(self::CURRENT_VERSION_FILE_NAME, $currentVersion);
}
return $response->write('0.0.' . $currentVersion);
});
$this->app->run();
}
}
(new Faker())->fake();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment