Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cb5fabd
aliases are removed from the 1.1 spec
lode Aug 13, 2019
47d867f
allow adding local id if there is no normal id
lode Oct 20, 2020
f6481f4
make sure to pass along the local id when we normally pass the id
lode Oct 20, 2020
defb86d
easily set a json schema or other describing link to the document
lode Oct 20, 2020
e886ae4
support the new link 'native-meta' properties
lode Oct 20, 2020
b13f326
fix type checking
lode Oct 24, 2020
e1fd802
Merge branch 'master' into remove-aliasing
lode Apr 5, 2021
1ac504a
Merge branch 'remove-aliasing' into split-extension-and-profile
lode Apr 5, 2021
17eea59
add interface for extensions
lode Apr 5, 2021
760548f
add extension and profiles links in the jsonapi object and content-type
lode Apr 5, 2021
d9988db
allow to set extension members
lode Apr 5, 2021
8c79241
adjust example code for profiles and add for extensions
lode Apr 5, 2021
ab8a2d2
adjust tests
lode Apr 5, 2021
f69059b
adjust and add more tests
lode Apr 5, 2021
7722c17
add generic tests around extensions
lode Apr 5, 2021
5eaf3f5
add ready-to-use atomic operations extension
lode Apr 5, 2021
eca7637
test profile link appears in jsonapi object
lode Apr 5, 2021
0a9f38d
try to fix pre-php7.2 date constants
lode Apr 5, 2021
a980a46
cleanup
lode Apr 5, 2021
a513d3d
improve test coverage
lode Apr 5, 2021
e7fc8ff
improve test coverage
lode Apr 5, 2021
ad40d13
Merge branch 'remove-aliasing' into split-extension-and-profile
lode Apr 5, 2021
214a517
prevent using setUp as it has a BC break between php7.1 and 7.2
lode Apr 5, 2021
867a224
check for valid extension namespaces
lode Apr 5, 2021
7140bbe
Merge branch 'split-extension-and-profile' into remove-array-links
lode Apr 5, 2021
a68da0e
Merge branch 'main' into split-extension-and-profile
lode Apr 25, 2021
6aa605c
Merge branch 'main' into remove-aliasing
lode Apr 25, 2021
2a1a7a1
Merge branch 'main' into remove-array-links
lode Apr 25, 2021
e709233
Merge branch 'main' into new-link-properties
lode Apr 25, 2021
f8eb1df
Merge branch 'main' into described-by-at-root
lode Apr 25, 2021
f3d6d74
Merge branch 'main' into local-ids
lode Apr 25, 2021
260e411
Merge branch 'main' into remove-aliasing
lode May 14, 2021
5088604
Merge branch 'main' into local-ids
lode May 14, 2021
66d3949
Merge branch 'main' into described-by-at-root
lode May 14, 2021
06d4775
Merge branch 'main' into new-link-properties
lode May 14, 2021
74501c8
Merge branch 'remove-aliasing' into split-extension-and-profile
lode May 14, 2021
7efeb44
Merge branch 'main' into remove-aliasing
lode May 14, 2021
2e9cc5c
Merge branch 'main' into local-ids
lode May 14, 2021
a72bc22
Merge branch 'main' into described-by-at-root
lode May 14, 2021
ce2a31f
Merge branch 'main' into new-link-properties
lode May 14, 2021
8b9492e
Merge branch 'remove-aliasing' into split-extension-and-profile
lode May 14, 2021
9529521
explain when to use local id
lode May 14, 2021
a396260
test using local ids
lode May 14, 2021
65ebda7
test described by root link
lode May 14, 2021
3c3f011
fix adding link languages
lode May 15, 2021
7e53ef2
test emptyness
lode May 15, 2021
03f34f5
add some future validation ideas
lode May 15, 2021
353ef77
test the new link properties
lode May 15, 2021
51a9d27
be explicit about time
lode May 15, 2021
107c331
annotate new tests
lode May 15, 2021
68cd3e7
Merge branch 'remove-aliasing' into 2.3.0
lode May 15, 2021
07affd7
Merge branch 'local-ids' into 2.3.0
lode May 15, 2021
778b563
Merge branch 'described-by-at-root' into 2.3.0
lode May 15, 2021
2f23979
Merge branch 'new-link-properties' into 2.3.0
lode May 15, 2021
210ce0c
Merge branch '2.3.0' into split-extension-and-profile
lode May 15, 2021
8d21f97
Merge branch 'split-extension-and-profile' into 2.3.0
lode May 15, 2021
a767475
Merge branch '2.3.0' into remove-array-links
lode May 15, 2021
c01a21e
mark all methods using link arrays as deprecated
lode May 16, 2021
c168e95
adjust tests
lode May 16, 2021
9647198
keep code coverage for the deprecated method
lode May 16, 2021
11a2fc7
CS
lode May 16, 2021
9c64d6c
test
lode May 16, 2021
05b0b8e
Merge branch '2.3.0' into type-on-root-self
lode May 16, 2021
e02f986
add the extension/profile headers to the root self link
lode May 16, 2021
9c3143b
improve tests around applying extensions and profiles
lode May 16, 2021
9afcda0
test whether the extended self link works
lode May 16, 2021
d357322
re-use links initialization of the link manager
lode May 16, 2021
5351415
Merge pull request #62 from lode/remove-array-links
lode Aug 21, 2021
2675b65
Merge branch '2.3.0' into type-on-root-self
lode Aug 21, 2021
0073d5d
Merge branch 'main' into 2.3.0
lode Aug 21, 2021
8dc7855
Merge branch '2.3.0' into type-on-root-self
lode Aug 21, 2021
8332164
Merge pull request #67 from lode/type-on-root-self
lode Aug 21, 2021
30e6fb3
test extentions link for atomic operations in self link
lode Aug 22, 2021
bd98dd0
make it easy to set localids on resource documents as well
lode Aug 22, 2021
b08b5e3
make it easy to fetch local ids from request documents
lode Aug 22, 2021
aaf9ec9
Merge branch 'main' into 2.3.0
lode Aug 23, 2021
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
Prev Previous commit
Next Next commit
check for valid extension namespaces
  • Loading branch information
lode committed Apr 5, 2021
commit 867a2247abd9fab7936f7c4fddc87211559e2ed2
14 changes: 13 additions & 1 deletion src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace alsvanzelf\jsonapi;

use alsvanzelf\jsonapi\exceptions\DuplicateException;
use alsvanzelf\jsonapi\exceptions\Exception;
use alsvanzelf\jsonapi\exceptions\InputException;
use alsvanzelf\jsonapi\helpers\AtMemberManager;
Expand Down Expand Up @@ -190,9 +191,20 @@ public function unsetJsonapiObject() {
* @see https://jsonapi.org/extensions/#extensions
*
* @param ExtensionInterface $extension
*
* @throws Exception if namespace uses illegal characters
* @throws DuplicateException if namespace conflicts with another applied extension
*/
public function applyExtension(ExtensionInterface $extension) {
$this->extensions[] = $extension;
$namespace = $extension->getNamespace();
if (strlen($namespace) < 1 || preg_match('{[^a-zA-Z0-9]}', $namespace) === 1) {
throw new Exception('invalid namespace "'.$namespace.'"');
}
if (isset($this->extensions[$namespace])) {
throw new DuplicateException('an extension with namespace "'.$namespace.'" is already applied');
}

$this->extensions[$namespace] = $extension;

if ($this->jsonapi !== null) {
$this->jsonapi->addExtension($extension);
Expand Down
32 changes: 32 additions & 0 deletions tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace alsvanzelf\jsonapiTests;

use alsvanzelf\jsonapi\exceptions\DuplicateException;
use alsvanzelf\jsonapi\exceptions\Exception;
use alsvanzelf\jsonapi\exceptions\InputException;
use alsvanzelf\jsonapi\objects\LinkObject;
Expand Down Expand Up @@ -203,6 +204,37 @@ public function testApplyExtension_HappyPath() {
$this->assertSame('bar', $array['test:foo']);
}

public function testApplyExtension_InvalidNamespace() {
$document = new Document();
$extension = new TestExtension();
$extension->setNamespace('foo-bar');

$this->expectException(Exception::class);
$this->expectExceptionMessage('invalid namespace "foo-bar"');

$document->applyExtension($extension);
}

public function testApplyExtension_ConflictingNamespace() {
$document = new Document();

$extension1 = new TestExtension();
$extension1->setNamespace('foo');
$document->applyExtension($extension1);

$extension2 = new TestExtension();
$extension2->setNamespace('bar');
$document->applyExtension($extension2);

$extension3 = new TestExtension();
$extension3->setNamespace('foo');

$this->expectException(DuplicateException::class);
$this->expectExceptionMessage('an extension with namespace "foo" is already applied');

$document->applyExtension($extension3);
}

/**
* @group Profiles
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/SeparateProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testSendResponse_ContentTypeHeader() {
*/
public function testSendResponse_ContentTypeHeaderWithExtensions() {
$extension = new TestExtension();
$extension->setNamespace('one');
$extension->setOfficialLink('https://jsonapi.org');

$document = new Document();
Expand All @@ -86,6 +87,7 @@ public function testSendResponse_ContentTypeHeaderWithExtensions() {
$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL.'; ext="https://jsonapi.org"'], xdebug_get_headers());

$extension = new TestExtension();
$extension->setNamespace('two');
$extension->setOfficialLink('https://jsonapi.org/2');
$document->applyExtension($extension);

Expand Down