diff options
Diffstat (limited to 'lib/private/app')
-rw-r--r-- | lib/private/app/dependencyanalyzer.php | 87 | ||||
-rw-r--r-- | lib/private/app/infoparser.php | 74 | ||||
-rw-r--r-- | lib/private/app/platform.php | 33 |
3 files changed, 189 insertions, 5 deletions
diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php new file mode 100644 index 00000000000..fb4b3761656 --- /dev/null +++ b/lib/private/app/dependencyanalyzer.php @@ -0,0 +1,87 @@ +<?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 { + + /** @var Platform */ + private $system; + + /** @var \OCP\IL10N */ + private $l; + + /** @var array */ + private $missing; + + /** @var array */ + private $dependencies; + + /** + * @param array $app + * @param Platform $platform + * @param \OCP\IL10N $l + */ + function __construct(array $app, $platform, $l) { + $this->system = $platform; + $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(); + $this->analyseSupportedDatabases(); + return $this->missing; + } + + private function analysePhpVersion() { + if (isset($this->dependencies['php']['@attributes']['min-version'])) { + $minVersion = $this->dependencies['php']['@attributes']['min-version']; + if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) { + $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); + } + } + if (isset($this->dependencies['php']['@attributes']['max-version'])) { + $maxVersion = $this->dependencies['php']['@attributes']['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); + } + } + } + + private function analyseSupportedDatabases() { + if (!isset($this->dependencies['database'])) { + return; + } + + $supportedDatabases = $this->dependencies['database']; + if (empty($supportedDatabases)) { + return; + } + $supportedDatabases = array_map(function($db) { + if (isset($db['@value'])) { + return $db['@value']; + } + return $db; + }, $supportedDatabases); + $currentDatabase = $this->system->getDatabase(); + if (!in_array($currentDatabase, $supportedDatabases)) { + $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); + } + } +} diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index b4bdbea5c04..0bfbf6bd139 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -47,7 +47,7 @@ class InfoParser { if ($xml == false) { return null; } - $array = json_decode(json_encode((array)$xml), TRUE); + $array = $this->xmlToArray($xml, false); if (is_null($array)) { return null; } @@ -60,8 +60,11 @@ class InfoParser { if (!array_key_exists('public', $array)) { $array['public'] = array(); } + if (!array_key_exists('types', $array)) { + $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 @@ -73,9 +76,70 @@ class InfoParser { } } if (array_key_exists('types', $array)) { - foreach ($array['types'] as $type => $v) { - unset($array['types'][$type]); - $array['types'][] = $type; + if (is_array($array['types'])) { + foreach ($array['types'] as $type => $v) { + unset($array['types'][$type]); + if (is_string($type)) { + $array['types'][] = $type; + } + } + } else { + $array['types'] = array(); + } + } + + return $array; + } + + /** + * @param \SimpleXMLElement $xml + * @return array + */ + function xmlToArray($xml) { + if (!$xml->children()) { + return (string)$xml; + } + + $array = array(); + foreach ($xml->children() as $element => $node) { + $totalElement = count($xml->{$element}); + + if (!isset($array[$element])) { + $array[$element] = ""; + } + /** + * @var \SimpleXMLElement $node + */ + + // Has attributes + if ($attributes = $node->attributes()) { + $data = array( + '@attributes' => array(), + ); + if (!count($node->children())){ + $value = (string)$node; + if (!empty($value)) { + $data['@value'] = (string)$node; + } + } else { + $data = array_merge($data, $this->xmlToArray($node)); + } + foreach ($attributes as $attr => $value) { + $data['@attributes'][$attr] = (string)$value; + } + + if ($totalElement > 1) { + $array[$element][] = $data; + } else { + $array[$element] = $data; + } + // Just a value + } else { + if ($totalElement > 1) { + $array[$element][] = $this->xmlToArray($node); + } else { + $array[$element] = $this->xmlToArray($node); + } } } diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php new file mode 100644 index 00000000000..39f8a2979f9 --- /dev/null +++ b/lib/private/app/platform.php @@ -0,0 +1,33 @@ +<?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; + +use OCP\IConfig; + +class Platform { + + function __construct(IConfig $config) { + $this->config = $config; + } + + public function getPhpVersion() { + return phpversion(); + } + + public function getDatabase() { + $dbType = $this->config->getSystemValue('dbtype', 'sqlite'); + if ($dbType === 'sqlite3') { + $dbType = 'sqlite'; + } + + return $dbType; + } +} |