1
|
|
|
<?php namespace Xoopsmodules\xsitemap\common; |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
14
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
15
|
|
|
* @author mamba <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
trait VersionChecks |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
22
|
|
|
* @static |
23
|
|
|
* @param \XoopsModule $module |
|
|
|
|
24
|
|
|
* |
25
|
|
|
* @param null|string $requiredVer |
26
|
|
|
* @return bool true if meets requirements, false if not |
27
|
|
|
*/ |
28
|
|
|
public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
29
|
|
|
{ |
30
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
31
|
|
|
if (null === $module) { |
32
|
|
|
$module = \XoopsModule::getByDirname($moduleDirName); |
33
|
|
|
} |
34
|
|
|
xoops_loadLanguage('admin', $moduleDirName); |
35
|
|
|
|
36
|
|
|
//check for minimum XOOPS version |
37
|
|
|
$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
38
|
|
|
if (null === $requiredVer) { |
39
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
40
|
|
|
} |
41
|
|
|
$success = true; |
42
|
|
|
|
43
|
|
|
if (version_compare($currentVer, $requiredVer, '<')){ |
44
|
|
|
$success = false; |
45
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $success; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* |
53
|
|
|
* Verifies PHP version meets minimum requirements for this module |
54
|
|
|
* @static |
55
|
|
|
* @param \XoopsModule $module |
56
|
|
|
* |
57
|
|
|
* @return bool true if meets requirements, false if not |
58
|
|
|
*/ |
59
|
|
|
public static function checkVerPhp(\XoopsModule $module) |
60
|
|
|
{ |
61
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
62
|
|
|
// check for minimum PHP version |
63
|
|
|
$success = true; |
64
|
|
|
$verNum = PHP_VERSION; |
65
|
|
|
$reqVer =& $module->getInfo('min_php'); |
66
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
67
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
68
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_PHP, $reqVer, $verNum)); |
69
|
|
|
$success = false; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $success; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.