All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- Nothing
- Added the ability to send headers through repositories #103.
- Added support for Laravel 11 #101.
- Added support for
psr/http-message
v2 #100.
- Added support for Laravel 10.
- Dropped PHP <7.4 support.
- Dropped Laravel <8 support.
- Added
getData
method on relationships to get the relationship data #97.
- Fix relationship data meta issue #97.
- The
Repository
is split up into one trait per action #91. This allows you to build your own repository by extending theBaseRepository
and including just the actions/traits you need. See the (updated) readme for usage instructions. TheRepository
now uses these new traits and should be fully backwards compatible.
- Fix ParamNameMismatch issue #96.
- Added support for Laravel 9.
- Temporarily suppress PHP 8.1 notices about inconsistencies with interfaces.
Please also check the changes in 2.0.0-beta and see UPGRADING for details on how to upgrade.
- All classes now use strict typing #93.
- All JSON-actions (
json_encode
andjson_decode
) will throw JsonExceptions on error #94.
- Dropped PHP <7.3 support.
Please see UPGRADING for details on how to upgrade.
- Added
Item::mergeAppends
,Item::mergeCasts
,Item::mergeFillable
andItem::mergeGuarded
.
- Renamed
Item::addHidden
toItem::makeHidden
. - Merged
Item::addVisible
andItem::withHidden
intoItem::makeVisible
. - Changed visibility of
Item::getAttributeValue
to public. - The item's
toArray
method will now cast any attributes that implementIlluminate\Contracts\Support\Arrayable
to an array. - The item's
newInstance
method will now copy the type of the original item.
- Dropped Laravel <6 and PHP <7.2 support.
- Removed
jenssegers/model
dependency and added the classes into the package. - Removed unintended array access to internal properties on the item (e.g.
$item['attributes']
). - Extracted Laravel parts (config, service provider and facades) into swisnl/json-api-client-laravel.
- Parse meta in resource identifier objects #89.
- The service provider will not set the base uri if it's empty. This allows you to set it in a custom container binding without using the config file.
- Do not prepend the base uri if the endpoint is already absolute #82.
- Added factory methods to
DocumentClient
,ResponseParser
andDocumentParser
. This will make it easier to use these without an IOC container. See the (updated) readme for usage instructions. #79
- Added support for Laravel 8 #81.
Document
,Jsonapi
,Links
andMeta
classes will be serialized as object when empty.- Properly handle relations without data #78.
- Added support for Laravel 7 #75.
- Do not break out of loop when hydrating relations #71.
- Do not require error links object to contain an about member #69.
- Reworded
ValidationException
messages to align them with the wordings used in the specification. DocumentParser
throws aValidationException
when it encounters duplicate resources #64.TypeMapperInterface
andTypeMapper
are now registered as the same singleton #65.
ItemHydrator
unsets a relation when null (singular) or empty array (plural) instead of hydrating a relation with idnull
#67.
- Fixed parsing of empty singular relationships #63.
This release includes a small breaking change because we switched from PHP-HTTP to PSR-18, its successor. Almost all PHP-HTTP clients now implement PSR-18, so this should not be a big problem. This also means for example that PSR exceptions are thrown instead of PHP-HTTP exceptions. If you are relying on some PHP-HTTP classes yourself, make sure to review your code and change those to their PSR equivalent. If you are using this package within a Laravel application, it is important to note that we also changed the way how you can bind your own HTTP client. Please see the documentation and compare all code changes for more details!
- Added support for Laravel 6 #61.
- Switched from PHP-HTTP to PSR-18, its successor #60.
- The
\Swis\JsonApi\Client\Client
now uses php-http/discovery itself instead of the service provider. This should make usage without Laravel easier #60. - Removed the
$baseUri
parameter from\Swis\JsonApi\Client\Client::__construct()
, use\Swis\JsonApi\Client\Client::setBaseUri()
instead #60.
- Removed
\Swis\JsonApi\Client\Providers\ServiceProvider::getHttpClient()
and\Swis\JsonApi\Client\Providers\ServiceProvider::getMessageFactory()
as the client now discovers these classes itself. Custom HTTP clients must now be registered within your own service provider using a custom container binding #60.
- Self and related links can not be
null
#59. - Error links MUST have about link. Relationship links MUST have either self or related link #59.
- Links has to be an object.
- Drop art4/json-api-client dependency and validate the JSON ourselves #58.
\Swis\JsonApi\Client\Exceptions\ValidationException
is thrown instead of\Art4\JsonApiClient\Exception\ValidationException
#58.- Added
hasAttribute
toItemInterface
. - All exceptions thrown by this package now implement
\Swis\JsonApi\Client\Exceptions\Exception
.
- Empty (
null
) links are correctly parsed. - Empty (
null
) singular relationships are correctly parsed.
- Change signature of
RepositoryInterface::save()
. It should now receive anItemInterface
instead of aItemDocumentInterface
.
- Added
DocumentFactory
#52. - Added facades for
DocumentFactory
,DocumentParser
,ItemHydrator
,ResponseParser
andTypeMapper
. - Added
DocumentParserInterface
andResponseParserInterface
interfaces and implementations #54.
- The
TypeMapper
now checks if the class exists in the setter instead of the getter. - The
ItemHydrator
now also hydrates the id if provided #53. - Added
hasType
,hasAttributes
,hasRelationships
andgetRelations
toItemInterface
#53. - Removed
canBeIncluded
andgetIncluded
fromItemInterface
as theDocumentFactory
is now responsible for gathering the included items #53. - Renamed
getRelationship
togetRelation
,hasRelationship
tohasRelation
andremoveRelationship
tounsetRelation
inItem
#53. - Renamed/aligned some parameters in several relation methods in
Item
#53. - Renamed namespace
Swis\JsonApi\Client\Traits
toSwis\JsonApi\Client\Concerns
#53. - Renamed namespace
Swis\JsonApi\Client\JsonApi
toSwis\JsonApi\Client\Parsers
#54. - Renamed
ServiceProvider::registerParser
(singular) toServiceProvider::registerParsers
(plural) #54.
- Removed
CollectionDocumentBuilder
andItemDocumentBuilder
in favor ofDocumentFactory
#52. - Removed
ParserInterface
in favor ofDocumentParserInterface
andResponseParserInterface
#54.
- The id of an item can be set/get using magic accessors just like the attributes #51.
- Added (optional) type hints to several interfaces. N.B. This is a breaking change if you implement some of the interfaces yourself.
- Renamed
deleteById
method to simplydelete
and removed the 'old' implementation inRepositoryInterface
. N.B. This is a breaking change and all calls todeleteById
should simply be changed todelete
as the signature is unchanged.
- Added support for Laravel 5.8 #50.
- Added
DocumentInterface::getResponse()
so every document instance can have its corresponding response. This allows access to the underlying response to check headers or status codes etc #48. - Added
ParserInterface::deserializeResponse($reponse)
to deserialize a\Psr\Http\Message\ResponseInterface
.
ClientInterface
must now return a\Psr\Http\Message\ResponseInterface
for requests instead of our own (removed)ResponseInterface
#48. N.B. This is a breaking change if you use theClient
directly, theDocumentClient
isn't affected.- Changed namespace of error classes:
\Swis\JsonApi\Client\Errors\Error -> \Swis\JsonApi\Client\Error
\Swis\JsonApi\Client\Errors\ErrorCollection -> \Swis\JsonApi\Client\ErrorCollection
\Swis\JsonApi\Client\Errors\ErrorSource -> \Swis\JsonApi\Client\ErrorSource
- Removed
ResponseInterface
andResponse
classes #48.
This release includes changes to some interfaces #47. This is a breaking change if you use these interfaces in your own code.
- Added
take
method toRepository
to allow fetching resources without id. - Added links and meta to
ItemInterface
. - Added
Jsonapi
class. - Added links and meta to
OneRelationInterface
andManyRelationInterface
. - Added
Link
andLinks
classes. - Added links to
Error
.
Error::getMeta()
now returns aMeta
instance instead of anErrorMeta
instance. TheMeta
class does not have thehas
andget
methods, but uses magic overloading methods (e.g.__get
and__set
) just likeItem
. N.B. This is a breaking change if you use meta on errors.DocumentInterface::getLinks()
now returns aLinks
instance instead of a plain array. If no links are present, it returnsnull
. All implementations have been updated to reflect these changes. N.B. This is a minor breaking change if you use links on documents.DocumentInterface::getMeta()
now returns aMeta
instance instead of a plain array. If no meta is present, it returnsnull
. All implementations have been updated to reflect these changes. N.B. This is a minor breaking change if you use meta on documents.DocumentInterface::getJsonapi()
now returns aJsonapi
instance instead of a plain array. If no jsonapi is present, it returnsnull
. All implementations have been updated to reflect these changes.- Parameters for
ItemInterface::setRelation()
have changed to include optionalLinks
andMeta
objects. JsonApi\ErrorsParser
,JsonApi\Hydrator
andJsonApi\Parser
have an extra dependency in their constructor. N.B. Make sure to add this dependency if you've overwrittenServiceProvider::registerParser
or construct theJsonApi\Parser
yourself.
- Removed
ErrorMeta
class in favor of genericMeta
class.
- Fixed parsing of JSON:API object in document.
This release includes changes to some interfaces #45. This is a breaking change if you use these interfaces in your own code.
- Added
OneRelationInterface
andManyRelationInterface
to differentiate between singular and plural relations. - Added documentation about
ItemDocumentBuilder
,ItemHydrator
andRepository
classes.
- Moved
setType
andgetType
fromRelationInterface
to a separate interface;TypedRelationInterface
. - Added type hints to
ItemInterface::setRelation
. - Added return type hint to
Item::hasAttribute
.
- Removed
RelationInterface
in favor ofOneRelationInterface
andManyRelationInterface
. - Removed
setId
andgetId
fromHasOneRelation
andMorphToRelation
. These operations should be performed on the included item. - Removed
setType
andgetType
from morph relations. Use regular relations if you want to set the type.
- Omit item from included when it has no attributes or relationships (only type and id)
N.B. This is a breaking change if you implement the
ItemInterface
yourself instead of using the suppliedItem
. - Make sure included is always a plain array so it is serialized as array
- Fix hydrating of HasOne relations by id using ItemHydrator #44
- Add
isSuccess
method to Document #40
- Add headers to request methods in
DocumentClientInterface
. N.B. This is a breaking change if you implement the interface yourself or extend theDocumentClient
. #34 Repository
doesn't throw exceptions anymore. #41 N.B. This is a breaking change if you catchDocumentNotFoundException
orDocumentTypeException
. If you would like the old behaviour, you can simply extend theRepository
and implement it yourself.- A HasOne or MorphTo relation do not set a
[relationship]_id
field on the parent when associating a related item. #42
- Removed obsolete
ItemDocumentSerializer
in favor ofJsonSerializable
. N.B. This is a breaking change if you use this class directly, construct theDocumentClient
yourself or have overwritten\Swis\JsonApi\Client\Providers\ServiceProvider::registerClients
. TheItemDocument
can now be serialized usingjson_encode
. - Removed obsolete
DocumentNotFoundException
andDocumentTypeException
. #41 N.B. This is a breaking change if you catch these exceptions.
- Do not fail on, but skip relationships without data #38
- Dissociating a related item now produces valid JSON #42
- Implement
JsonSerializable
inDocument
#32 - Add toArray to
DocumentInterface
andDocument
soCollectionDocument
andItemDocument
now share the same toArray method #32
- Omit 'type' attribute when filling attributes for a morph relationship #28
- Allow '0' as id in ItemDocumentBuilder #27
- Add the id when the item has one and not only when it is not new
- Added Laravel 5.7 support
- Added Laravel 5.6 support
- Travis now runs tests on all supported versions of Laravel
- Refactored name(space) of
\Swis\JsonApi\Client\Items\JenssegersItem
to\Swis\JsonApi\Client\Item
as we only have one item now.
EloquentItem
is removed because it had some limitations which could not be fixed without being too opinionated.NullItem
is removed in favor of simplynull
. This item was only used internally so this should not affect you.
- Do not add attributes to item when empty #20
- Reverted the behaviour of handling duplicate items back to what it was in <= 0.7.2. This change in behaviour was introduced in the last performance update (0.7.3). N.B. This change will only affect you if you parse documents with duplicate items, which violates the JSON API spec.
- Improved performance of JsonApi\Hydrator #18
- Fixed building the request with headers
- Corrected the path to the config file
The following classes are changed in some arguments and some method returns, if you extended or directly use \Swis\JsonApi\Client\JsonApi\Hydrator
or \Swis\JsonApi\Client\JsonApi\Parser
please check your code.
\Art4\JsonApiClient\Resource\CollectionInterface -> \Art4\JsonApiClient\ResourceCollectionInterface
\Art4\JsonApiClient\Resource\ItemInterface -> \Art4\JsonApiClient\ResourceItemInterface
\Art4\JsonApiClient\Resource\IdentifierCollection -> \Art4\JsonApiClient\ResourceIdentifierCollection
\Art4\JsonApiClient\Resource\Identifier -> \Art4\JsonApiClient\ResourceIdentifier
\Art4\JsonApiClient\Resource\Collection -> \Art4\JsonApiClient\ResourceCollection
- Added CHANGELOG.md
- Changed package name in composer.json
- Changed autodiscovery service provider in composer.json
- Added a proper README with instructions.
- Updated namespace to
Swis\JsonApi\Client
for consistency. - Split service provider binds so overwriting is easier.
- Extracted fixtures client to swisnl/php-http-fixture-client and swisnl/guzzle-fixture-handler
- Removed resources as it was redundant.
Refactored to use php-http/httpplug instead of Guzzle so the library doesn't depend on a specific http client implementation.
This does change how you customize the ServiceProvider, just include an adapter for the client you want to use and the library uses autodiscovery to find the correct adapter/client. It also uses a MessageFactory for creating Requests and Response objects.
So for example, if you want to use Guzzle, just composer require php-http/guzzle6-adapter
, and all should be swell.
In order to have a working mock client for testing you now need to include php-http/mock-client. Which is an easy way to mock requests.