Merge commit 'da43ae82fe3b8839a4d153b0365f815cf9859d77'

# Conflicts:
#	resources/vanilla
#	src/utils/Config.php
#	src/utils/Timezone.php
#	src/utils/Utils.php
This commit is contained in:
Dylan K. Taylor 2020-01-31 20:02:39 +00:00
commit 3a68f5e3d0
4 changed files with 32 additions and 8 deletions

View File

@ -68,7 +68,7 @@ class Config{
public const ENUM = 5; // .txt, .list, .enum public const ENUM = 5; // .txt, .list, .enum
public const ENUMERATION = Config::ENUM; public const ENUMERATION = Config::ENUM;
/** @var array */ /** @var mixed[] */
private $config = []; private $config = [];
/** @var mixed[] */ /** @var mixed[] */
@ -104,9 +104,9 @@ class Config{
]; ];
/** /**
* @param string $file Path of the file to be loaded * @param string $file Path of the file to be loaded
* @param int $type Config type to load, -1 by default (detect) * @param int $type Config type to load, -1 by default (detect)
* @param array $default Array with the default values that will be written to the file if it did not exist * @param mixed[] $default Array with the default values that will be written to the file if it did not exist
*/ */
public function __construct(string $file, int $type = Config::DETECT, array $default = []){ public function __construct(string $file, int $type = Config::DETECT, array $default = []){
$this->load($file, $type, $default); $this->load($file, $type, $default);
@ -134,6 +134,8 @@ class Config{
} }
/** /**
* @param mixed[] $default
*
* @throws \InvalidArgumentException if config type could not be auto-detected * @throws \InvalidArgumentException if config type could not be auto-detected
* @throws \InvalidStateException if config type is invalid * @throws \InvalidStateException if config type is invalid
*/ */
@ -424,6 +426,9 @@ class Config{
} }
} }
/**
* @param mixed[] $v
*/
public function setAll(array $v) : void{ public function setAll(array $v) : void{
$this->config = $v; $this->config = $v;
$this->changed = true; $this->changed = true;
@ -451,10 +456,16 @@ class Config{
$this->changed = true; $this->changed = true;
} }
/**
* @return mixed[]
*/
public function getAll(bool $keys = false) : array{ public function getAll(bool $keys = false) : array{
return ($keys ? array_keys($this->config) : $this->config); return ($keys ? array_keys($this->config) : $this->config);
} }
/**
* @param mixed[] $defaults
*/
public function setDefaults(array $defaults) : void{ public function setDefaults(array $defaults) : void{
$this->fillDefaults($defaults, $this->config); $this->fillDefaults($defaults, $this->config);
} }

View File

@ -198,7 +198,7 @@ abstract class Terminal{
* Returns a string with colorized ANSI Escape codes for the current terminal * Returns a string with colorized ANSI Escape codes for the current terminal
* Note that this is platform-dependent and might produce different results depending on the terminal type and/or OS. * Note that this is platform-dependent and might produce different results depending on the terminal type and/or OS.
* *
* @param string|array $string * @param string|string[] $string
*/ */
public static function toANSI($string) : string{ public static function toANSI($string) : string{
if(!is_array($string)){ if(!is_array($string)){

View File

@ -68,6 +68,8 @@ abstract class TextFormat{
/** /**
* Splits the string by Format tokens * Splits the string by Format tokens
*
* @return string[]
*/ */
public static function tokenize(string $string) : array{ public static function tokenize(string $string) : array{
return preg_split("/(" . TextFormat::ESCAPE . "[0-9a-fk-or])/u", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); return preg_split("/(" . TextFormat::ESCAPE . "[0-9a-fk-or])/u", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
@ -99,7 +101,7 @@ abstract class TextFormat{
/** /**
* Returns an JSON-formatted string with colors/markup * Returns an JSON-formatted string with colors/markup
* *
* @param string|array $string * @param string|string[] $string
*/ */
public static function toJSON($string) : string{ public static function toJSON($string) : string{
if(!is_array($string)){ if(!is_array($string)){
@ -285,7 +287,7 @@ abstract class TextFormat{
/** /**
* Returns an HTML-formatted string with colors/markup * Returns an HTML-formatted string with colors/markup
* *
* @param string|array $string * @param string|string[] $string
*/ */
public static function toHTML($string) : string{ public static function toHTML($string) : string{
if(!is_array($string)){ if(!is_array($string)){

View File

@ -353,7 +353,7 @@ class Utils{
} }
/** /**
* @return array of claims * @return mixed[] array of claims
* *
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
@ -390,6 +390,11 @@ class Utils{
return -1; return -1;
} }
/**
* @param mixed[][] $trace
*
* @return string[]
*/
public static function printableTrace(array $trace, int $maxStringLength = 80) : array{ public static function printableTrace(array $trace, int $maxStringLength = 80) : array{
$messages = []; $messages = [];
for($i = 0; isset($trace[$i]); ++$i){ for($i = 0; isset($trace[$i]); ++$i){
@ -419,6 +424,9 @@ class Utils{
return $messages; return $messages;
} }
/**
* @return mixed[][]
*/
public static function currentTrace(int $skipFrames = 0) : array{ public static function currentTrace(int $skipFrames = 0) : array{
++$skipFrames; //omit this frame from trace, in addition to other skipped frames ++$skipFrames; //omit this frame from trace, in addition to other skipped frames
if(function_exists("xdebug_get_function_stack")){ if(function_exists("xdebug_get_function_stack")){
@ -433,6 +441,9 @@ class Utils{
return array_values($trace); return array_values($trace);
} }
/**
* @return string[]
*/
public static function printableCurrentTrace(int $skipFrames = 0) : array{ public static function printableCurrentTrace(int $skipFrames = 0) : array{
return self::printableTrace(self::currentTrace(++$skipFrames)); return self::printableTrace(self::currentTrace(++$skipFrames));
} }