[3.3.0-b1] ext.php & custom reasons

Discussion forum for Extension Writers regarding Extension Development.
User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4933
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [3.3.0-b1] ext.php & custom reasons

Post by VSE » Tue Nov 05, 2019 5:19 am

3Di wrote:
Mon Nov 04, 2019 6:49 am
Well, all of this does not help in my case.
Something I came up with for multiple tests. Again, I don't care about messages for phpBB 3.2 or 3.1. Once 3.3 is out, that is what we'd like users to use...not the end of life or soon to be end of life versions. Basically it's such a convoluted work-around to achieve this same result with 3.2/3.1 that you may as well just continue using that for 3.3 and beyond...because it's silly to do both. For me personally, the feature arrived in 3.3, so that's where I will use it.

Code: Select all

/**
 * @var array An array of installation error messages
 */
protected $errors = [];

/**
 * Check whether or not the extension can be enabled.
 *
 * @return bool|array True if 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.0 minimum requirement.
 *
 * @return void
 */
protected function phpbb_requirement()
{
	if (phpbb_version_compare(PHPBB_VERSION, '3.2.0', '<'))
	{
		$this->errors[] = 'PHPBB_VERSION_ERROR';
	}
}

/**
 * Check PHP 5.4.0 minimum requirement.
 *
 * @return void
 */
protected function php_requirement()
{
	if (phpbb_version_compare(PHP_VERSION, '5.4.0', '<'))
	{
		$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('install_errors', 'vendor/extension');
		return array_map([$language, 'lang'], $this->errors);
	}

	return false;
}
Now, obviously in this example, the first 2 tests: >= phpBB 3.2.0 and >= PHP 5.4 are meaningless to a user who can see these error messages, as they would be using phpBB 3.3.0 already so those tests would always pass for them. But we do test for the ZipArchive library here, and that could potentially fail for somebody on a 3.3 board so they would at least get an explanation why they can't enable for that.
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

Post Reply

Return to “Extension Writers Discussion”