dbp/relay-base-organization-bundle

v0.2.13 2024-05-23 09:32 UTC

README

GitHub | Packagist

Test

集成到 Relay API 服务器

  • 将捆绑包添加为依赖项
composer require dbp/relay-base-organization-bundle
  • config/bundles.php 中将捆绑包添加到 DbpRelayCoreBundle 之前
...
Dbp\Relay\BaseOrganizationBundle\DbpRelayBaseOrganizationBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle => ['all' => true],
];
  • 运行 composer install 清除缓存

OrganizationProvider 服务

对于需要获取组织的服务,您需要在您的应用程序中创建一个实现 OrganizationProviderInterface 的服务。

示例

服务类

例如,您可以将以下代码放入 src/Service/OrganizationProvider.php

<?php

declare(strict_types=1);

namespace YourUniversity\Service;

use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseOrganizationBundle\Entity\Organization;

class OrganizationProvider implements OrganizationProviderInterface
{
    public function getOrganizationById(string $identifier, string $lang): Organization
    {
        return some_method_that_fetches_an_organization_by_id($identifier, $lang);
    }

    /**
     * @return Organization[]
     */
    public function getOrganizationsByPerson(Person $person, string $context, string $lang): array
    {
        return some_method_that_fetches_an_organization_by_person($person, $context, $lang);
    }

    /**
     * @return Organization[]
     */
    public function getOrganizations(string $lang): array
    {
        return some_method_that_fetches_all_organizations($lang);
    }
}

服务配置

对于上述类,您需要将其添加到您的 src/Resources/config/services.yaml

  Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface:
    '@YourUniversity\Service\OrganizationProvider'