Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions examples/bootstrap_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use alsvanzelf\jsonapi\Document;
use alsvanzelf\jsonapi\ResourceDocument;
use alsvanzelf\jsonapi\helpers\ProfileAliasManager;
use alsvanzelf\jsonapi\interfaces\ProfileInterface;
use alsvanzelf\jsonapi\interfaces\ResourceInterface;

Expand Down Expand Up @@ -102,17 +101,13 @@ function getCurrentLocation() {
}
}

class ExampleVersionProfile extends ProfileAliasManager implements ProfileInterface {
class ExampleVersionProfile implements ProfileInterface {
/**
* the required methods (next to extending ProfileAliasManager)
* the required method
*/

public function getOfficialLink() {
return 'https://jsonapi.org/format/1.1/#profile-keywords-and-aliases';
}

public function getOfficialKeywords() {
return ['version'];
return 'https://jsonapi.org/format/1.1/#profile-keywords';
}

/**
Expand All @@ -121,10 +116,10 @@ public function getOfficialKeywords() {

public function setVersion(ResourceInterface $resource, $version) {
if ($resource instanceof ResourceDocument) {
$resource->addMeta($this->getKeyword('version'), $version, $level=Document::LEVEL_RESOURCE);
$resource->addMeta('version', $version, $level=Document::LEVEL_RESOURCE);
}
else {
$resource->addMeta($this->getKeyword('version'), $version);
$resource->addMeta('version', $version);
}
}
}
4 changes: 1 addition & 3 deletions examples/example_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

/**
* use a profile as extension to the document
*
* allowing to define aliases for the keywords to solve conflicts between different profiles
*/

$profile = new ExampleVersionProfile(['version' => 'ref']);
$profile = new ExampleVersionProfile();

$document = new ResourceDocument('user', 42);
$document->applyProfile($profile);
Expand Down
10 changes: 1 addition & 9 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
use alsvanzelf\jsonapi\interfaces\DocumentInterface;
use alsvanzelf\jsonapi\interfaces\ProfileInterface;
use alsvanzelf\jsonapi\objects\JsonapiObject;
use alsvanzelf\jsonapi\objects\LinkObject;
use alsvanzelf\jsonapi\objects\LinksObject;
use alsvanzelf\jsonapi\objects\MetaObject;
use alsvanzelf\jsonapi\objects\ProfileLinkObject;

/**
* @see ResourceDocument, CollectionDocument, ErrorsDocument or MetaDocument
Expand Down Expand Up @@ -196,13 +194,7 @@ public function applyProfile(ProfileInterface $profile) {
$this->setLinksObject(new LinksObject());
}

$link = $profile->getAliasedLink();
if ($link instanceof LinkObject) {
$this->links->appendLinkObject('profile', $link);
}
else {
$this->links->append('profile', $link);
}
$this->links->append('profile', $profile->getOfficialLink());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use alsvanzelf\jsonapi\interfaces\ObjectInterface;
use alsvanzelf\jsonapi\interfaces\ProfileInterface;
use alsvanzelf\jsonapi\objects\LinkObject;

/**
* @internal
Expand Down Expand Up @@ -48,8 +47,7 @@ public static function mergeProfilesInContentType($contentType, array $profiles)

$profileLinks = [];
foreach ($profiles as $profile) {
$link = $profile->getAliasedLink();
$profileLinks[] = ($link instanceof LinkObject) ? $link->toArray()['href'] : $link;
$profileLinks[] = $profile->getOfficialLink();
}
$profileLinks = implode(' ', $profileLinks);

Expand Down
80 changes: 0 additions & 80 deletions src/helpers/ProfileAliasManager.php

This file was deleted.

52 changes: 0 additions & 52 deletions src/interfaces/ProfileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,7 @@

namespace alsvanzelf\jsonapi\interfaces;

use alsvanzelf\jsonapi\exceptions\InputException;
use alsvanzelf\jsonapi\objects\LinkObject;

/**
* @see ProfileAliasManager which implement most of the methods
*/
interface ProfileInterface {
/**
* get a profile with its aliases to keywords of the profile
*
* having this in the constructor makes sure the aliases are used from the start
*
* @param array $aliases optional mapping keywords to aliases
*
* @throws InputException if the alias is not different from the keyword
* @throws InputException if the keyword is not known to the profile
* @throws InputException if the alias is not a valid member name
*/
public function __construct(array $aliases=[]);

/**
* get the keyword or current alias based on the official keyword from the profile
*
* e.g. for a profile defining an official keyword 'version', this would return 'version'
* or if ->alias('version', 'v') was called before, this would return 'v'
*
* @param string $keyword
* @return string
*
* @throws InputException if the keyword is not known to the profile
*/
public function getKeyword($keyword);

/**
* returns an array of official keywords this profile defines
*
* @internal
*
* @return string[]
*/
public function getOfficialKeywords();

/**
* the unique link identifying and describing the profile
*
Expand All @@ -52,15 +11,4 @@ public function getOfficialKeywords();
* @return string
*/
public function getOfficialLink();

/**
* get the official link, or a LinkObject with the link and its aliases
*
* optionally also contains the aliases applied
*
* @internal
*
* @return LinkObject|string
*/
public function getAliasedLink();
}
47 changes: 0 additions & 47 deletions src/objects/ProfileLinkObject.php

This file was deleted.

30 changes: 17 additions & 13 deletions src/profiles/CursorPaginationProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use alsvanzelf\jsonapi\Document;
use alsvanzelf\jsonapi\ResourceDocument;
use alsvanzelf\jsonapi\helpers\ProfileAliasManager;
use alsvanzelf\jsonapi\interfaces\PaginableInterface;
use alsvanzelf\jsonapi\interfaces\ProfileInterface;
use alsvanzelf\jsonapi\interfaces\ResourceInterface;
Expand Down Expand Up @@ -44,7 +43,7 @@
* - {@see get*ErrorObject} to generate ErrorObjects for specific error cases
* - {@see generatePreviousLink} {@see generateNextLink} to apply the links manually
*/
class CursorPaginationProfile extends ProfileAliasManager implements ProfileInterface {
class CursorPaginationProfile implements ProfileInterface {
/**
* human api
*/
Expand Down Expand Up @@ -115,7 +114,7 @@ public function setCount(PaginableInterface $paginable, $exactTotal=null, $bestG
* @return string
*/
public function generatePreviousLink($baseOrCurrentUrl, $beforeCursor) {
return $this->setQueryParameter($baseOrCurrentUrl, $this->getKeyword('page').'[before]', $beforeCursor);
return $this->setQueryParameter($baseOrCurrentUrl, 'page[before]', $beforeCursor);
}

/**
Expand All @@ -126,7 +125,7 @@ public function generatePreviousLink($baseOrCurrentUrl, $beforeCursor) {
* @return string
*/
public function generateNextLink($baseOrCurrentUrl, $afterCursor) {
return $this->setQueryParameter($baseOrCurrentUrl, $this->getKeyword('page').'[after]', $afterCursor);
return $this->setQueryParameter($baseOrCurrentUrl, 'page[after]', $afterCursor);
}

/**
Expand Down Expand Up @@ -192,10 +191,10 @@ public function setItemMeta(ResourceInterface $resource, $cursor) {
];

if ($resource instanceof ResourceDocument) {
$resource->addMeta($this->getKeyword('page'), $metadata, $level=Document::LEVEL_RESOURCE);
$resource->addMeta('page', $metadata, $level=Document::LEVEL_RESOURCE);
}
else {
$resource->addMeta($this->getKeyword('page'), $metadata);
$resource->addMeta('page', $metadata);
}
}

Expand Down Expand Up @@ -229,7 +228,7 @@ public function setPaginationMeta(PaginableInterface $paginable, $exactTotal=nul
$metadata['rangeTruncated'] = $rangeIsTruncated;
}

$paginable->addMeta($this->getKeyword('page'), $metadata);
$paginable->addMeta('page', $metadata);
}

/**
Expand Down Expand Up @@ -280,9 +279,9 @@ public function getUnsupportedSortErrorObject($genericTitle=null, $specificDetai
public function getMaxPageSizeExceededErrorObject($maxSize, $genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Max page size exceeded');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/max-size-exceeded');
$errorObject->blameQueryParameter($this->getKeyword('page').'[size]');
$errorObject->blameQueryParameter('page[size]');
$errorObject->setHttpStatusCode(400);
$errorObject->addMeta($this->getKeyword('page'), $value=['maxSize' => $maxSize]);
$errorObject->addMeta('page', $value=['maxSize' => $maxSize]);

if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
Expand All @@ -302,7 +301,7 @@ public function getMaxPageSizeExceededErrorObject($maxSize, $genericTitle=null,
* - /errors/0/title optional
* - /errors/0/detail optional
*
* @param int $queryParameter e.g. 'sort' or 'page[size]', aliasing should already be done using {@see getKeyword}
* @param int $queryParameter e.g. 'sort' or 'page[size]'
* @param string $typeLink optional
* @param string $genericTitle optional, e.g. 'Invalid Parameter.'
* @param string $specificDetails optional, e.g. 'page[size] must be a positive integer; got 0'
Expand Down Expand Up @@ -394,9 +393,14 @@ public function getOfficialLink() {
}

/**
* @inheritDoc
* returns the keyword without aliasing
*
* @deprecated since aliasing was removed from the profiles spec
*
* @param string $keyword
* @return string
*/
public function getOfficialKeywords() {
return ['page'];
public function getKeyword($keyword) {
return $keyword;
}
}
Loading