All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning and this changelog format.
- Adapter class now handles reading and modifying domain records.
- Adapter class has been split into resource and relationship adapters.
- Methods previously available on the request interpreter interface have been added to the request interface.
- The request interface has been renamed to 'inbound request' to make it clearer that it represents a JSON API request inbound to a server from a client.
- Middleware traits have been updated to reflect the changes to the inbound request interface.
- Hydrators have been removed as a result of the adapter changes described above.
- The request interpreter interface and classes have been removed as a result of the above changes.
- The request interface has been deprecated in favour of the inbound request interface.
- 37 Correctly detect message body in a HTTP response.
- The JSON API request interface's
getRecord()
method has been deprecated.
- All classes in the
Testing
namespace have been moved to thecloudcreativity/json-api-testing
package.
- Browsers sending an empty
Content-Length
header were being interpreted as sending message-body because we were following the specification exactly and checking for the existence of the header. If theContent-Length
header is sent, it is now checked that it is a non-zero value.
- An HTTP client interface for sending JSON API requests to a remote server, and a Guzzle 6 implementation.
- Can now get included resource objects from the JSON API document object.
- Can now get error objects from the JSON API document object.
- Added the following helper functions:
json_decode()
: wraps the native function and throws a JSON API exception if decoding fails.http_contains_body()
: determines if a PSR message contains body content.
- New serializer interface to type-hint that an encoder can also serialize data to an array.
- The response factory implementation was merged into the abstract responses class. This is because there was no logical difference between the two and it is simpler to merge them.
- A decoder is now only matched if the client has sent a HTTP request with message body.
- Deleted the
Utils\NullReporter
class as it was not in use. - The
Decoders\Helpers\DecodesJsonTrait
has been removed in preference of the package'sjson_decode()
function. - The
Decoders\DocumentDecoder
has been removed as it is no longer in use. - The
Contracts\Http\ApiInterface
interface andHttp\Api
have been removed as they are no longer in use within this package. - The
Contracts\Http\Responses\ResponseFactoryInterface
interface andHttp\Responses\ResponseFactory
have been removed (see changes above).
- Validation error messages for invalid attributes and query parameters can now be created via the validator error factory.
- Renamed
Resource
toResourceObject
, along with associated interfaces, collections and testers. This is becauseresource
is a reserved name in PHP. id
member on a resource object or resource object identifier will now always be returned as a string. Integers were previously allowed, however the spec states that theid
member must be a string.
- Separated out the standard object implementation into a
cloudcreativity/utils-object
package and removed the classes, interfaces and utilities from this package. - Deprecated
RelatedHydratorTrait::callHydrateRelated()
removed. - The
HttpServiceInterface
was removed as it is no longer required as classes can be directly injected rather than obtained via the service.
- [#35] Validator was not rejecting a resource identifier with a
null
id. It will now reject an identifier that does not have a stringid
. The same change has also been implemented in the resource object validator. - [#30] Attributes that are objects are now cast as standard objects when iterating over attributes.
- A query parameter validator interface that can be injected into a new validation query checker class. This allows integration of framework specific validators into the query checking process.
- Traits to apply to HTTP middleware are now available in the
Http\Middleware
namespace.
- Resource type is now passed to authorizer methods that do not receive a record instance.
- The
ApiInterface
no longer returns a factory, paging strategy or options. It now returns an errors repository as errors are specifically scoped to an API. - Store adapters are now tied to a specific resource type rather than handling multiple. This allows them to deal with querying (index routes) many resources at once - i.e. filter, pagination logic.
- Pagination has been removed as it is too framework-specific. This package now only contains a single interface -
PageInterface
- that indicates that data is paginated. The response factory handles this to merge the paginated data into the encoded response. - Refactored factories to bring them more in line with the
neomerx/json-api
factory approach.
- The
RequestHandlerInterface
and related classes. This helps reduce the number of units per resource-type, as the functions of this class can be implemented as HTTP middleware. - The filter validator has been removed in preference of query parameter validation.
- Corrected doc blocks in
RequestHandler
- Extended encoder that allows serialization of JSON API documents to arrays.
- Can now check whether a resource type is known to the store (i.e. is a valid resource type).
- Relationships validators will now reject a resource identifier if the resource type is not known to the store - i.e. is not valid. A specific validation error message is returned when this is encountered.
- The
neomerx/json-api
dependency has been updated to v1.0.
- This package no longer supports PHP 5.5.
- New trait for standard hydrating of attributes:
Hydrator\HydratesAttributesTrait
. - New trait for standard extraction of attributes:
Schema\ExtractsAttributesTrait
. - Helpers have been added for converting string keys, to aid conversion from the JSON API recommended dasherized
format to underscores or camel case. Helpers are on the
Utils\Str
class. RelatedHydratorTrait
now also enables attributes to be mapped during related hydration.
- Added a full suite of request processing classes, as changes to the
ApiInterface
and the addition of aRequestInterface
allow this to be framework-agnostic.- A request factory now builds a JSON API request object, throwing JSON API exceptions if anything about the
request does not conform to the JSON API specification.
-
RequestInterpreterInterface
and anAbstractRequestInterpreter
class. This interface determines what 'type' of JSON API request the current request is. The abstract implementation means there is minimal framework integration required. RequestHandlerInterface
validates the request against domain (application) logic. A default request handler is provided and applications can compose the logic by injecting it with an authorizer and validator provider.
- A request factory now builds a JSON API request object, throwing JSON API exceptions if anything about the
request does not conform to the JSON API specification.
-
- Added an
AbstractResponses
class that means very minimal framework integration is required. - Added a
ResponseFactory
class to provided easy creation of common JSON API responses. - A new trait
ErrorCreatorTrait
is now available. This allows an object to construct the errors it contains either directly from error objects or by using string keys that load errors from the error repository. The recommended approach is to always load errors via an error repository. - New validator -
RelationshipValidator
- that validates that a relationships object is either a has-one or a has-many relationship. I.e. that it is a valid relationship object according to the JSON API spec. - The store is now backed by an identity map, meaning multiple checks for resource identifiers will not result in adapters being queried multiple times.
- Allow a document's data member to be returned as a resource collection if it is an array. Added a resource collection interface and class for this purpose.
- Allow a hydrator to hint that it needs to hydrate related domain records by implementing the
HydratesRelatedInterface
. This is useful for two-step hydration, which is commonly needed for relational databases.
- An acceptable relationship callback or class implementing
AceptRelatedResourceInterface
can now return an error or error collection instead of a boolean. This allows a custom error message to be returned. AbstractHydrator::methodForRelationship()
is no longer abstract. The default implementation camel cases a relationship key, prependshydrate
and appendsRelationship
.- Authorizers now receive the client sent resource in
canUpdate()
and the client sent relationship incanModifyRelationship
. This allows authorization logic to factor in what a client is attempting to change on a specific resource if needed. AbstractAuthorizer
now uses the newErrorCreatorTrait
instead of theErrorsAwareTrait
, so that authorizers can load authorization errors from the error repository.- Improved
ValidatorProviderInterface
so that a provider receives the URL arguments from a request. This means that a validator provider can now be used for multiple resource types if required. - Can now construct generic validators to check a document is valid according to the JSON API spec without knowing
any business logic - i.e. that the document is semantically correct. The validator factory can now make:
- a generic resource validator, plus the resource validator argument is now optional when creating a resource document validator; and
- a generic relationship validator, plus the relationship validator argument is now optional when creating a relationship document validator.
- A generic validator provider is now available that will validate any request against the JSON API spec using these default validators.
- Bug in resources tester that prevented normalization of ids if an integer was passed for ids.
- Testers for a resource and multiple resources (resource collections). These tester can be obtained via methods on the document tester.
- Hydration hooks in
AbstractHydrator
so that it is easier to implement pre- and post-hydration logic.
This is a substantial refactoring, based on using this package in production environments. We also updated
the underlying package neomerx/json-api
to from v0.6.6
to ^0.8.0
, which is a breaking change.
See the Upgrade Notes for help.
This is a brief summary of the main changes:
- New validator interfaces so that a validator is specific as to what part of the JSON API document it is responsible for validating.
- Validator instances are now built via a validator factory (which has a defined interface). This makes it clearer how to construct validators that are provided by this package.
- Each resource type in an application will now have a 'validator provider' (
ValidatorProviderInterface
) that constructs the validators that are specific for that resource type. - The concept of a 'store' was added. This enables validators etc to look up domain objects that are referred to in JSON API resource identifiers (type/id combinations).
- Errors defined in configuration arrays are now loaded via an 'error repository'. Provision of errors from this service allows your application to implement global error modifiers, e.g. translation, as required.
- An
ApiInterface
now exists to hold the JSON API configuration per API in your application. - A
HydratorInterface
was added so that the logic for transferring data from a JSON API document into a domain object can be unitized if desired. This helps reduce the complexity of controllers. - The
Testing
namespace was added, with some initial test helpers. The test helpers are designed for use with PHPUnit and enable assertions on the content of JSON API documents returned by your applications. We'll be adding more test helpers in future releases.
- Abstracted framework integration removed in favour of framework packages writing their own integrations that suit the needs of the particular framework.
- Error handling changes in the
neomerx/json-api
package resulted in exception renderers being removed. - All validators in the
Validator
(singular) namespace were removed. Our refactored validator implementation is in theValidators
namespace instead.
- Standard object
transformKeys
method, to apply a callable transform to keys on the object. - Standard object
convertValue
andconvertValues
methods. To apply a callable converter to key or keys on the object.
- Standard object
mapKey
andmapKeys
helpers, to change keys within the object.
ThrowableError
class is now deprecated. In its place, you should throw anErrorException
and can use an array as the first constructor argument to construct the JSON API error object that is being thrown.ThrowableError
will be removed inv0.5.0
.