Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @protected & @version #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions Exception/JsonLdException.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ class JsonLdException extends \RuntimeException
*/
const INVALID_DEFAULT_LANGUAGE = "invalid default language";

/**
* The protected value is not a bool and thus invalid.
*/
const INVALID_PROTECTED = "invalid protected value";

/**
* The version is not numeric and thus invalid.
*/
const INVALID_VERSION = "invalid version";

/**
* A keyword redefinition has been detected.
*/
Expand Down
26 changes: 26 additions & 0 deletions Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,32 @@ public function processContext($loclctx, &$activectx, $remotectxs = array())
unset($context->{'@language'});
}

if (property_exists($context, '@protected')) {
if ((null !== $context->{'@protected'}) && (false === is_bool($context->{'@protected'}))) {
throw new JsonLdException(
JsonLdException::INVALID_PROTECTED,
'The value of @protected must be a bool.',
$context
);
}

$activectx['@protected'] = $context->{'@protected'};
unset($context->{'@protected'});
}

if (property_exists($context, '@version')) {
if ((null !== $context->{'@version'}) && (false === is_numeric($context->{'@version'}))) {
throw new JsonLdException(
JsonLdException::INVALID_VERSION,
'The value of @version must be a float or integer.',
$context
);
}

$activectx['@version'] = $context->{'@version'};
unset($context->{'@version'});
}

foreach ($context as $key => $value) {
unset($context->{$key});
unset($activectx[$key]);
Expand Down