Skip to content

Commit

Permalink
Feat: allow switch serializer and support generating enum from string
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Dec 11, 2023
1 parent 7eab193 commit c3f7ffa
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ DB_MAX_CONNECTIONS=10
DB_IDLE_TIMEOUT=60
# Recent data will be stored in memory this amount of time:
DB_CACHE_TTL="+5 minutes"
# Options: serialize, igbinary
DB_SERIALIZER=serialize
# Enable to add cache info about users to database. Disable if you only read data from channels.
DB_ENABLE_MIN_DATABASE=0
# Enable file metadata cache
Expand Down
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ DB_MAX_CONNECTIONS=10
DB_IDLE_TIMEOUT=60
# Recent data will be stored in memory this amount of time:
DB_CACHE_TTL="+5 minutes"
# Options: serialize, igbinary
DB_SERIALIZER=serialize
# Enable to add cache info about users to database. Disable if you only read data from channels.
DB_ENABLE_MIN_DATABASE=0
# Enable file metadata cache
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ RUN true \
&& docker-php-ext-install -j$(nproc) sockets bcmath mysqli pdo_mysql pcntl ffi intl gmp zip gd \
# Install additional extension
&& mkdir -p /usr/src/php/ext/ && cd /usr/src/php/ext/ \
&& pecl bundle ev-beta && pecl bundle eio-beta \
&& docker-php-ext-install -j$(nproc) ev eio \
&& pecl bundle ev-beta && pecl bundle eio-beta && pecl bundle igbinary \
&& docker-php-ext-install -j$(nproc) ev eio igbinary \
# Install PrimeModule for AuthKey generation speedup
&& git clone https://github.com/danog/PrimeModule-ext \
&& cd PrimeModule-ext && make -j$(nproc) \
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'max_connections' => (int)getenv('DB_MAX_CONNECTIONS'),
'idle_timeout' => (int)getenv('DB_IDLE_TIMEOUT'),
'cache_ttl' => (string)getenv('DB_CACHE_TTL'),
'serializer' => danog\MadelineProto\Settings\Database\SerializerType::from('serialize'),
'serializer' => ((string)getenv('DB_SERIALIZER')) ?: 'serialize',
]
],
'files' => [
Expand Down
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use danog\MadelineProto\API;
use danog\MadelineProto\APIWrapper;
use danog\MadelineProto\Settings;
use danog\MadelineProto\Settings\Database\SerializerType;
use danog\MadelineProto\SettingsAbstract;
use InvalidArgumentException;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -187,6 +188,9 @@ private static function getSettingsFromArray(string $session, array $settings, S
$method = 'get' . ucfirst(str_replace('_', '', ucwords($key, '_')));
self::getSettingsFromArray($session, $value, $settingsObject->$method());
} else {
if ($key === 'serializer' && is_string($value)) {
$value = SerializerType::from($value);
}
$method = 'set' . ucfirst(str_replace('_', '', ucwords($key, '_')));
$settingsObject->$method($value);
}
Expand Down

0 comments on commit c3f7ffa

Please sign in to comment.