1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-22 16:06:38 +08:00

优化Providers

This commit is contained in:
xiaochong0302 2023-06-15 11:36:55 +08:00
parent fb5feb0759
commit f7a3c0d736
6 changed files with 28 additions and 7 deletions

View File

@ -26,15 +26,19 @@ class Annotation extends Provider
$this->di->setShared($this->serviceName, function () use ($config) {
if ($config->get('env') == ENV_DEV) {
$annotations = new MemoryAnnotations();
} else {
$statsKey = '_ANNOTATION_';
$annotations = new RedisAnnotations([
'host' => $config->path('redis.host'),
'port' => $config->path('redis.port'),
'auth' => $config->path('redis.auth'),
'index' => $config->path('redis.index') ?: 0,
'lifetime' => $config->path('annotation.lifetime') ?: 30 * 86400,
'index' => $config->path('redis.index'),
'lifetime' => $config->path('annotation.lifetime'),
'prefix' => $statsKey . ':',
'statsKey' => $statsKey,
]);

View File

@ -33,7 +33,7 @@ class Cache extends Provider
'host' => $config->path('redis.host'),
'port' => $config->path('redis.port'),
'auth' => $config->path('redis.auth'),
'index' => $config->path('redis.index') ?: 0,
'index' => $config->path('redis.index'),
]);
});
}

View File

@ -42,8 +42,11 @@ class Database extends Provider
$connection = new MySqlAdapter($options);
if ($config->get('env') == ENV_DEV) {
$eventsManager = new EventsManager();
$eventsManager->attach('db', new DbListener());
$connection->setEventsManager($eventsManager);
}

View File

@ -26,15 +26,19 @@ class MetaData extends Provider
$this->di->setShared($this->serviceName, function () use ($config) {
if ($config->get('env') == ENV_DEV) {
$metaData = new MemoryMetaData();
} else {
$statsKey = '_METADATA_';
$metaData = new RedisMetaData([
'host' => $config->path('redis.host'),
'port' => $config->path('redis.port'),
'auth' => $config->path('redis.auth'),
'index' => $config->path('redis.index') ?: 0,
'lifetime' => $config->path('metadata.lifetime') ?: 30 * 86400,
'index' => $config->path('redis.index'),
'lifetime' => $config->path('metadata.lifetime'),
'prefix' => $statsKey . ':',
'statsKey' => $statsKey,
]);

View File

@ -28,8 +28,8 @@ class Session extends Provider
'host' => $config->path('redis.host'),
'port' => $config->path('redis.port'),
'auth' => $config->path('redis.auth'),
'index' => $config->path('redis.index') ?: 0,
'lifetime' => $config->path('session.lifetime') ?: 24 * 3600,
'index' => $config->path('redis.index'),
'lifetime' => $config->path('session.lifetime'),
'prefix' => '_SESSION_:',
]);

View File

@ -99,6 +99,16 @@ class Volt extends Provider
return 'kg_anonymous(' . $resolvedArgs . ')';
});
$compiler->addFilter('split', function ($resolvedArgs, $exprArgs) use ($compiler) {
$firstArgument = $compiler->expression($exprArgs[0]['expr']);
if (isset($exprArgs[1])) {
$secondArgument = $compiler->expression($exprArgs[1]['expr']);
} else {
$secondArgument = '';
}
return sprintf('explode(%s,%s)', $secondArgument, $firstArgument);
});
return $volt;
});
}