class Routes implements ContainerInjectionInterface (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Defines dynamic routes.

Constants

CONTROLLER_SERVICE_NAME

The service name for the primary JSON:API controller.

All resources except the entrypoint are served by this controller.

JSON_API_ROUTE_FLAG_KEY

A key with which to flag a route as belonging to the JSON:API module.

RESOURCE_TYPE_KEY

The route default key for the route's resource type information.

Properties

protected ResourceTypeRepositoryInterface $resourceTypeRepository

The JSON:API resource type repository.

protected string[] $providerIds

List of providers.

protected string $jsonApiBasePath

The JSON:API base path.

Methods

__construct(ResourceTypeRepositoryInterface $resource_type_repository, array $authentication_providers, string $jsonapi_base_path)

Instantiates a Routes object.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

routes()

{@inheritdoc}

static RouteCollection
getRoutesForResourceType(ResourceType $resource_type, string $path_prefix)

Gets applicable resource routes for a JSON:API resource type.

static RouteCollection
getFileUploadRoutesForResourceType(ResourceType $resource_type, string $path_prefix)

Gets the file upload route collection for the given resource type.

static bool
isJsonApiRequest(array $defaults)

Determines if the given request is for a JSON:API generated route.

static RouteCollection
getIndividualRoutesForResourceType(ResourceType $resource_type)

Gets a route collection for the given resource type.

Route
getEntryPointRoute(string $path_prefix)

Provides the entry point route.

static 
addRouteParameter(Route $route, string $name, mixed $parameter)

Adds a parameter option to a route, overrides options of the same name.

static string
getRouteName(ResourceType $resource_type, string $route_type)

Get a unique route name for the JSON:API resource type and route type.

static string
getFileUploadRouteName(ResourceType $resource_type, string $route_type)

Get a unique route name for the file upload resource type and route type.

static bool
hasNonInternalTargetResourceTypes(array $resource_types)

Determines if an array of resource types has any non-internal ones.

static bool
hasNonInternalFileTargetResourceTypes(array $resource_types)

Determines if an array of resource types lists non-internal "file" ones.

static ResourceType|null
getResourceTypeNameFromParameters(array $parameters)

Gets the resource type from a route or request's parameters.

static 
rebuild()

Invalidates any JSON:API resource type dependent responses and routes.

Details

__construct(ResourceTypeRepositoryInterface $resource_type_repository, array $authentication_providers, string $jsonapi_base_path)

Instantiates a Routes object.

Parameters

ResourceTypeRepositoryInterface $resource_type_repository

The JSON:API resource type repository.

array $authentication_providers

The authentication providers, keyed by ID.

string $jsonapi_base_path

The JSON:API base path.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

routes()

{@inheritdoc}

static protected RouteCollection getRoutesForResourceType(ResourceType $resource_type, string $path_prefix)

Gets applicable resource routes for a JSON:API resource type.

Parameters

ResourceType $resource_type

The JSON:API resource type for which to get the routes.

string $path_prefix

The root path prefix.

Return Value

RouteCollection

A collection of routes for the given resource type.

static protected RouteCollection getFileUploadRoutesForResourceType(ResourceType $resource_type, string $path_prefix)

Gets the file upload route collection for the given resource type.

Parameters

ResourceType $resource_type

The resource type for which the route collection should be created.

string $path_prefix

The root path prefix.

Return Value

RouteCollection

The route collection.

static bool isJsonApiRequest(array $defaults)

Determines if the given request is for a JSON:API generated route.

Parameters

array $defaults

The request's route defaults.

Return Value

bool

Whether the request targets a generated route.

static protected RouteCollection getIndividualRoutesForResourceType(ResourceType $resource_type)

Gets a route collection for the given resource type.

Parameters

ResourceType $resource_type

The resource type for which the route collection should be created.

Return Value

RouteCollection

The route collection.

protected Route getEntryPointRoute(string $path_prefix)

Provides the entry point route.

Parameters

string $path_prefix

The root path prefix.

Return Value

Route

The entry point route.

static protected addRouteParameter(Route $route, string $name, mixed $parameter)

Adds a parameter option to a route, overrides options of the same name.

The Symfony Route class only has a method for adding options which overrides any previous values. Therefore, it is tedious to add a single parameter while keeping those that are already set.

Parameters

Route $route

The route to which the parameter is to be added.

string $name

The name of the parameter.

mixed $parameter

The parameter's options.

static string getRouteName(ResourceType $resource_type, string $route_type)

Get a unique route name for the JSON:API resource type and route type.

Parameters

ResourceType $resource_type

The resource type for which the route collection should be created.

string $route_type

The route type. E.g. 'individual' or 'collection'.

Return Value

string

The generated route name.

static protected string getFileUploadRouteName(ResourceType $resource_type, string $route_type)

Get a unique route name for the file upload resource type and route type.

Parameters

ResourceType $resource_type

The resource type for which the route collection should be created.

string $route_type

The route type. E.g. 'individual' or 'collection'.

Return Value

string

The generated route name.

static protected bool hasNonInternalTargetResourceTypes(array $resource_types)

Determines if an array of resource types has any non-internal ones.

Parameters

array $resource_types

The resource types to check.

Return Value

bool

TRUE if there is at least one non-internal resource type in the given array; FALSE otherwise.

static protected bool hasNonInternalFileTargetResourceTypes(array $resource_types)

Determines if an array of resource types lists non-internal "file" ones.

Parameters

array $resource_types

The resource types to check.

Return Value

bool

TRUE if there is at least one non-internal "file" resource type in the given array; FALSE otherwise.

static ResourceType|null getResourceTypeNameFromParameters(array $parameters)

Gets the resource type from a route or request's parameters.

Parameters

array $parameters

An array of parameters. These may be obtained from a route's parameter defaults or from a request object.

Return Value

ResourceType|null

The resource type, NULL if one cannot be found from the given parameters.

static rebuild()

Invalidates any JSON:API resource type dependent responses and routes.