<?php namespace App; use Cylab\Mark\Client; use Composer\Semver\Semver; /** * Description of Mark * * @author tibo */ class Mark { private static $VERSION_CONSTRAINT = "^2.3.0"; private static $instance; public static function get() : Client { if (self::$instance !== null) { return self::$instance; } $mark_url = 'http://' . config("app.mark_host") . ':' . config('app.mark_port'); $instance = new Client($mark_url); // test we can connect to the server try { $instance->test(); } catch (\JsonRPC\Exception\ConnectionFailureException $ex) { session()->flash('error', 'Failed to connect to MARk server at ' . $mark_url); abort(redirect('app/error')); } // test the server satisfies the required version // first remove the -SNAPSHOT suffix, so we can use development version of MARk $server_version = str_replace("-SNAPSHOT", "", $instance->status()["version"]); if (! Semver::satisfies($server_version, self::$VERSION_CONSTRAINT)) { session()->flash('error', 'MARk server does not satisfy required version ' . self::$VERSION_CONSTRAINT); abort(redirect('app/error')); } self::$instance = $instance; return $instance; } }