diff --git a/Exception/JsonLdException.php b/Exception/JsonLdException.php index 6638301..0b34090 100644 --- a/Exception/JsonLdException.php +++ b/Exception/JsonLdException.php @@ -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. */ diff --git a/Processor.php b/Processor.php index 1c1ff3e..86e7d10 100644 --- a/Processor.php +++ b/Processor.php @@ -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]);