Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Open up Paginator::$documents for read

未关闭
#8,118 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
elasticsearch, php
领域
api, backend

调研方向

从 Elasticsearch\Paginator 类开始,检查 Hydra 集合规范化器如何使用其文档。使用 issue 中的 decorator 示例,验证无需替换原生 provider 即可读取 Elasticsearch 聚合;当文档保持只读但可公开访问时,这项工作就完成了。

由索引模型根据 Issue 内容生成。

描述

Elasticsearch

Description
In Elasticsearch\Paginator, the results of the query stored in $this->documents are private readonly.

Since the property is readonly anyway, would you be willing to make it public readonly?

A lot of the time, Elasticsearch returns metadata such as aggregations, necessary for building feature-rich search experiences.

It is a total waste of time to implement a custom Elasticsearch provider. The native one is great and does a lot of heavy lifting. If the property was open for read, I could simply decorate the normalizer, see example.

Example

#[AsDecorator('api_platform.hydra.normalizer.collection')]
class ElasticsearchNormalizer implements NormalizerInterface, NormalizerAwareInterface
{
    public function __construct(
        private NormalizerInterface $normalizer,
    ) {
    }

    public function normalize(mixed $object, string $format = null, array $context = []): array
    {
        if (!$object instanceof Elasticsearch\Paginator) {
            throw new \LogicException();
        }

        return array_merge(
            $this->normalizer->normalize($object, $format, $context), // produces a valid hydra:collection
            ['aggregations => $object->documents['aggregations']], // metadata returned by Elasticsearch read from the raw result
        ));
    }
}
主要语言
PHP
星标
2.6k
派生
988
平均合并
1 天 19 小时
30 天内合并 PR
108

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。