Completed
Pull Request — master (#70)
by Matt
01:18
created

ext::enable_failed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 *
4
 * phpBB Media Embed PlugIn extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2016 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\mediaembed;
12
13
class ext extends \phpbb\extension\base
14
{
15
	/** @var string YAML file extension */
16
	const YML = '.yml';
17
18
	/**
19
	 * @var array An array of installation error messages
20
	 */
21
	protected $errors = [];
22
23
	/**
24
	 * {@inheritDoc}
25
	 */
26
	public function is_enableable()
27
	{
28
		$this->phpbb_version_is_valid();
29
		$this->s9e_mediamebed_installed();
30
31
		return count($this->errors) ? $this->enable_failed() : true;
32
	}
33
34
	/**
35
	 * Check the installed phpBB version meets this
36
	 * extension's requirements.
37
	 *
38
	 * Minimum requirements: phpBB 3.2.1
39
	 *
40
	 * @return void
41
	 */
42
	public function phpbb_version_is_valid()
43
	{
44
		if (phpbb_version_compare(PHPBB_VERSION, '3.2.1', '<'))
45
		{
46
			$this->errors[] = 'PHPBB_VERSION_ERROR';
47
		}
48
	}
49
50
	/**
51
	 * Check if s9e MediaEmbed extension for phpBB is installed
52
	 * (it must NOT be to enable this extension).
53
	 *
54
	 * @return void
55
	 */
56
	public function s9e_mediamebed_installed()
57
	{
58
		$ext_manager = $this->container->get('ext.manager');
59
60
		if ($ext_manager->is_enabled('s9e/mediaembed'))
61
		{
62
			$this->errors[] = 'S9E_MEDIAEMBED_ERROR';
63
		}
64
	}
65
66
	/**
67
	 * Generate the best enable failed response for the current phpBB environment.
68
	 * Return error messages in phpBB 3.3 or newer. Return boolean false otherwise.
69
	 *
70
	 * @return array|bool
71
	 */
72
	protected function enable_failed()
73
	{
74
		if (phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
75
		{
76
			$language = $this->container->get('language');
77
			$language->add_lang('install', 'phpbb/mediaembed');
78
			return array_map([$language, 'lang'], $this->errors);
79
		}
80
81
		return false;
82
	}
83
}
84