Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Set min PHP to 7.1 and add checking code for minor/point release comp…
Browse files Browse the repository at this point in the history
…arison, fixes #106
  • Loading branch information
damieng committed Feb 22, 2018
1 parent 460ad8d commit ac8bdb4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {AutoLanguageClient, DownloadFile} = require('atom-languageclient')
const serverDownloadUrl = 'https://github.com/atom/ide-php/files/1708112/php-ls-5.3.6.tar.gz'
const serverDownloadSize = 3434791
const serverLauncher = path.join('felixfbecker', 'language-server', 'bin', 'php-language-server.php')
const minPHPRuntime = 7
const minPHPRuntime = '7.1'
const bytesToMegabytes = 1024 * 1024

class PHPLanguageClient extends AutoLanguageClient {
Expand Down Expand Up @@ -65,7 +65,7 @@ class PHPLanguageClient extends AutoLanguageClient {
if (alreadyShownError) return
if (exitCode === 0 && stdOut != '') {
this.logger.debug(`Using PHP ${stdOut} from ${command}`)
if (Number(stdOut.split('.')[0]) >= minPHPRuntime) {
if (this.meetsRequiredVersion(stdOut, minPHPRuntime)) {
resolve()
} else {
atom.notifications.addError(`IDE-PHP requires PHP ${minPHPRuntime} or later but found ${stdOut}`, {
Expand All @@ -89,6 +89,24 @@ class PHPLanguageClient extends AutoLanguageClient {
})
}

meetsRequiredVersion (versionString, requiredString) {
var version = versionString.split('.')
var required = requiredString.split('.')

for (var i = 0; i < required.length; i++) {
if (i >= version.length) return false

var versionPoint = parseInt(version[i])
var requiredPoint = parseInt(required[i])

if (versionPoint < requiredPoint) return false;
if (versionPoint > requiredPoint) return true;
// Otherwise check next part via loop
}

return true
}

downloadPHP () {
shell.openExternal('https://secure.php.net/downloads.php')
}
Expand Down

0 comments on commit ac8bdb4

Please sign in to comment.