You are here

public function EntityToJsonApi::__construct in JSON:API Extras 8.2

Same name and namespace in other branches
  1. 8.3 src/EntityToJsonApi.php \Drupal\jsonapi_extras\EntityToJsonApi::__construct()

EntityToJsonApi constructor.

Parameters

\Symfony\Component\Serializer\SerializerInterface $serializer: The serializer.

\Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository: The resource type repository.

\Drupal\Core\Session\AccountInterface $current_user: The currently logged in user.

\Symfony\Component\HttpFoundation\RequestStack $request_stack: The request stack.

string $jsonapi_base_path: The JSON API base path.

File

src/EntityToJsonApi.php, line 71

Class

EntityToJsonApi
Simplifies the process of generating a JSON API version of an entity.

Namespace

Drupal\jsonapi_extras

Code

public function __construct(SerializerInterface $serializer, ResourceTypeRepositoryInterface $resource_type_repository, AccountInterface $current_user, RequestStack $request_stack, $jsonapi_base_path) {
  assert($serializer instanceof Serializer);
  $this->serializer = $serializer;
  $this->resourceTypeRepository = $resource_type_repository;
  $this->currentUser = $current_user;
  $this->masterRequest = $request_stack
    ->getMasterRequest();
  assert(is_string($jsonapi_base_path));
  assert($jsonapi_base_path[0] === '/');
  assert(isset($jsonapi_base_path[1]));
  assert(substr($jsonapi_base_path, -1) !== '/');
  $this->jsonApiBasePath = $jsonapi_base_path;
}