-
Notifications
You must be signed in to change notification settings - Fork 14
/
ext.php
103 lines (92 loc) · 2.15 KB
/
ext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\skeleton;
class ext extends \phpbb\extension\base
{
const DEFAULT_PHP = '7.1.3';
const DEFAULT_PHPBB_MIN = '3.3.0';
const DEFAULT_PHPBB_MAX = '4.0.0@dev';
/**
* @var array An array of installation error messages
*/
protected $errors = [];
/**
* Check whether the extension can be enabled.
*
* @return bool|array True if it can be enabled. False if not, or an array of error messages in phpBB 3.3.
*/
public function is_enableable()
{
// Check requirements
$this->phpbb_requirement();
$this->php_requirement();
$this->ziparchive_exists();
return count($this->errors) ? $this->enable_failed() : true;
}
/**
* Check phpBB 3.2.3 minimum requirement.
*
* @return void
*/
protected function phpbb_requirement()
{
if (phpbb_version_compare(PHPBB_VERSION, '3.2.3', '<'))
{
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
}
else if (phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='))
{
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
}
}
/**
* Check PHP 5.6.0 minimum requirement.
*
* @return void
*/
protected function php_requirement()
{
if (PHP_VERSION_ID < 50600)
{
$this->errors[] = 'PHP_VERSION_ERROR';
}
}
/**
* Check PHP ZipArchive binary requirement.
*
* @return void
*/
protected function ziparchive_exists()
{
if (!class_exists('ZipArchive'))
{
$this->errors[] = 'NO_ZIPARCHIVE_ERROR';
}
}
/**
* Generate the best enable failed response for the current phpBB environment.
* Return error messages in phpBB 3.3 or newer. Return boolean false otherwise.
*
* @return array|bool
*/
protected function enable_failed()
{
if (phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
{
$language = $this->container->get('language');
$language->add_lang('common', 'phpbb/skeleton');
return array_map([$language, 'lang'], $this->errors);
}
return false;
}
}