Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JsonApi resource and collection for empty result
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace hiapi\jsonApi; | ||
|
||
use WoohooLabs\Yin\JsonApi\Schema\Document\AbstractCollectionDocument; | ||
use WoohooLabs\Yin\JsonApi\Schema\JsonApiObject; | ||
use WoohooLabs\Yin\JsonApi\Schema\Link\DocumentLinks; | ||
|
||
/** | ||
* Empty collection to return empty array (nothin is found). | ||
* | ||
* @author Andrii Vasyliev <sol@hiqdev.com> | ||
*/ | ||
final class EmptyCollectionDocument extends AbstractCollectionDocument | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(new EmptyResource); | ||
} | ||
|
||
public function getJsonApi(): ?JsonApiObject | ||
{ | ||
return new JsonApiObject('1.1'); | ||
} | ||
|
||
public function getMeta(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getLinks(): ?DocumentLinks | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace hiapi\jsonApi; | ||
|
||
use WoohooLabs\Yin\JsonApi\Schema\Link\ResourceLinks; | ||
use WoohooLabs\Yin\JsonApi\Schema\Resource\AbstractResource; | ||
|
||
final class EmptyResource extends AbstractResource | ||
{ | ||
public function getType($entity): string | ||
{ | ||
return 'empty'; | ||
} | ||
|
||
public function getId($entity): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getMeta($entity): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getLinks($entity): ?ResourceLinks | ||
{ | ||
return null; | ||
} | ||
|
||
public function getAttributes($entity): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getDefaultIncludedRelationships($entity): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getRelationships($entity): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters