开罗项目/api-loader

一个数据加载监听器,用于附加到ApiController事件

dev-master / 1.0.x-dev 2018-08-25 10:19 UTC

This package is not auto-updated.

Last update: 2024-09-15 05:39:28 UTC


README

一个数据加载监听器,用于附加到ApiController事件。

1) 主题

数据加载是每个应用程序和Web项目的必要部分。因此,开罗项目的API部分必须能够加载、存储、验证客户端数据等。

ApiLoader系统本身负责此功能的数据加载部分。它必须与大量驱动程序、适配器或Web服务客户端协同工作。顺便说一下,该段落的泛化是关键特性。默认情况下,它不会实现任何加载逻辑,而只提供一种通用范式。

在第一层上,该组件必须处理两个知名操作

  • 加载特定项
  • 加载一系列项

为了依赖于ApiController库,ApiLoader将其定义为依赖项。然后,它变得可能集成事件分派逻辑。这种逻辑将允许开发人员附加一些查询构建扩展。这些扩展将使用查询构建事件而不是顶级ApiController的ProcessEvent。

由于原始事件包含对请求的引用,可能需要扩展,新的一个将提供访问它的权限。

2) 类架构

API加载系统是更多特定数据访问对象(DAO)的占位符。为了遵循此原则,元素不能实现数据加载算法,而应提供由特定DAO继承的抽象加载工作流程。

抽象加载器将实现三个方法,作为两个基本加载操作的唯一入口点。这两个是

  • loadCollection
  • loadItem

元素必须管理一个日志系统,以确保系统的可追溯性。

3) 依赖描述和在元素中的使用

在撰写本文时,API控制器被设计为有三个生产依赖项,如下所示

  • psr/log
  • symfony/event-dispatcher
  • kairos-project/api-controller

3.1) psr/log

调试和错误回溯是每个项目部分开发的基本法律,目前它是OWASP十大威胁之一所缺少的部分。

根据第三版PHP标准参考定义,日志组件必须实现一个特定接口。顺便说一下,日志系统将适用于每个现有的框架。

3.2) symfony/event-dispatcher

API加载系统设计为易于扩展,并将实现一个事件分派系统,允许按优先级附加和分离逻辑。

3.3) kairos-project/api-controller

加载器是为API和开罗项目中的通用系统API控制器而设计的。该系统提供了访问特定工作流程事件的权限。

加载器将定义控制器组件作为依赖项以使用工作流程事件。

4) 实现规范

如第二部分所述,抽象类将实现'loadCollection'和'loadItem'方法。

4.1) 依赖注入规范

实例将在构造函数中直接接收日志实例和事件分派器。

为了配置能力,可以提供两个事件名称来定义查询构建分派的事件。这些元素将有一个默认值,由常量定义。

还可以定义查询结果键。

4.2) loadCollection方法算法

loadCollection方法旨在查找并加载一组项目。

We assume to receive the process event from the parameters.
We assume to receive the event name from the parameters.
We assume to receive the event dispatcher from the parameters.

Get a queryBuilding event from the getQueryBuildingEvent by offer the initial event.
Provide the event to instanciateQueryBuilder, and inject a new queryBuilder.
Provide the event to configureQueryForCollection. This step configures the queryBuilder.
Dispatch a query building event name. This action allows the modification of the query by some attached extensions.
Execute the query for collection and insert the result into the original event, at a defined key.

4.3) loadItem方法算法

loadItem方法旨在查找并加载特定项目。

We assume to receive the process event from the parameters.
We assume to receive the event name from the parameters.
We assume to receive the event dispatcher from the parameters.

Get a queryBuilding event from the getQueryBuildingEvent by offer the initial event.
Provide the event to instanciateQueryBuilder, and inject a new queryBuilder.
Provide the event to configureQueryForItem. This step configures the queryBuilder.
Dispatch a query building event name. This action allows the modification of the query by some attached extensions.
Execute the query for an item and insert the result into the original event, at a defined key.
If the item is empty and the loader is configured to throw an exception in such case, it will throw a runtime exception with code 404.

4.4) 事件规范

由库定义的查询构建事件是初始进程事件和查询构建器的传输元素。它必须继承基本事件逻辑,在实例化时存储进程事件,并提供一个setQuery方法。

事件必须提供获取器以检索存储的元素。getQuery和getProcessEvent将是组件操作的一部分。

5) 使用方法

API加载器仅提供抽象类,不能直接使用。