Compare commits

..

7 Commits

4 changed files with 38 additions and 11 deletions

View File

@ -1 +1 @@
v3.2.3
v3.2.4

View File

@ -11,6 +11,7 @@
namespace controllers\internals;
use DateTime;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
@ -37,15 +38,34 @@ class ExpressionProvider implements ExpressionFunctionProviderInterface
return isset($var);
});
//Check if today is birthday given a birthdate as DateTime
$is_birthday = new ExpressionFunction('is_birthday', function ($birthdate)
{
return sprintf('isset(%1$s) && is_a(%1$s, \'DateTime\') && %1$s->format(\'m-d\') == (new \\DateTime())->format(\'m-d\')', $birthdate);
}, function ($arguments, DateTime $birthdate)
{
if (!($birthdate ?? false))
{
return false;
}
return $birthdate->format('m-d') == (new DateTime())->format('m-d');
});
return [
$neutralized_constant,
$exists,
$is_birthday,
ExpressionFunction::fromPhp('mb_strtolower', 'lower'),
ExpressionFunction::fromPhp('mb_strtoupper', 'upper'),
ExpressionFunction::fromPhp('mb_substr', 'substr'),
ExpressionFunction::fromPhp('mb_strlen', 'strlen'),
ExpressionFunction::fromPhp('abs', 'abs'),
ExpressionFunction::fromPhp('strtotime', 'date'),
ExpressionFunction::fromPhp('date_create', 'date'),
ExpressionFunction::fromPhp('date_create_from_format', 'date_from_format'),
ExpressionFunction::fromPhp('intval', 'intval'),
ExpressionFunction::fromPhp('boolval', 'boolval'),
ExpressionFunction::fromPhp('count', 'count'),
];
}
}

View File

@ -43,18 +43,15 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
{
try
{
$this->expression_language->parse($condition, array_keys($data));
//Use @ to hide notices on non defined vars
@$this->expression_language->parse($condition, array_keys($data));
return true;
}
catch (\Exception $e)
catch (\Throwable $t) //Catch both, exceptions and php error
{
return false;
}
catch (\Throwable $t)
{
//Just ignore non critical php warning and notice
}
}
/**
@ -69,11 +66,12 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
{
try
{
//Use @ to hide notices on non defined vars
@$result = $this->expression_language->evaluate($condition, $data);
return (bool) $result;
}
catch (\Exception $e)
catch (\Throwable $t) //Catch both, exceptions and php error
{
return null;
}

View File

@ -20,6 +20,8 @@ use Monolog\Logger;
class Phone extends AbstractDaemon
{
private $max_inactivity = 5 * 60;
private $read_delay = 20 / 0.5;
private $read_tick = 0;
private $msg_queue;
private $msg_queue_id;
private $webhook_queue;
@ -56,13 +58,20 @@ class Phone extends AbstractDaemon
{
usleep(0.5 * 1000000); //Micro sleep for perfs
$this->read_tick += 1;
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
//Send smss in queue
$this->send_smss();
//Read received smss
$this->read_smss();
//Read only every x ticks (x/2 seconds) to prevent too many call
if ($this->read_tick >= $this->read_delay)
{
//Read received smss
$this->read_smss();
$this->read_tick = 0;
}
//Stop after 5 minutes of inactivity to avoid useless daemon
if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)