Skip to content

Commit

Permalink
Remove obsolete ItemDocumentSerializer in favor of JsonSerializable
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Dec 21, 2018
1 parent 07b2d73 commit 5715478
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 61 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Removed

* Removed obsolete `ItemDocumentSerializer` in favor of `JsonSerializable`.
N.B. This is a breaking change if you use this class directly, construct the `DocumentClient` yourself or have overwritten `\Swis\JsonApi\Client\Providers\ServiceProvider::registerClients`. The `ItemDocument` can now be serialized using its `jsonSerialize` method.

## [0.11.0] - 2018-12-21

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Swis\JsonApi\Client\Interfaces\DataInterface;
use Swis\JsonApi\Client\Interfaces\DocumentInterface;

class Document implements DocumentInterface, \JsonSerializable
class Document implements DocumentInterface
{
/**
* @var \Swis\JsonApi\Client\Interfaces\DataInterface
Expand Down
16 changes: 3 additions & 13 deletions src/DocumentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,18 @@ class DocumentClient implements DocumentClientInterface
*/
private $client;

/**
* @var \Swis\JsonApi\Client\ItemDocumentSerializer
*/
private $itemDocumentSerializer;

/**
* @var \Swis\JsonApi\Client\Interfaces\ParserInterface
*/
private $parser;

/**
* @param \Swis\JsonApi\Client\Interfaces\ClientInterface $client
* @param \Swis\JsonApi\Client\ItemDocumentSerializer $itemDocumentSerializer
* @param \Swis\JsonApi\Client\Interfaces\ParserInterface $parser
*/
public function __construct(
ClientInterface $client,
ItemDocumentSerializer $itemDocumentSerializer,
ParserInterface $parser
) {
public function __construct(ClientInterface $client, ParserInterface $parser)
{
$this->client = $client;
$this->itemDocumentSerializer = $itemDocumentSerializer;
$this->parser = $parser;
}

Expand Down Expand Up @@ -106,7 +96,7 @@ public function delete(string $endpoint): DocumentInterface
*/
protected function prepareBody(ItemDocumentInterface $body): string
{
return $this->sanitizeJson($this->itemDocumentSerializer->serialize($body));
return $this->sanitizeJson($body->jsonSerialize());

This comment has been minimized.

Copy link
@Fivell

Fivell Dec 26, 2018

Contributor

@JaZo can u please clarify, according to codebase

$body->jsonSerialize()

returns mixed/array data type

but sanitizeJson accepts string

This comment has been minimized.

Copy link
@Fivell

Fivell Dec 26, 2018

Contributor

@JaZo maybe json_encode should be called here which calls jsonSerialize internally?

This comment has been minimized.

Copy link
@JaZo

JaZo Jan 7, 2019

Author Member

@Fivell, you're absolutely right, thanks!

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Swis\JsonApi\Client\Collection;
use Swis\JsonApi\Client\Errors\ErrorCollection;

interface DocumentInterface
interface DocumentInterface extends \JsonSerializable
{
/**
* @return \Swis\JsonApi\Client\Interfaces\DataInterface
Expand Down
15 changes: 15 additions & 0 deletions src/InvalidResponseDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public function getJsonapi()
return null;
}

/**
* Specify data which should be serialized to JSON.
*
* @see http://php.net/manual/en/jsonserializable.jsonserialize.php
*
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource
*
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->toArray();
}

/**
* @return array
*/
Expand Down
44 changes: 0 additions & 44 deletions src/ItemDocumentSerializer.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Swis\JsonApi\Client\Interfaces\DocumentClientInterface as ApiDocumentClientInterface;
use Swis\JsonApi\Client\Interfaces\ParserInterface;
use Swis\JsonApi\Client\Interfaces\TypeMapperInterface;
use Swis\JsonApi\Client\ItemDocumentSerializer;
use Swis\JsonApi\Client\JsonApi\ErrorsParser;
use Swis\JsonApi\Client\JsonApi\Hydrator;
use Swis\JsonApi\Client\JsonApi\Parser;
Expand Down Expand Up @@ -84,7 +83,6 @@ function () {
function (Application $app) {
return new ApiDocumentClient(
$app->make(ApiClientInterface::class),
new ItemDocumentSerializer(),
$app->make(ParserInterface::class)
);
}
Expand Down

0 comments on commit 5715478

Please sign in to comment.