Compare commits
No commits in common. "b5d148304874a27a5cfbdccd8956042bf8b87db3" and "e80638dd2e114793f29077d65a3535a6c7acd0d4" have entirely different histories.
b5d1483048
...
e80638dd2e
|
@ -11,7 +11,6 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
use DateTime;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
|
@ -38,34 +37,15 @@ 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('date_create', 'date'),
|
||||
ExpressionFunction::fromPhp('date_create_from_format', 'date_from_format'),
|
||||
ExpressionFunction::fromPhp('intval', 'intval'),
|
||||
ExpressionFunction::fromPhp('boolval', 'boolval'),
|
||||
ExpressionFunction::fromPhp('count', 'count'),
|
||||
ExpressionFunction::fromPhp('strtotime', 'date'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,15 +43,18 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|||
{
|
||||
try
|
||||
{
|
||||
//Use @ to hide notices on non defined vars
|
||||
@$this->expression_language->parse($condition, array_keys($data));
|
||||
$this->expression_language->parse($condition, array_keys($data));
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $t) //Catch both, exceptions and php error
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
//Just ignore non critical php warning and notice
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,12 +69,11 @@ 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 (\Throwable $t) //Catch both, exceptions and php error
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ 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;
|
||||
|
@ -58,20 +56,13 @@ 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 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;
|
||||
}
|
||||
//Read received smss
|
||||
$this->read_smss();
|
||||
|
||||
//Stop after 5 minutes of inactivity to avoid useless daemon
|
||||
if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)
|
||||
|
|
Loading…
Reference in New Issue