Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60613bf311 | ||
|
|
2a583e525c | ||
|
|
04b0476b4d | ||
|
|
13fb22385b | ||
|
|
b7f594e683 |
@@ -132,7 +132,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
],
|
||||
'valid color' => [
|
||||
'rgb' => [10, 100, 200],
|
||||
'hsb' => [212, 95, 78],
|
||||
'hsb' => [212, 95, 78.0],
|
||||
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
||||
'hsl' => [211.6, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
@@ -327,13 +327,13 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_h
|
||||
* @param integer $input_s
|
||||
* @param integer $input_b
|
||||
* @param float $input_h
|
||||
* @param float $input_s
|
||||
* @param float $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsb2rgb(int $input_h, int $input_s, int $input_b, $expected): void
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
|
||||
@@ -3384,6 +3384,24 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// if this is a select query, db dbReturn, dbReturnRow, dbReturnArray too
|
||||
if (preg_match("/^(select|show|with) /i", $query)) {
|
||||
// TODO also tst dbReturnRow and dbReturnArray
|
||||
$res = $db->dbReturn($query);
|
||||
$this->assertEquals(
|
||||
$expected_rows,
|
||||
$db->dbGetNumRows()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_cols,
|
||||
$db->dbGetNumFields()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_col_names,
|
||||
$db->dbGetFieldNames()
|
||||
);
|
||||
}
|
||||
|
||||
// reset all data
|
||||
$db->dbExec("TRUNCATE table_with_primary_key");
|
||||
$db->dbExec("TRUNCATE table_without_primary_key");
|
||||
|
||||
@@ -57,6 +57,7 @@ print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . $color_class::r
|
||||
$rgb = [10, 20, 30];
|
||||
$hex = '#0a141e';
|
||||
$hsb = [210, 67, 12];
|
||||
$hsb_f = [210.5, 67.5, 12.5];
|
||||
$hsl = [210, 50, 7.8];
|
||||
print "S::COLOR rgb->hex: $rgb[0], $rgb[1], $rgb[2]: " . Colors::rgb2hex($rgb[0], $rgb[1], $rgb[2]) . "<br>";
|
||||
print "S::COLOR hex->rgb: $hex: " . DgS::printAr(Colors::hex2rgb($hex)) . "<br>";
|
||||
@@ -69,6 +70,8 @@ print "S::COLOR rgb->hsl: $rgb[0], $rgb[1], $rgb[2]: "
|
||||
// D(from hsb/hsl) Note that param 2 + 3 is always 0-100 divided
|
||||
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
||||
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
||||
print "S::COLOR hsb_f->rgb: $hsb_f[0], $hsb_f[1], $hsb_f[2]: "
|
||||
. DgS::printAr(Colors::hsb2rgb($hsb_f[0], $hsb_f[1], $hsb_f[2])) . "<br>";
|
||||
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
|
||||
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
|
||||
|
||||
@@ -76,6 +79,15 @@ $hsb = [0, 0, 5];
|
||||
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
||||
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
||||
|
||||
// Random text
|
||||
$h = rand(0, 359);
|
||||
$s = rand(15, 70);
|
||||
$b = 100;
|
||||
$l = 50;
|
||||
print "RANDOM IN: H: " . $h . ", S: " . $s . ", B/L: " . $b . "/" . $l . "<br>";
|
||||
print "RANDOM hsb->rgb: <pre>" . DgS::printAr(Colors::hsb2rgb($h, $s, $b)) . "</pre><br>";
|
||||
print "RANDOM hsl->rgb: <pre>" . DgS::printAr(Colors::hsl2rgb($h, $s, $l)) . "</pre><br>";
|
||||
|
||||
// TODO: run compare check input must match output
|
||||
|
||||
// error message
|
||||
|
||||
@@ -69,6 +69,9 @@ $db->dbSetEncoding('SJIS');
|
||||
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
|
||||
$db->dbResetEncoding();
|
||||
|
||||
$res = $db->dbReturn("SELECT * FROM max_test");
|
||||
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
|
||||
|
||||
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) {
|
||||
print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
|
||||
}
|
||||
@@ -277,7 +280,7 @@ print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got p
|
||||
// return Array Test
|
||||
$query = "SELECT type, sdate, integer FROM foobar";
|
||||
$data = $db->dbReturnArray($query, true);
|
||||
print "Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
|
||||
print "Rows: " . $db->dbGetNumRows() . ", Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
|
||||
|
||||
// trigger a warning
|
||||
print "<b>WARNING NEXT</b><br>";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "gullevek/corelibs",
|
||||
"description": "CoreLibs",
|
||||
"name": "gullevek/corelibs-dev",
|
||||
"version": "dev-master",
|
||||
"description": "CoreLibs: Development package",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
{
|
||||
|
||||
@@ -256,10 +256,11 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
|
||||
// where global tables are that are used by all schemas (eg queue tables for online, etc)
|
||||
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
|
||||
// debug settings, site lang, etc
|
||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location']);
|
||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag']);
|
||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang']);
|
||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']);
|
||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? 'en_utf8');
|
||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||
// paths
|
||||
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
|
||||
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
|
||||
@@ -274,8 +275,8 @@ define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||
/************ STYLE SHEETS / JS **********/
|
||||
define('ADMIN_STYLESHEET', 'edit.css');
|
||||
define('ADMIN_JAVASCRIPT', 'edit.js');
|
||||
define('STYLESHEET', 'frontend.css');
|
||||
define('JAVASCRIPT', 'frontend.js');
|
||||
define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
|
||||
define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
|
||||
|
||||
// anything optional
|
||||
/************* INTERNAL ******************/
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2008/08/01
|
||||
* SHORT DESCRIPTION:
|
||||
* URL redirect header
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ class Colors
|
||||
}
|
||||
$rgbArray = [];
|
||||
if (strlen($hexStr) == 6) {
|
||||
// If a proper hex code, convert using bitwise operation. No overhead... faster
|
||||
// If a proper hex code, convert using bitwise operation.
|
||||
// No overhead... faster
|
||||
$colorVal = hexdec($hexStr);
|
||||
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
|
||||
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
|
||||
@@ -135,13 +136,13 @@ class Colors
|
||||
* hsb2rgb does not clean convert back to hsb in a round trip
|
||||
* converts HSB/V to RGB values RGB is full INT
|
||||
* if HSB/V value is invalid, sets this value to 0
|
||||
* @param int $H hue 0-360 (int)
|
||||
* @param int $S saturation 0-100 (int)
|
||||
* @param int $V brightness/value 0-100 (int)
|
||||
* @param float $H hue 0-360 (int)
|
||||
* @param float $S saturation 0-100 (int)
|
||||
* @param float $V brightness/value 0-100 (int)
|
||||
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
|
||||
* false for input value error
|
||||
*/
|
||||
public static function hsb2rgb(int $H, int $S, int $V)
|
||||
public static function hsb2rgb(float $H, float $S, float $V)
|
||||
{
|
||||
// check that H is 0 to 359, 360 = 0
|
||||
// and S and V are 0 to 1
|
||||
@@ -270,12 +271,12 @@ class Colors
|
||||
/**
|
||||
* converts an HSL to RGB
|
||||
* if HSL value is invalid, set this value to 0
|
||||
* @param int|float $hue hue: 0-360 (degrees)
|
||||
* @param float $hue hue: 0-360 (degrees)
|
||||
* @param float $sat saturation: 0-100
|
||||
* @param float $lum luminance: 0-100
|
||||
* @return array<int,float|int>|bool red/blue/green 0-255 each
|
||||
*/
|
||||
public static function hsl2rgb($hue, float $sat, float $lum)
|
||||
public static function hsl2rgb(float $hue, float $sat, float $lum)
|
||||
{
|
||||
if (!is_numeric($hue)) {
|
||||
return false;
|
||||
@@ -289,7 +290,8 @@ class Colors
|
||||
if ($lum < 0 || $lum > 100) {
|
||||
return false;
|
||||
}
|
||||
$hue = (1 / 360) * $hue; // calc to internal convert value for hue
|
||||
// calc to internal convert value for hue
|
||||
$hue = (1 / 360) * $hue;
|
||||
// convert to internal 0-1 format
|
||||
$sat /= 100;
|
||||
$lum /= 100;
|
||||
|
||||
@@ -1786,9 +1786,12 @@ class IO
|
||||
// count the rows returned (if select)
|
||||
$this->cursor_ext[$query_hash]['num_rows'] =
|
||||
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
|
||||
// also set last return
|
||||
$this->num_rows = $this->cursor_ext[$query_hash]['num_rows'];
|
||||
// count the fields
|
||||
$this->cursor_ext[$query_hash]['num_fields'] =
|
||||
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
|
||||
$this->num_fields = $this->cursor_ext[$query_hash]['num_fields'];
|
||||
// set field names
|
||||
$this->cursor_ext[$query_hash]['field_names'] = [];
|
||||
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
|
||||
@@ -1798,6 +1801,7 @@ class IO
|
||||
$i
|
||||
);
|
||||
}
|
||||
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
|
||||
// reset first call vars
|
||||
$this->cursor_ext[$query_hash]['firstcall'] = 0;
|
||||
// reset the internal pos counter
|
||||
@@ -2870,7 +2874,7 @@ class IO
|
||||
*/
|
||||
public function dbGetInsertPKName(): string
|
||||
{
|
||||
return $this->insert_id_pk_name;
|
||||
return (string)$this->insert_id_pk_name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user