mirror of
https://github.com/getgrav/grav.git
synced 2026-03-05 03:51:50 +01:00
Added new Licenses::validate method to validate the format of a License
This commit is contained in:
@@ -11,8 +11,21 @@ namespace Grav\Common\GPM;
|
||||
use Grav\Common\Grav;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
|
||||
/**
|
||||
* Class Licenses
|
||||
*
|
||||
* @package Grav\Common\GPM
|
||||
*/
|
||||
class Licenses
|
||||
{
|
||||
|
||||
/**
|
||||
* Regex to validate the format of a License
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $regex = '^(?:[A-F0-9]{8}-){3}(?:[A-F0-9]{8}){1}$';
|
||||
|
||||
/**
|
||||
* Returns the license for a Premium package
|
||||
*
|
||||
@@ -66,6 +79,26 @@ class Licenses
|
||||
return $data['licenses'][$slug];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates the License format
|
||||
*
|
||||
* @param $license
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($license = null)
|
||||
{
|
||||
if (!is_string($license)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return preg_match('#' . self::$regex. '#', $license);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected static function getLicensePath()
|
||||
{
|
||||
$path = Grav::instance()['locator']->findResource('user://data') . '/licenses.yaml';
|
||||
|
||||
Reference in New Issue
Block a user