From 5829097649009879edd325b38b978e4061553805 Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 8 Feb 2011 05:28:42 +0000 Subject: Added suggests to the plugins deps system. It parallels the requires system, but doesn't affect if the plugin can be enabled and only shows up in the deps table on the advanced view. git-svn-id: http://code.elgg.org/elgg/trunk@8070 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggPluginManifest.php | 170 +++++++++++++++----------- engine/classes/ElggPluginManifestParser18.php | 7 +- engine/classes/ElggPluginPackage.php | 9 +- 3 files changed, 112 insertions(+), 74 deletions(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 7a261a755..7c9c0670e 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -25,7 +25,7 @@ class ElggPluginManifest { /** * The expected structure of a requires element */ - private $depsRequiresStructPlugin = array( + private $depsStructPlugin = array( 'type' => '', 'name' => '', 'version' => '', @@ -35,7 +35,7 @@ class ElggPluginManifest { /** * The expected structure of a requires element */ - private $depsRequiresStructPriority = array( + private $depsStructPriority = array( 'type' => '', 'priority' => '', 'plugin' => '' @@ -44,7 +44,7 @@ class ElggPluginManifest { /* * The expected structure of elgg and elgg_release requires element */ - private $depsRequiresStructElgg = array( + private $depsStructElgg = array( 'type' => '', 'version' => '', 'comparison' => 'ge' @@ -53,7 +53,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_ini dependency element */ - private $depsRequiresStructPhpIni = array( + private $depsStructPhpIni = array( 'type' => '', 'name' => '', 'value' => '', @@ -63,7 +63,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_extension dependency element */ - private $depsRequiresStructPhpExtension = array( + private $depsStructPhpExtension = array( 'type' => '', 'name' => '', 'version' => '', @@ -427,88 +427,118 @@ class ElggPluginManifest { $normalized = array(); foreach ($reqs as $req) { + $normalized[] = $this->normalizeDep($req); + } - switch ($req['type']) { - case 'elgg_version': - case 'elgg_release': - $struct = $this->depsRequiresStructElgg; - break; + return $normalized; + } - case 'plugin': - $struct = $this->depsRequiresStructPlugin; - break; + /** + * Returns the suggests elements. + * + * @return array + */ + public function getSuggests() { + $suggests = $this->parser->getAttribute('suggests'); - case 'priority': - $struct = $this->depsRequiresStructPriority; - break; + if (!$suggests) { + $suggests = array(); + } - case 'php_extension': - $struct = $this->depsRequiresStructPhpExtension; - break; + $normalized = array(); + foreach ($suggests as $suggest) { + $normalized[] = $this->normalizeDep($suggest); + } + + return $normalized; + } - case 'php_ini': - $struct = $this->depsRequiresStructPhpIni; - - // also normalize boolean values - if (isset($req['value'])) { - switch (strtolower($normalized_req['value'])) { - case 'yes': - case 'true': - case 'on': - case 1: - $normalized_req['value'] = 1; - break; - - case 'no': - case 'false': - case 'off': - case 0: - case '': - $normalized_req['value'] = 0; - break; - } + /** + * Normalizes a dependency array using the defined structs. + * Can be used with either requires or suggests. + * + * @param array $dep An dependency array. + * @return array The normalized deps array. + */ + private function normalizeDep($dep) { + switch ($dep['type']) { + case 'elgg_version': + case 'elgg_release': + $struct = $this->depsStructElgg; + break; + + case 'plugin': + $struct = $this->depsStructPlugin; + break; + + case 'priority': + $struct = $this->depsStructPriority; + break; + + case 'php_extension': + $struct = $this->depsStructPhpExtension; + break; + + case 'php_ini': + $struct = $this->depsStructPhpIni; + + // also normalize boolean values + if (isset($dep['value'])) { + switch (strtolower($normalized_dep['value'])) { + case 'yes': + case 'true': + case 'on': + case 1: + $normalized_dep['value'] = 1; + break; + + case 'no': + case 'false': + case 'off': + case 0: + case '': + $normalized_dep['value'] = 0; + break; } + } - break; - } + break; + } - $normalized_req = $this->buildStruct($struct, $req); + $normalized_dep = $this->buildStruct($struct, $dep); - // normalize comparison operators - if (isset($normalized_req['comparison'])) { - switch ($normalized_req['comparison']) { - case '<': - $normalized_req['comparison'] = 'lt'; - break; + // normalize comparison operators + if (isset($normalized_dep['comparison'])) { + switch ($normalized_dep['comparison']) { + case '<': + $normalized_dep['comparison'] = 'lt'; + break; - case '<=': - $normalized_req['comparison'] = 'le'; - break; + case '<=': + $normalized_dep['comparison'] = 'le'; + break; - case '>': - $normalized_req['comparison'] = 'gt'; - break; + case '>': + $normalized_dep['comparison'] = 'gt'; + break; - case '>=': - $normalized_req['comparison'] = 'ge'; - break; + case '>=': + $normalized_dep['comparison'] = 'ge'; + break; - case '==': - case 'eq': - $normalized_req['comparison'] = '='; - break; + case '==': + case 'eq': + $normalized_dep['comparison'] = '='; + break; - case '<>': - case 'ne': - $normalized_req['comparison'] = '!='; - break; - } + case '<>': + case 'ne': + $normalized_dep['comparison'] = '!='; + break; } - - $normalized[] = $normalized_req; } - return $normalized; + return $normalized_dep; } /** diff --git a/engine/classes/ElggPluginManifestParser18.php b/engine/classes/ElggPluginManifestParser18.php index 1f5b51bb5..c74b23e32 100644 --- a/engine/classes/ElggPluginManifestParser18.php +++ b/engine/classes/ElggPluginManifestParser18.php @@ -14,9 +14,9 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { */ protected $validAttributes = array( 'name', 'author', 'version', 'blurb', 'description', - 'website', 'copyright', 'license', 'requires', 'screenshot', - 'category', 'conflicts', 'provides', 'on_activate', 'on_deactivate', - 'admin_interface', 'activate_on_install' + 'website', 'copyright', 'license', 'requires', 'suggests', + 'screenshot', 'category', 'conflicts', 'provides', 'on_activate', + 'on_deactivate', 'admin_interface', 'activate_on_install' ); /** @@ -63,6 +63,7 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { case 'provides': case 'conflicts': case 'requires': + case 'suggests': if (!isset($element->children)) { return false; } diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 48a5fc4a8..2ae686b25 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -340,7 +340,14 @@ class ElggPluginPackage { } } - foreach (array('requires', 'conflicts') as $dep_type) { + $check_types = array('requires', 'conflicts'); + + if ($full_report) { + $suggests = $this->getManifest()->getSuggests(); + $check_types[] = 'suggests'; + } + + foreach ($check_types as $dep_type) { $inverse = ($dep_type == 'conflicts') ? true : false; foreach (${$dep_type} as $dep) { -- cgit v1.2.3