dbp / relay-base-bundle
此软件包已被废弃,不再维护。未建议替代软件包。
v0.1.3
2021-10-21 08:58 UTC
Requires
- php: ^7.3
- ext-json: *
- api-platform/core: ^2.6.3
- dbp/relay-core-bundle: ^0.1.11
- guzzlehttp/guzzle: ^7.0
- nelmio/cors-bundle: ^2.1.0
- phpdocumentor/reflection-docblock: ^3.0 || ^4.0 || ^5.0
- symfony/config: ^5.2
- symfony/expression-language: ^5.2
- symfony/framework-bundle: ^5.2
- symfony/security-bundle: ^5.2
- symfony/security-core: ^5.2
- symfony/security-guard: ^5.2
- symfony/twig-bundle: ^5.2
- symfony/validator: ^5.2
- symfony/yaml: ^5.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^0.12.33
- phpstan/phpstan-phpunit: ^0.12.13
- symfony/browser-kit: ^5.2
- symfony/http-client: ^5.2
- symfony/monolog-bundle: ^3.7
- symfony/phpunit-bridge: ^5.2
- vimeo/psalm: ^4.4
README
此Symfony软件包包含许多软件包所需的DBP中继项目的实体。
集成到中继API服务器
- 将软件包包作为依赖项添加
composer require dbp/relay-base-bundle
- 将软件包添加到您的
config/bundles.php
中,位于DbpRelayCoreBundle
前面
...
Dbp\Relay\BaseBundle\DbpRelayBaseBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle => ['all' => true],
];
- 运行
composer install
以清除缓存
PersonProvider服务
为了让此软件包工作,您需要在您的应用程序中创建一个实现 PersonProviderInterface 的服务。
示例
服务类
例如,您可以将以下代码放入 src/Service/PersonProvider.php
<?php
declare(strict_types=1);
namespace YourUniversity\Service;
use Dbp\Relay\BaseBundle\API\PersonProviderInterface;
use Dbp\Relay\BaseBundle\Entity\Person;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class PersonProvider implements PersonProviderInterface
{
/**
* @param array $filters $filters['search'] can be a string to search for people (e.g. part of the name)
* @return Person[]
*/
public function getPersons(array $filters): array
{
$people = some_method_to_fetch_persons($filters);
return $people;
}
public function getPersonsByNameAndBirthDate(string $givenName, string $familyName, string $birthDate): array
{
$people = some_method_to_fetch_persons_by_name_and_birthday($givenName, $familyName, $birthDate);
return $people;
}
public function getPerson(string $id): Person
{
return some_method_to_fetch_person_by_id($id);
}
/**
* This is only used by external services (e.g. the alma bundle) to translate external persons to internal persons
*
* @param string $service identifies the service that wants to fetch a person
* @param string $serviceID identifies person by an external id
* @return Person
*/
public function getPersonForExternalService(string $service, string $serviceID): Person
{
switch($service) {
case "some-service":
return some_method_to_fetch_person_from_external_service($serviceID);
break;
default:
throw new BadRequestHttpException("Unknown service: $service");
}
}
/**
* Returns the Person matching the current user. Or null if there is no associated person
* like when the client is another server.
*/
public function getCurrentPerson(): ?Person
{
return some_method_to_fetch_current_person();
}
}
服务配置
对于上述类,您需要将其添加到您的 src/Resources/config/services.yaml
Dbp\Relay\BaseBundle\API\PersonProviderInterface:
'@YourUniversity\Service\PersonProvider'
OrganizationProvider服务
对于需要获取组织的服务,您需要在您的应用程序中创建一个实现 OrganizationProviderInterface 的服务。
示例
服务类
例如,您可以将以下代码放入 src/Service/OrganizationProvider.php
<?php
declare(strict_types=1);
namespace YourUniversity\Service;
use Dbp\Relay\BaseBundle\API\OrganizationProviderInterface;
use Dbp\Relay\BaseBundle\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\BaseBundle\API\OrganizationProviderInterface:
'@YourUniversity\Service\OrganizationProvider'