| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Fallback; |
| 4 |
|
| 5 |
use ReflectionMethod; |
| 6 |
|
| 7 |
final class FallBack |
| 8 |
{ |
| 9 |
public static function getOlderVersion() |
| 10 |
{ |
| 11 |
$installed = get_option('bitforms_installed'); |
| 12 |
$oldversion = null; |
| 13 |
if ($installed) { |
| 14 |
$oldversion = get_option('bitforms_version'); |
| 15 |
} |
| 16 |
return $oldversion; |
| 17 |
} |
| 18 |
|
| 19 |
public static function add($version, $invokeable, $check = '>=') |
| 20 |
{ |
| 21 |
$oldversion = self::getOlderVersion(); |
| 22 |
if ($oldversion && version_compare($oldversion, BITFORMS_VERSION, '!=')) { |
| 23 |
return static::action($version, $invokeable, $oldversion, $check); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public static function action($version, $invokeable, $oldversion, $check) |
| 28 |
{ |
| 29 |
if (!version_compare($version, $oldversion, $check)) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
$namespace = 'BitCode\BitForm\Core\Fallback'; |
| 33 |
$invoke = explode('@', $invokeable); |
| 34 |
if (is_array($invoke) && 2 === count($invoke)) { |
| 35 |
$fileName = $invoke[0]; |
| 36 |
$method = $invoke[1]; |
| 37 |
$class = $namespace . '\\' . $fileName; |
| 38 |
if (class_exists($class) && method_exists($class, $method)) { |
| 39 |
$invokeMethod = new ReflectionMethod($class, $method); |
| 40 |
$invokeMethod->invoke($invokeMethod->isStatic() ? null : new $class()); |
| 41 |
} else { |
| 42 |
return 'Method or class not exist'; |
| 43 |
} |
| 44 |
} else { |
| 45 |
return 'Invalid invokeable'; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|