Fixed more Exceptions to be not Errors but Exceptions
DateTime, Session, FileWrite, Image, SymmetricEncryption phpunit tests updated, run checks added
This commit is contained in:
@@ -309,41 +309,49 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
'2021-12-12',
|
'2021-12-12',
|
||||||
-1,
|
-1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'dates equal' => [
|
'dates equal' => [
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
0,
|
0,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'second date smaller' => [
|
'second date smaller' => [
|
||||||
'2021-12-12',
|
'2021-12-12',
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
1
|
1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'dates equal with different time' => [
|
'dates equal with different time' => [
|
||||||
'2020-12-12 12:12:12',
|
'2020-12-12 12:12:12',
|
||||||
'2020-12-12 13:13:13',
|
'2020-12-12 13:13:13',
|
||||||
0,
|
0,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'invalid dates --' => [
|
'invalid dates --' => [
|
||||||
'--',
|
'--',
|
||||||
'--',
|
'--',
|
||||||
false
|
false,
|
||||||
|
'UnexpectedValueException',
|
||||||
],
|
],
|
||||||
'empty dates' => [
|
'empty dates' => [
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
false
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
'invalid dates' => [
|
'invalid dates' => [
|
||||||
'not a date',
|
'not a date',
|
||||||
'not a date either',
|
'not a date either',
|
||||||
false,
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
'out of bound dates' => [
|
'out of bound dates' => [
|
||||||
'1900-1-1',
|
'1900-1-1',
|
||||||
'9999-12-31',
|
'9999-12-31',
|
||||||
-1
|
-1,
|
||||||
|
null,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -355,51 +363,61 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
'2021-12-12',
|
'2021-12-12',
|
||||||
-1,
|
-1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'dates equal no timestamp' => [
|
'dates equal no timestamp' => [
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
0,
|
0,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'second date smaller no timestamp' => [
|
'second date smaller no timestamp' => [
|
||||||
'2021-12-12',
|
'2021-12-12',
|
||||||
'2020-12-12',
|
'2020-12-12',
|
||||||
1
|
1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'date equal first time smaller' => [
|
'date equal first time smaller' => [
|
||||||
'2020-12-12 12:12:12',
|
'2020-12-12 12:12:12',
|
||||||
'2020-12-12 13:13:13',
|
'2020-12-12 13:13:13',
|
||||||
-1,
|
-1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'date equal time equal' => [
|
'date equal time equal' => [
|
||||||
'2020-12-12 12:12:12',
|
'2020-12-12 12:12:12',
|
||||||
'2020-12-12 12:12:12',
|
'2020-12-12 12:12:12',
|
||||||
0,
|
0,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'date equal second time smaller' => [
|
'date equal second time smaller' => [
|
||||||
'2020-12-12 13:13:13',
|
'2020-12-12 13:13:13',
|
||||||
'2020-12-12 12:12:12',
|
'2020-12-12 12:12:12',
|
||||||
1,
|
1,
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'valid date invalid time' => [
|
'valid date invalid time' => [
|
||||||
'2020-12-12 13:99:13',
|
'2020-12-12 13:99:13',
|
||||||
'2020-12-12 12:12:99',
|
'2020-12-12 12:12:99',
|
||||||
false,
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
'invalid datetimes --' => [
|
'invalid datetimes --' => [
|
||||||
'--',
|
'--',
|
||||||
'--',
|
'--',
|
||||||
false,
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
'empty datetimess' => [
|
'empty datetimess' => [
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
false,
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
'invalid datetimes' => [
|
'invalid datetimes' => [
|
||||||
'not a date',
|
'not a date',
|
||||||
'not a date either',
|
'not a date either',
|
||||||
false,
|
false,
|
||||||
|
'UnexpectedValueException'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -616,8 +634,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
* @param int|bool $expected
|
* @param int|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
public function testCompareDate(string $input_a, string $input_b, int|bool $expected, ?string $exception): void
|
||||||
{
|
{
|
||||||
|
if ($expected === false) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
}
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
||||||
@@ -636,8 +657,11 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
* @param int|bool $expected
|
* @param int|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
public function testCompareDateTime(string $input_a, string $input_b, int|bool $expected, ?string $exception): void
|
||||||
{
|
{
|
||||||
|
if ($expected === false) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
}
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
// setSessionName: true/false,
|
// setSessionName: true/false,
|
||||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||||
// getSessionId: string or false
|
// getSessionId: string or false
|
||||||
// 3: exepcted name (session)
|
// 3: exepcted name (session)]
|
||||||
// 4: expected error string
|
// 4: Exception thrown on error
|
||||||
|
// 5: expected error string
|
||||||
return [
|
return [
|
||||||
'session parameter' => [
|
'session parameter' => [
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
@@ -44,7 +45,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
''
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
'session globals' => [
|
'session globals' => [
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
@@ -57,7 +59,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
''
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
'session name default' => [
|
'session name default' => [
|
||||||
'',
|
'',
|
||||||
@@ -70,7 +73,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
''
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
// error checks
|
// error checks
|
||||||
// 1: we are in cli
|
// 1: we are in cli
|
||||||
@@ -85,6 +89,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
'[SESSION] No sessions in php cli'
|
'[SESSION] No sessions in php cli'
|
||||||
],
|
],
|
||||||
// 2: session disabled
|
// 2: session disabled
|
||||||
@@ -99,6 +104,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
'[SESSION] Sessions are disabled'
|
'[SESSION] Sessions are disabled'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: string
|
// 3: invalid session name: string
|
||||||
@@ -113,6 +119,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: only numbers
|
// 3: invalid session name: only numbers
|
||||||
@@ -127,6 +134,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
'[SESSION] Invalid session name: 123'
|
'[SESSION] Invalid session name: 123'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: invalid name short
|
// 3: invalid session name: invalid name short
|
||||||
@@ -143,6 +151,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
'[SESSION] Failed to activate session'
|
'[SESSION] Failed to activate session'
|
||||||
],
|
],
|
||||||
// 5: get session id return false
|
// 5: get session id return false
|
||||||
@@ -157,6 +166,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => false
|
'getSessionId' => false
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
'[SESSION] getSessionId did not return a session id'
|
'[SESSION] getSessionId did not return a session id'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -173,6 +183,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array<mixed> $mock_data
|
* @param array<mixed> $mock_data
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
|
* @param string|null $exception
|
||||||
* @param string $expected_error
|
* @param string $expected_error
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -181,6 +192,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
string $type,
|
string $type,
|
||||||
array $mock_data,
|
array $mock_data,
|
||||||
string $expected,
|
string $expected,
|
||||||
|
?string $exception,
|
||||||
string $expected_error
|
string $expected_error
|
||||||
): void {
|
): void {
|
||||||
// override expected
|
// override expected
|
||||||
@@ -224,6 +236,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
// regex for session id
|
// regex for session id
|
||||||
$ression_id_regex = "/^\w+$/";
|
$ression_id_regex = "/^\w+$/";
|
||||||
|
|
||||||
|
if ($exception !== null) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
}
|
||||||
|
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
unset($GLOBALS['SET_SESSION_NAME']);
|
||||||
$session_id = '';
|
$session_id = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
@@ -253,13 +269,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
$expected,
|
$expected,
|
||||||
$session_mock->getSessionName()
|
$session_mock->getSessionName()
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
// false checks
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected_error,
|
|
||||||
$session_mock->getErrorStr(),
|
|
||||||
'error assert'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,13 @@ foreach ($images as $image) {
|
|||||||
echo "<hr>";
|
echo "<hr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// errros
|
||||||
|
try {
|
||||||
|
Image::createThumbnailSimple('', $thumb_width, 0, $cache_folder, $web_folder);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
print "Message:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -105,49 +105,48 @@ class DateTime
|
|||||||
bool $show_micro = true
|
bool $show_micro = true
|
||||||
): string {
|
): string {
|
||||||
// check if the timestamp has any h/m/s/ms inside, if yes skip
|
// check if the timestamp has any h/m/s/ms inside, if yes skip
|
||||||
if (!preg_match("/(h|m|s|ms)/", (string)$timestamp)) {
|
if (preg_match("/(h|m|s|ms)/", (string)$timestamp)) {
|
||||||
list($timestamp, $ms) = array_pad(explode('.', (string)round((float)$timestamp, 4)), 2, null);
|
return (string)$timestamp;
|
||||||
// if negative remember
|
}
|
||||||
$negative = false;
|
list($timestamp, $ms) = array_pad(explode('.', (string)round((float)$timestamp, 4)), 2, null);
|
||||||
if ((int)$timestamp < 0) {
|
// if negative remember
|
||||||
$negative = true;
|
$negative = false;
|
||||||
}
|
if ((int)$timestamp < 0) {
|
||||||
$timestamp = abs((float)$timestamp);
|
$negative = true;
|
||||||
$timegroups = [86400, 3600, 60, 1];
|
}
|
||||||
$labels = ['d', 'h', 'm', 's'];
|
$timestamp = abs((float)$timestamp);
|
||||||
$time_string = '';
|
$timegroups = [86400, 3600, 60, 1];
|
||||||
// if timestamp is zero, return zero string
|
$labels = ['d', 'h', 'm', 's'];
|
||||||
if ($timestamp == 0) {
|
$time_string = '';
|
||||||
$time_string = '0s';
|
// if timestamp is zero, return zero string
|
||||||
} else {
|
if ($timestamp == 0) {
|
||||||
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) {
|
$time_string = '0s';
|
||||||
$output = floor((float)$timestamp / $timegroups[$i]);
|
|
||||||
$timestamp = (float)$timestamp % $timegroups[$i];
|
|
||||||
// output has days|hours|min|sec
|
|
||||||
if ($output || $time_string) {
|
|
||||||
$time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// only add ms if we have an ms value
|
|
||||||
if ($ms !== null) {
|
|
||||||
// if we have ms and it has leading zeros, remove them, but only if it is nut just 0
|
|
||||||
$ms = preg_replace("/^0+(\d+)$/", '${1}', $ms);
|
|
||||||
if (!is_string($ms) || empty($ms)) {
|
|
||||||
$ms = '0';
|
|
||||||
}
|
|
||||||
// add ms if there
|
|
||||||
if ($show_micro) {
|
|
||||||
$time_string .= ' ' . $ms . 'ms';
|
|
||||||
} elseif (!$time_string) {
|
|
||||||
$time_string .= $ms . 'ms';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($negative) {
|
|
||||||
$time_string = '-' . $time_string;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$time_string = $timestamp;
|
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) {
|
||||||
|
$output = floor((float)$timestamp / $timegroups[$i]);
|
||||||
|
$timestamp = (float)$timestamp % $timegroups[$i];
|
||||||
|
// output has days|hours|min|sec
|
||||||
|
if ($output || $time_string) {
|
||||||
|
$time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// only add ms if we have an ms value
|
||||||
|
if ($ms !== null) {
|
||||||
|
// if we have ms and it has leading zeros, remove them, but only if it is nut just 0
|
||||||
|
$ms = preg_replace("/^0+(\d+)$/", '${1}', $ms);
|
||||||
|
if (!is_string($ms) || empty($ms)) {
|
||||||
|
$ms = '0';
|
||||||
|
}
|
||||||
|
// add ms if there
|
||||||
|
if ($show_micro) {
|
||||||
|
$time_string .= ' ' . $ms . 'ms';
|
||||||
|
} elseif (!$time_string) {
|
||||||
|
$time_string .= $ms . 'ms';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($negative) {
|
||||||
|
$time_string = '-' . $time_string;
|
||||||
}
|
}
|
||||||
return (string)$time_string;
|
return (string)$time_string;
|
||||||
}
|
}
|
||||||
@@ -162,37 +161,36 @@ class DateTime
|
|||||||
public static function stringToTime(string|int|float $timestring): string|int|float
|
public static function stringToTime(string|int|float $timestring): string|int|float
|
||||||
{
|
{
|
||||||
$timestamp = 0;
|
$timestamp = 0;
|
||||||
if (preg_match("/(d|h|m|s|ms)/", (string)$timestring)) {
|
if (!preg_match("/(d|h|m|s|ms)/", (string)$timestring)) {
|
||||||
$timestring = (string)$timestring;
|
|
||||||
// pos for preg match read + multiply factor
|
|
||||||
$timegroups = [2 => 86400, 4 => 3600, 6 => 60, 8 => 1];
|
|
||||||
$matches = [];
|
|
||||||
// if start with -, strip and set negative
|
|
||||||
$negative = false;
|
|
||||||
if (preg_match("/^-/", $timestring)) {
|
|
||||||
$negative = true;
|
|
||||||
$timestring = substr($timestring, 1);
|
|
||||||
}
|
|
||||||
// preg match: 0: full string
|
|
||||||
// 2, 4, 6, 8 are the to need values
|
|
||||||
preg_match("/^((\d+)d ?)?((\d+)h ?)?((\d+)m ?)?((\d+)s ?)?((\d+)ms)?$/", $timestring, $matches);
|
|
||||||
// multiply the returned matches and sum them up. the last one (ms) is added with .
|
|
||||||
foreach ($timegroups as $i => $time_multiply) {
|
|
||||||
if (isset($matches[$i]) && is_numeric($matches[$i])) {
|
|
||||||
$timestamp += (float)$matches[$i] * $time_multiply;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($matches[10]) && is_numeric($matches[10])) {
|
|
||||||
$timestamp .= '.' . $matches[10];
|
|
||||||
}
|
|
||||||
if ($negative) {
|
|
||||||
// cast to flaot so we can do a negative multiplication
|
|
||||||
$timestamp = (float)$timestamp * -1;
|
|
||||||
}
|
|
||||||
return $timestamp;
|
|
||||||
} else {
|
|
||||||
return $timestring;
|
return $timestring;
|
||||||
}
|
}
|
||||||
|
$timestring = (string)$timestring;
|
||||||
|
// pos for preg match read + multiply factor
|
||||||
|
$timegroups = [2 => 86400, 4 => 3600, 6 => 60, 8 => 1];
|
||||||
|
$matches = [];
|
||||||
|
// if start with -, strip and set negative
|
||||||
|
$negative = false;
|
||||||
|
if (preg_match("/^-/", $timestring)) {
|
||||||
|
$negative = true;
|
||||||
|
$timestring = substr($timestring, 1);
|
||||||
|
}
|
||||||
|
// preg match: 0: full string
|
||||||
|
// 2, 4, 6, 8 are the to need values
|
||||||
|
preg_match("/^((\d+)d ?)?((\d+)h ?)?((\d+)m ?)?((\d+)s ?)?((\d+)ms)?$/", $timestring, $matches);
|
||||||
|
// multiply the returned matches and sum them up. the last one (ms) is added with .
|
||||||
|
foreach ($timegroups as $i => $time_multiply) {
|
||||||
|
if (isset($matches[$i]) && is_numeric($matches[$i])) {
|
||||||
|
$timestamp += (float)$matches[$i] * $time_multiply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($matches[10]) && is_numeric($matches[10])) {
|
||||||
|
$timestamp .= '.' . $matches[10];
|
||||||
|
}
|
||||||
|
if ($negative) {
|
||||||
|
// cast to flaot so we can do a negative multiplication
|
||||||
|
$timestamp = (float)$timestamp * -1;
|
||||||
|
}
|
||||||
|
return $timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,21 +321,21 @@ class DateTime
|
|||||||
*
|
*
|
||||||
* @param string $start_date start date string in YYYY-MM-DD
|
* @param string $start_date start date string in YYYY-MM-DD
|
||||||
* @param string $end_date end date string in YYYY-MM-DD
|
* @param string $end_date end date string in YYYY-MM-DD
|
||||||
* @return int|bool false on error
|
* @return int int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
* or int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
* @throws \UnexpectedValueException On empty start/end values
|
||||||
*/
|
*/
|
||||||
public static function compareDate(string $start_date, string $end_date): int|bool
|
public static function compareDate(string $start_date, string $end_date): int|bool
|
||||||
{
|
{
|
||||||
// pre check for empty or wrong
|
// pre check for empty or wrong
|
||||||
if ($start_date == '--' || $end_date == '--' || !$start_date || !$end_date) {
|
if ($start_date == '--' || $end_date == '--' || empty($start_date) || empty($end_date)) {
|
||||||
return false;
|
throw new \UnexpectedValueException('Start or End date not set or are just "--"');
|
||||||
}
|
}
|
||||||
// if invalid, quit
|
// if invalid, quit
|
||||||
if (($start_timestamp = strtotime($start_date)) === false) {
|
if (($start_timestamp = strtotime($start_date)) === false) {
|
||||||
return false;
|
throw new \UnexpectedValueException("Error parsing start date through strtotime()");
|
||||||
}
|
}
|
||||||
if (($end_timestamp = strtotime($end_date)) === false) {
|
if (($end_timestamp = strtotime($end_date)) === false) {
|
||||||
return false;
|
throw new \UnexpectedValueException("Error parsing end date through strtotime()");
|
||||||
}
|
}
|
||||||
// convert anything to Y-m-d and then to timestamp
|
// convert anything to Y-m-d and then to timestamp
|
||||||
// this is to remove any time parts
|
// this is to remove any time parts
|
||||||
@@ -350,8 +348,6 @@ class DateTime
|
|||||||
return 0;
|
return 0;
|
||||||
} elseif ($start_timestamp > $end_timestamp) {
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,21 +362,21 @@ class DateTime
|
|||||||
*
|
*
|
||||||
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
|
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
|
||||||
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
|
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
|
||||||
* @return int|bool false for error
|
* @return int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
* or -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
* @throws \UnexpectedValueException On empty start/end values
|
||||||
*/
|
*/
|
||||||
public static function compareDateTime(string $start_datetime, string $end_datetime): int|bool
|
public static function compareDateTime(string $start_datetime, string $end_datetime): int|bool
|
||||||
{
|
{
|
||||||
// pre check for empty or wrong
|
// pre check for empty or wrong
|
||||||
if ($start_datetime == '--' || $end_datetime == '--' || !$start_datetime || !$end_datetime) {
|
if ($start_datetime == '--' || $end_datetime == '--' || empty($start_datetime) || empty($end_datetime)) {
|
||||||
return false;
|
throw new \UnexpectedValueException('Start or end timestamp not set or are just "--"');
|
||||||
}
|
}
|
||||||
// quit if invalid timestamp
|
// quit if invalid timestamp
|
||||||
if (($start_timestamp = strtotime($start_datetime)) === false) {
|
if (($start_timestamp = strtotime($start_datetime)) === false) {
|
||||||
return false;
|
throw new \UnexpectedValueException("Error parsing start timestamp through strtotime()");
|
||||||
}
|
}
|
||||||
if (($end_timestamp = strtotime($end_datetime)) === false) {
|
if (($end_timestamp = strtotime($end_datetime)) === false) {
|
||||||
return false;
|
throw new \UnexpectedValueException("Error parsing end timestamp through strtotime()");
|
||||||
}
|
}
|
||||||
// compare, or return false
|
// compare, or return false
|
||||||
if ($start_timestamp < $end_timestamp) {
|
if ($start_timestamp < $end_timestamp) {
|
||||||
@@ -389,8 +385,6 @@ class DateTime
|
|||||||
return 0;
|
return 0;
|
||||||
} elseif ($start_timestamp > $end_timestamp) {
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ namespace CoreLibs\Create;
|
|||||||
|
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
/** @var string list for errors */
|
|
||||||
private string $session_intern_error_str = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init a session, if array is empty or array does not have session_name set
|
* init a session, if array is empty or array does not have session_name set
|
||||||
* then no auto init is run
|
* then no auto init is run
|
||||||
@@ -71,17 +68,6 @@ class Session
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return set error string, empty if none set
|
|
||||||
* Error strings are only set in the startSession method
|
|
||||||
*
|
|
||||||
* @return string Last error string
|
|
||||||
*/
|
|
||||||
public function getErrorStr(): string
|
|
||||||
{
|
|
||||||
return $this->session_intern_error_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if session name is valid
|
* check if session name is valid
|
||||||
*
|
*
|
||||||
@@ -120,13 +106,11 @@ class Session
|
|||||||
{
|
{
|
||||||
// we can't start sessions on command line
|
// we can't start sessions on command line
|
||||||
if ($this->checkCliStatus()) {
|
if ($this->checkCliStatus()) {
|
||||||
$this->session_intern_error_str = '[SESSION] No sessions in php cli';
|
throw new \RuntimeException('[SESSION] No sessions in php cli');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// if session are OFF
|
// if session are OFF
|
||||||
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
|
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
|
||||||
$this->session_intern_error_str = '[SESSION] Sessions are disabled';
|
throw new \RuntimeException('[SESSION] Sessions are disabled');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// session_status
|
// session_status
|
||||||
// initial the session if there is no session running already
|
// initial the session if there is no session running already
|
||||||
@@ -139,8 +123,7 @@ class Session
|
|||||||
if (!empty($session_name)) {
|
if (!empty($session_name)) {
|
||||||
// invalid session name, abort
|
// invalid session name, abort
|
||||||
if (!$this->checkValidSessionName($session_name)) {
|
if (!$this->checkValidSessionName($session_name)) {
|
||||||
$this->session_intern_error_str = '[SESSION] Invalid session name: ' . $session_name;
|
throw new \UnexpectedValueException('[SESSION] Invalid session name: ' . $session_name);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$this->setSessionName($session_name);
|
$this->setSessionName($session_name);
|
||||||
}
|
}
|
||||||
@@ -149,11 +132,10 @@ class Session
|
|||||||
}
|
}
|
||||||
// if we still have no active session
|
// if we still have no active session
|
||||||
if (!$this->checkActiveSession()) {
|
if (!$this->checkActiveSession()) {
|
||||||
$this->session_intern_error_str = '[SESSION] Failed to activate session';
|
throw new \RuntimeException('[SESSION] Failed to activate session');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (false === ($session_id = $this->getSessionId())) {
|
if (false === ($session_id = $this->getSessionId())) {
|
||||||
$this->session_intern_error_str = '[SESSION] getSessionId did not return a session id';
|
throw new \UnexpectedValueException('[SESSION] getSessionId did not return a session id');
|
||||||
}
|
}
|
||||||
return $session_id;
|
return $session_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class FileWriter
|
|||||||
*
|
*
|
||||||
* @param string $string string to write to the file
|
* @param string $string string to write to the file
|
||||||
* @param boolean $enter default true, if set adds a linebreak \n at the end
|
* @param boolean $enter default true, if set adds a linebreak \n at the end
|
||||||
* @return bool True for log written, false for not wirrten
|
* @return bool True for log written, false for not written
|
||||||
*/
|
*/
|
||||||
public static function fdebug(string $string, bool $enter = true): bool
|
public static function fdebug(string $string, bool $enter = true): bool
|
||||||
{
|
{
|
||||||
@@ -75,7 +75,7 @@ class FileWriter
|
|||||||
empty(self::$debug_folder) &&
|
empty(self::$debug_folder) &&
|
||||||
defined('BASE') && defined('LOG')
|
defined('BASE') && defined('LOG')
|
||||||
) {
|
) {
|
||||||
/** @deprecated Do not use this anymore, define path with fsetFolder */
|
/** @deprecated Do not use this anymore, define path with festFolder */
|
||||||
trigger_error(
|
trigger_error(
|
||||||
'fsetFolder must be set first. Setting via LOG_FILE_ID and LOG constants is deprecated',
|
'fsetFolder must be set first. Setting via LOG_FILE_ID and LOG constants is deprecated',
|
||||||
E_USER_DEPRECATED
|
E_USER_DEPRECATED
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace CoreLibs\Output;
|
namespace CoreLibs\Output;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class Image
|
class Image
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +25,8 @@ class Image
|
|||||||
* if empty ROOT is choosen
|
* if empty ROOT is choosen
|
||||||
* @param string $cache_source cache path, if not given TMP is used
|
* @param string $cache_source cache path, if not given TMP is used
|
||||||
* @param bool $clear_cache if set to true, will create thumb all the tame
|
* @param bool $clear_cache if set to true, will create thumb all the tame
|
||||||
* @return string|false thumbnail name, or false for error
|
* @return string thumbnail name
|
||||||
|
* @throws \RuntimeException no ImageMagick convert command found
|
||||||
*/
|
*/
|
||||||
public static function createThumbnail(
|
public static function createThumbnail(
|
||||||
string $pic,
|
string $pic,
|
||||||
@@ -33,7 +36,7 @@ class Image
|
|||||||
string $path = '',
|
string $path = '',
|
||||||
string $cache_source = '',
|
string $cache_source = '',
|
||||||
bool $clear_cache = false
|
bool $clear_cache = false
|
||||||
): string|false {
|
): string {
|
||||||
// get image type flags
|
// get image type flags
|
||||||
$image_types = [
|
$image_types = [
|
||||||
0 => 'UNKOWN-IMAGE',
|
0 => 'UNKOWN-IMAGE',
|
||||||
@@ -41,7 +44,7 @@ class Image
|
|||||||
2 => 'jpg',
|
2 => 'jpg',
|
||||||
3 => 'png'
|
3 => 'png'
|
||||||
];
|
];
|
||||||
$return_data = false;
|
$return_data = '';
|
||||||
$CONVERT = '';
|
$CONVERT = '';
|
||||||
// if CONVERT is not defined, abort
|
// if CONVERT is not defined, abort
|
||||||
/** @phan-suppress-next-line PhanUndeclaredConstant */
|
/** @phan-suppress-next-line PhanUndeclaredConstant */
|
||||||
@@ -49,7 +52,7 @@ class Image
|
|||||||
/** @phan-suppress-next-line PhanUndeclaredConstant */
|
/** @phan-suppress-next-line PhanUndeclaredConstant */
|
||||||
$CONVERT = CONVERT;
|
$CONVERT = CONVERT;
|
||||||
} else {
|
} else {
|
||||||
return $return_data;
|
throw new \RuntimeException('CONVERT set binary is not executable or CONVERT is not defined');
|
||||||
}
|
}
|
||||||
if (!empty($cache_source)) {
|
if (!empty($cache_source)) {
|
||||||
$tmp_src = $cache_source;
|
$tmp_src = $cache_source;
|
||||||
@@ -69,72 +72,7 @@ class Image
|
|||||||
$pic = $tmp[(count($tmp) - 1)];
|
$pic = $tmp[(count($tmp) - 1)];
|
||||||
}
|
}
|
||||||
// does this picture exist and is it a picture
|
// does this picture exist and is it a picture
|
||||||
if (file_exists($filename) && is_file($filename)) {
|
if (!file_exists($filename) || !is_file($filename)) {
|
||||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
|
||||||
$convert_prefix = '';
|
|
||||||
$create_file = false;
|
|
||||||
$delete_filename = '';
|
|
||||||
// check if we can skip the PDF creation: if we have size, if do not have type, we assume type png
|
|
||||||
if (!$type) {
|
|
||||||
$check_thumb = $tmp_src . 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[3];
|
|
||||||
if (!is_file($check_thumb)) {
|
|
||||||
$create_file = true;
|
|
||||||
} else {
|
|
||||||
$type = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if type is not in the list, but returns as PDF, we need to convert to JPEG before
|
|
||||||
if (!$type) {
|
|
||||||
$output = [];
|
|
||||||
$return = null;
|
|
||||||
// is this a PDF, if no, return from here with nothing
|
|
||||||
$convert_prefix = 'png:';
|
|
||||||
# TEMP convert to PNG, we then override the file name
|
|
||||||
$convert_string = $CONVERT . ' ' . $filename . ' ' . $convert_prefix . $filename . '_TEMP';
|
|
||||||
$status = exec($convert_string, $output, $return);
|
|
||||||
$filename .= '_TEMP';
|
|
||||||
// for delete, in case we need to glob
|
|
||||||
$delete_filename = $filename;
|
|
||||||
// find file, if we can't find base name, use -0 as the first one (ignore other pages in multiple ones)
|
|
||||||
if (!is_file($filename)) {
|
|
||||||
$filename .= '-0';
|
|
||||||
}
|
|
||||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
|
||||||
}
|
|
||||||
// if no size given, set size to original
|
|
||||||
if (!$size_x || $size_x < 1) {
|
|
||||||
$size_x = $width;
|
|
||||||
}
|
|
||||||
if (!$size_y || $size_y < 1) {
|
|
||||||
$size_y = $height;
|
|
||||||
}
|
|
||||||
$thumb = 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[$type];
|
|
||||||
$thumbnail = $tmp_src . $thumb;
|
|
||||||
// check if we already have this picture converted
|
|
||||||
if (!is_file($thumbnail) || $clear_cache == true) {
|
|
||||||
// convert the picture
|
|
||||||
if ($width > $size_x) {
|
|
||||||
$convert_string = $CONVERT . ' -geometry ' . $size_x . 'x ' . $filename . ' ' . $thumbnail;
|
|
||||||
$status = exec($convert_string, $output, $return);
|
|
||||||
// get the size of the converted data, if converted
|
|
||||||
if (is_file($thumbnail)) {
|
|
||||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [0, 0, 0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($height > $size_y) {
|
|
||||||
$convert_string = $CONVERT . ' -geometry x' . $size_y . ' ' . $filename . ' ' . $thumbnail;
|
|
||||||
$status = exec($convert_string, $output, $return);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!is_file($thumbnail)) {
|
|
||||||
copy($filename, $thumbnail);
|
|
||||||
}
|
|
||||||
$return_data = $thumb;
|
|
||||||
// if we have a delete filename, delete here with glob
|
|
||||||
if ($delete_filename) {
|
|
||||||
array_map('unlink', glob($delete_filename . '*') ?: []);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!empty($dummy) && strstr($dummy, '/') === false) {
|
if (!empty($dummy) && strstr($dummy, '/') === false) {
|
||||||
// check if we have the "dummy" image flag set
|
// check if we have the "dummy" image flag set
|
||||||
$filename = PICTURES . ICONS . strtoupper($dummy) . ".png";
|
$filename = PICTURES . ICONS . strtoupper($dummy) . ".png";
|
||||||
@@ -142,11 +80,77 @@ class Image
|
|||||||
if (!empty($dummy) && file_exists($filename) && is_file($filename)) {
|
if (!empty($dummy) && file_exists($filename) && is_file($filename)) {
|
||||||
$return_data = $filename;
|
$return_data = $filename;
|
||||||
} else {
|
} else {
|
||||||
$return_data = false;
|
throw new \Exception('Could not set dummy return file: ' . $dummy . ' in ' . $filename);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$filename = $dummy;
|
$return_data = $dummy;
|
||||||
}
|
}
|
||||||
|
return $return_data;
|
||||||
|
}
|
||||||
|
// resize image
|
||||||
|
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||||
|
$convert_prefix = '';
|
||||||
|
$create_file = false;
|
||||||
|
$delete_filename = '';
|
||||||
|
// check if we can skip the PDF creation: if we have size, if do not have type, we assume type png
|
||||||
|
if (!$type) {
|
||||||
|
$check_thumb = $tmp_src . 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[3];
|
||||||
|
if (!is_file($check_thumb)) {
|
||||||
|
$create_file = true;
|
||||||
|
} else {
|
||||||
|
$type = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if type is not in the list, but returns as PDF, we need to convert to JPEG before
|
||||||
|
if (!$type) {
|
||||||
|
$output = [];
|
||||||
|
$return = null;
|
||||||
|
// is this a PDF, if no, return from here with nothing
|
||||||
|
$convert_prefix = 'png:';
|
||||||
|
# TEMP convert to PNG, we then override the file name
|
||||||
|
$convert_string = $CONVERT . ' ' . $filename . ' ' . $convert_prefix . $filename . '_TEMP';
|
||||||
|
$status = exec($convert_string, $output, $return);
|
||||||
|
$filename .= '_TEMP';
|
||||||
|
// for delete, in case we need to glob
|
||||||
|
$delete_filename = $filename;
|
||||||
|
// find file, if we can't find base name, use -0 as the first one (ignore other pages in multiple ones)
|
||||||
|
if (!is_file($filename)) {
|
||||||
|
$filename .= '-0';
|
||||||
|
}
|
||||||
|
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||||
|
}
|
||||||
|
// if no size given, set size to original
|
||||||
|
if (!$size_x || $size_x < 1) {
|
||||||
|
$size_x = $width;
|
||||||
|
}
|
||||||
|
if (!$size_y || $size_y < 1) {
|
||||||
|
$size_y = $height;
|
||||||
|
}
|
||||||
|
$thumb = 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[$type];
|
||||||
|
$thumbnail = $tmp_src . $thumb;
|
||||||
|
// check if we already have this picture converted
|
||||||
|
if (!is_file($thumbnail) || $clear_cache == true) {
|
||||||
|
// convert the picture
|
||||||
|
if ($width > $size_x) {
|
||||||
|
$convert_string = $CONVERT . ' -geometry ' . $size_x . 'x ' . $filename . ' ' . $thumbnail;
|
||||||
|
$status = exec($convert_string, $output, $return);
|
||||||
|
// get the size of the converted data, if converted
|
||||||
|
if (is_file($thumbnail)) {
|
||||||
|
[$width, $height, $type] = getimagesize($thumbnail) ?: [0, 0, 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($height > $size_y) {
|
||||||
|
$convert_string = $CONVERT . ' -geometry x' . $size_y . ' ' . $filename . ' ' . $thumbnail;
|
||||||
|
$status = exec($convert_string, $output, $return);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_file($thumbnail)) {
|
||||||
|
copy($filename, $thumbnail);
|
||||||
|
}
|
||||||
|
$return_data = $thumb;
|
||||||
|
// if we have a delete filename, delete here with glob
|
||||||
|
if ($delete_filename) {
|
||||||
|
array_map('unlink', glob($delete_filename . '*') ?: []);
|
||||||
}
|
}
|
||||||
return $return_data;
|
return $return_data;
|
||||||
}
|
}
|
||||||
@@ -173,7 +177,9 @@ class Image
|
|||||||
* set to false to not use (default true)
|
* set to false to not use (default true)
|
||||||
* to use quick but less nice version
|
* to use quick but less nice version
|
||||||
* @param int $jpeg_quality default 80, set image quality for jpeg only
|
* @param int $jpeg_quality default 80, set image quality for jpeg only
|
||||||
* @return string|false thumbnail with path
|
* @return string thumbnail with path
|
||||||
|
* @throws \UnexpectedValueException input values for filename or cache_folder are wrong
|
||||||
|
* @throws \RuntimeException convert (gd) failed
|
||||||
*/
|
*/
|
||||||
public static function createThumbnailSimple(
|
public static function createThumbnailSimple(
|
||||||
string $filename,
|
string $filename,
|
||||||
@@ -185,8 +191,9 @@ class Image
|
|||||||
bool $use_cache = true,
|
bool $use_cache = true,
|
||||||
bool $high_quality = true,
|
bool $high_quality = true,
|
||||||
int $jpeg_quality = 80
|
int $jpeg_quality = 80
|
||||||
): string|false {
|
): string {
|
||||||
$thumbnail = false;
|
$thumbnail = false;
|
||||||
|
$exception_message = 'Could not create thumbnail';
|
||||||
// $this->debug('IMAGE PREPARE', "FILE: $filename (exists "
|
// $this->debug('IMAGE PREPARE', "FILE: $filename (exists "
|
||||||
// .(string)file_exists($filename)."), WIDTH: $thumb_width, HEIGHT: $thumb_height");
|
// .(string)file_exists($filename)."), WIDTH: $thumb_width, HEIGHT: $thumb_height");
|
||||||
if (
|
if (
|
||||||
@@ -210,12 +217,17 @@ class Image
|
|||||||
}
|
}
|
||||||
// check that input image exists and is either jpeg or png
|
// check that input image exists and is either jpeg or png
|
||||||
// also fail if the basic CACHE folder does not exist at all
|
// also fail if the basic CACHE folder does not exist at all
|
||||||
if (
|
if (!file_exists($filename)) {
|
||||||
!file_exists($filename) ||
|
// return $thumbnail;
|
||||||
!is_dir($cache_folder) ||
|
throw new \UnexpectedValueException('Missing image file: ' . $filename);
|
||||||
!is_writable($cache_folder)
|
}
|
||||||
) {
|
if (!is_dir($cache_folder)) {
|
||||||
return $thumbnail;
|
// return $thumbnail;
|
||||||
|
throw new \UnexpectedValueException('Cache folder is not a directory: ' . $cache_folder);
|
||||||
|
}
|
||||||
|
if (!is_writable($cache_folder)) {
|
||||||
|
// return $thumbnail;
|
||||||
|
throw new \UnexpectedValueException('Cache folder is not writeable: ' . $cache_folder);
|
||||||
}
|
}
|
||||||
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
||||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [0, 0, null];
|
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [0, 0, null];
|
||||||
@@ -347,6 +359,7 @@ class Image
|
|||||||
imagedestroy($source);
|
imagedestroy($source);
|
||||||
imagedestroy($thumb);
|
imagedestroy($thumb);
|
||||||
} else {
|
} else {
|
||||||
|
$exception_message = 'Invalid source image file. Only JPEG/PNG are allowed: ' . $filename;
|
||||||
$thumbnail = false;
|
$thumbnail = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,7 +443,11 @@ class Image
|
|||||||
// add web path
|
// add web path
|
||||||
$thumbnail = $thumbnail_web_path . $thumbnail;
|
$thumbnail = $thumbnail_web_path . $thumbnail;
|
||||||
}
|
}
|
||||||
// either return false or the thumbnail name + output path web
|
// if still false -> throw exception
|
||||||
|
if ($thumbnail === false) {
|
||||||
|
throw new \RuntimeException($exception_message);
|
||||||
|
}
|
||||||
|
// else return the thumbnail name + output path web
|
||||||
return $thumbnail;
|
return $thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class SymmetricEncryption
|
|||||||
* @param string $message Message to encrypt
|
* @param string $message Message to encrypt
|
||||||
* @param string $key Encryption key (as hex string)
|
* @param string $key Encryption key (as hex string)
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
* @throws \RangeException
|
* @throws \RangeException
|
||||||
*/
|
*/
|
||||||
public static function encrypt(string $message, string $key): string
|
public static function encrypt(string $message, string $key): string
|
||||||
@@ -34,7 +35,7 @@ class SymmetricEncryption
|
|||||||
try {
|
try {
|
||||||
$key = CreateKey::hex2bin($key);
|
$key = CreateKey::hex2bin($key);
|
||||||
} catch (SodiumException $e) {
|
} catch (SodiumException $e) {
|
||||||
throw new \Exception('Invalid hex key');
|
throw new \UnexpectedValueException('Invalid hex key');
|
||||||
}
|
}
|
||||||
if (mb_strlen($key, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
|
if (mb_strlen($key, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
|
||||||
throw new \RangeException(
|
throw new \RangeException(
|
||||||
@@ -84,10 +85,10 @@ class SymmetricEncryption
|
|||||||
$key
|
$key
|
||||||
);
|
);
|
||||||
} catch (SodiumException $e) {
|
} catch (SodiumException $e) {
|
||||||
throw new \Exception('Invalid ciphertext (too short)');
|
throw new \UnexpectedValueException('Invalid ciphertext (too short)');
|
||||||
}
|
}
|
||||||
if (!is_string($plain)) {
|
if (!is_string($plain)) {
|
||||||
throw new \Exception('Invalid Key');
|
throw new \UnexpectedValueException('Invalid Key');
|
||||||
}
|
}
|
||||||
sodium_memzero($ciphertext);
|
sodium_memzero($ciphertext);
|
||||||
sodium_memzero($key);
|
sodium_memzero($key);
|
||||||
|
|||||||
Reference in New Issue
Block a user