diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-01 23:47:22 +0300 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-04 13:40:33 +0300 |
commit | b469e9f6fb83758ad91b8e41d81319ab3a73f098 (patch) | |
tree | 5ccc10851661957739d893d914c278e1b18ff409 /lib/private/app | |
parent | f74d568bdac14390a787a71f91571d84662f1fbe (diff) |
introduce dependency analyzer to take care of app dependencies
some more unit tests on xml info parser
Diffstat (limited to 'lib/private/app')
-rw-r--r-- | lib/private/app/dependencyanalyzer.php | 58 | ||||
-rw-r--r-- | lib/private/app/infoparser.php | 6 | ||||
-rw-r--r-- | lib/private/app/platform.php | 17 |
3 files changed, 79 insertions, 2 deletions
diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php new file mode 100644 index 00000000000..c76181926e2 --- /dev/null +++ b/lib/private/app/dependencyanalyzer.php @@ -0,0 +1,58 @@ +<?php + /** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\App; + +class DependencyAnalyzer { + + /** + * @param array $app + * @param Platform $system + * @param \OCP\IL10N $l + */ + function __construct(array $app, $system, $l) { + $this->system = $system; + $this->l = $l; + $this->missing = array(); + $this->dependencies = array(); + if (array_key_exists('dependencies', $app)) { + $this->dependencies = $app['dependencies']; + } + } + + /** + * @param array $app + * @returns array of missing dependencies + */ + public function analyze() { + $this->analysePhpVersion(); + return $this->missing; + } + + private function analysePhpVersion() { + if (!array_key_exists('php', $this->dependencies)) { + return; + } + + if (array_key_exists('min-version', $this->dependencies['php'])) { + $minVersion = $this->dependencies['php']['min-version']; + if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) { + $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); + } + } + if (array_key_exists('max-version', $this->dependencies['php'])) { + $maxVersion = $this->dependencies['php']['max-version']; + if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) { + $this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion); + } + } + } + +} diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index b0327fa4fd1..e220fb40df6 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -64,7 +64,7 @@ class InfoParser { $array['types'] = array(); } - if (array_key_exists('documentation', $array)) { + if (array_key_exists('documentation', $array) && is_array($array['documentation'])) { foreach ($array['documentation'] as $key => $url) { // If it is not an absolute URL we assume it is a key // i.e. admin-ldap will get converted to go.php?to=admin-ldap @@ -78,7 +78,9 @@ class InfoParser { if (array_key_exists('types', $array)) { foreach ($array['types'] as $type => $v) { unset($array['types'][$type]); - $array['types'][] = $type; + if (is_string($type)) { + $array['types'][] = $type; + } } } diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php new file mode 100644 index 00000000000..292159337a0 --- /dev/null +++ b/lib/private/app/platform.php @@ -0,0 +1,17 @@ +<?php + /** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\App; + +class Platform { + public function getPhpVersion() { + return phpversion(); + } +} |