attus/jsonapi_response 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

attus/jsonapi_response

最新稳定版本:2.6.0

Composer 安装命令:

composer require attus/jsonapi_response

包简介

JSON:API Response based on Custom Data

README 文档

README

A Drupal 10 module for custom JSON:API Entity responses.

Maintenance GitHub license GitHub release GitHub issues

Usage

use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\jsonapi_response\JsonapiEntityResponseInterface;

class MyController extends ControllerBase {

  private     $_jsonapiResponseEntity;

  public function __construct(JsonapiEntityResponseInterface $jsonapiResponseEntity) {
    $this->_jsonapiResponseEntity = $jsonapiResponseEntity;
  }
  
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('jsonapi_response.entity'),
    );
  }

  /**
   * A single entity in JSON:API Format
   */
  public function getMyEntity(): CacheableResponseInterface
  {
    $entity = $this->getEntityForResponse();
    $response = $this->_jsonapiResponseEntity->entityIndividualResponse($entity);
    $cache = new CacheableMetadata();
    $cache->setCacheMaxAge(0);
    $response->addCacheableDependency($cache);
    return $response;
  }

  /**
   * An entity collection in JSON:API Format
   */
  public function getMyEntityCollection(): CacheableResponseInterface
  {
    $entities = $this->getEntitiesForResponse();
    return $this->_jsonapiResponseEntity->entityCollectionResponse($entities);
  }
 
  /**
   * An entity collection in JSON:API Format with includes
   */
  public function getMyEntityCollectionWithIncludes(): CacheableResponseInterface
  {
    $entities = $this->getEntitiesForResponse();
    return $this->_jsonapiResponseEntity->entityCollectionResponse($entities, [$fieldName1, $fieldName2]);
  }

}

You are free to use this module without any restriction but without any warranty.

统计信息

  • 总下载量: 2.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2021-05-17