Skip to content

Commit

Permalink
docs: add docs for plugin ExtensionGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Jul 25, 2024
1 parent 64d482f commit 7570e2d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 与自定义模型交互
description: 了解如果通过代码的方式操作数据
description: 了解如何通过代码的方式操作数据
---

Halo 提供了两个类用于与自定义模型对象交互 `ExtensionClient``ReactiveExtensionClient`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: 获取扩展实例
description: 了解如何在插件中获取扩展实例
---

Halo 提供了丰富的扩展点,而插件不仅可以实现扩展点,也可以通过使用 `ExtensionGetter` 来获取 Halo 或其他插件所提供的扩展实例。

关于插件如何实现扩展点的详细信息,请参考:[扩展点](./extension-points/index.md)

```java
public interface ExtensionGetter {

/**
* Get only one enabled extension from system configuration.
*
* @param extensionPoint is extension point class.
* @return implementation of the corresponding extension point. If no configuration is found,
* we will use the default implementation from application context instead.
*/
<T extends ExtensionPoint> Mono<T> getEnabledExtension(Class<T> extensionPoint);

/**
* Get the extension(s) according to the {@link ExtensionPointDefinition} queried
* by incoming extension point class.
*
* @param extensionPoint extension point class
* @return implementations of the corresponding extension point.
* @throws IllegalArgumentException if the incoming extension point class does not have
* the {@link ExtensionPointDefinition}.
*/
<T extends ExtensionPoint> Flux<T> getEnabledExtensions(Class<T> extensionPoint);

/**
* Get all extensions according to extension point class.
*
* @param extensionPointClass extension point class
* @param <T> type of extension point
* @return a bunch of extension points.
*/
<T extends ExtensionPoint> Flux<T> getExtensions(Class<T> extensionPointClass);
}
```

### 示例

#### 单实例扩展点

对于单实例扩展点,例如 `SearchEngine` 扩展点,同一时间只能有一个实例被启用。要在插件中获取启用的搜索引擎扩展实例,可以使用以下代码:

```java
@Service
@RequiredArgsConstructor
public class SearchService {
private final ExtensionGetter extensionGetter;

Mono<SearchEngine> getSearchEngine() {
return extensionGetter.getEnabledExtension(SearchEngine.class)
}
}
```

#### 多实例扩展点

对于多实例扩展点,例如 `ReactiveNotifier` 扩展点,可以同时启用多个实例。要在插件中获取所有启用的通知器扩展实例,可以使用以下代码:

```java
@Service
@RequiredArgsConstructor
public class NotificationService {
private final ExtensionGetter extensionGetter;

Flux<ReactiveNotifier> getNotifiers() {
return extensionGetter.getEnabledExtensions(ReactiveNotifier.class)
}
}
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 静态资源代理
description: 了解如果使用静态资源代理来访问插件中的静态资源
description: 了解如何使用静态资源代理来访问插件中的静态资源
---

插件中的静态资源如图片等如果想被外部访问到,需要放到 `src/main/resources` 目录下,并通过创建 `ReverseProxy` 自定义模型对象来进行静态资源代理访问。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: API 权限控制
description: 了解如果对插件中的 API 定义角色模板以接入权限控制
description: 了解如何对插件中的 API 定义角色模板以接入权限控制
---

插件中的 APIs 无论是自定义模型自动生成的 APIs 或者是通过 `@Controller` 自定义的 APIs 都只有超级管理员能够访问,如果想将这些 APIs 授权给其他用户访问,
Expand Down

0 comments on commit 7570e2d

Please sign in to comment.