Merge branch 'php/7.0'

This commit is contained in:
Dylan K. Taylor
2017-09-07 19:33:01 +01:00
2 changed files with 39 additions and 29 deletions

View File

@ -5,7 +5,6 @@ php:
before_script: before_script:
# - pecl install channel://pecl.php.net/pthreads-3.1.6 # - pecl install channel://pecl.php.net/pthreads-3.1.6
- pecl install channel://pecl.php.net/weakref-0.3.3
- echo | pecl install channel://pecl.php.net/yaml-2.0.2 - echo | pecl install channel://pecl.php.net/yaml-2.0.2
- git clone https://github.com/krakjoe/pthreads.git --depth=1 - git clone https://github.com/krakjoe/pthreads.git --depth=1
- cd pthreads - cd pthreads

View File

@ -186,40 +186,51 @@ namespace pocketmine {
$logger = new MainLogger(\pocketmine\DATA . "server.log"); $logger = new MainLogger(\pocketmine\DATA . "server.log");
$logger->registerStatic(); $logger->registerStatic();
if(!ini_get("date.timezone")){ do{
$timezone = ini_get("date.timezone");
if($timezone !== ""){
/*
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
* an incorrect timezone abbreviation in php.ini apparently.
*/
if(strpos($timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($timezone);
if($default_timezone !== false){
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
break;
}else{
//Bad php.ini value, try another method to detect timezone
$logger->warning("Timezone \"$timezone\" could not be parsed as a valid timezone from php.ini, falling back to auto-detection");
}
}else{
date_default_timezone_set($timezone);
break;
}
}
if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){ if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){
//Success! Timezone has already been set and validated in the if statement. //Success! Timezone has already been set and validated in the if statement.
//This here is just for redundancy just in case some program wants to read timezone data from the ini. //This here is just for redundancy just in case some program wants to read timezone data from the ini.
ini_set("date.timezone", $timezone); ini_set("date.timezone", $timezone);
}else{ break;
//If system timezone detection fails or timezone is an invalid value. }
if($response = Utils::getURL("http://ip-api.com/json")
if($response = Utils::getURL("http://ip-api.com/json") //If system timezone detection fails or timezone is an invalid value.
and $ip_geolocation_data = json_decode($response, true) and $ip_geolocation_data = json_decode($response, true)
and $ip_geolocation_data['status'] !== 'fail' and $ip_geolocation_data['status'] !== 'fail'
and date_default_timezone_set($ip_geolocation_data['timezone']) and date_default_timezone_set($ip_geolocation_data['timezone'])
){ ){
//Again, for redundancy. //Again, for redundancy.
ini_set("date.timezone", $ip_geolocation_data['timezone']); ini_set("date.timezone", $ip_geolocation_data['timezone']);
}else{ break;
}
ini_set("date.timezone", "UTC"); ini_set("date.timezone", "UTC");
date_default_timezone_set("UTC"); date_default_timezone_set("UTC");
$logger->warning("Timezone could not be automatically determined. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file."); $logger->warning("Timezone could not be automatically determined or was set to an invalid value. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file.");
} }while(false);
}
}else{
/*
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
* an incorrect timezone abbreviation in php.ini apparently.
*/
$timezone = ini_get("date.timezone");
if(strpos($timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($timezone);
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
}else{
date_default_timezone_set($timezone);
}
}
function detect_system_timezone(){ function detect_system_timezone(){
switch(Utils::getOS()){ switch(Utils::getOS()){