diff --git a/generator/templates/twig/Graph.php.twig b/generator/templates/twig/Graph.php.twig
index 3da706434..bb6bfa2b3 100644
--- a/generator/templates/twig/Graph.php.twig
+++ b/generator/templates/twig/Graph.php.twig
@@ -30,7 +30,7 @@ class Graph implements Type, ArrayAccess, JsonSerializable
/** @var string|null */
protected $context;
- public function __construct(?string $context = null)
+ public function __construct(string|array|null $context = null)
{
$this->context = $context;
}
@@ -176,7 +176,7 @@ class Graph implements Type, ArrayAccess, JsonSerializable
{
// show all
if ($identifier === null) {
- $this->hidden[$type] = false;
+ unset($this->hidden[$type]);
return $this;
}
@@ -270,7 +270,7 @@ class Graph implements Type, ArrayAccess, JsonSerializable
return $this->nodes;
}
- public function getContext(): string
+ public function getContext(): string|array
{
return $this->context ?? 'https://schema.org';
}
diff --git a/src/Graph.php b/src/Graph.php
index 401e0ee67..4cbe4092e 100644
--- a/src/Graph.php
+++ b/src/Graph.php
@@ -912,7 +912,7 @@ class Graph implements Type, ArrayAccess, JsonSerializable
/** @var string|null */
protected $context;
- public function __construct(?string $context = null)
+ public function __construct(string|array|null $context = null)
{
$this->context = $context;
}
@@ -1058,7 +1058,7 @@ public function show(string $type, ?string $identifier = self::IDENTIFIER_DEFAUL
{
// show all
if ($identifier === null) {
- $this->hidden[$type] = false;
+ unset($this->hidden[$type]);
return $this;
}
@@ -1152,7 +1152,7 @@ public function getNodes(): array
return $this->nodes;
}
- public function getContext(): string
+ public function getContext(): string|array
{
return $this->context ?? 'https://schema.org';
}
diff --git a/tests/GraphTest.php b/tests/GraphTest.php
index 9bebc1df5..86cde270e 100644
--- a/tests/GraphTest.php
+++ b/tests/GraphTest.php
@@ -223,5 +223,26 @@
it('can be initialized with different context', function () {
$graph = new Graph('https://foobar.com');
+
expect($graph->getContext())->toBe('https://foobar.com');
+
+ expect($graph->toScript())->toBe(
+ ''
+ );
+});
+
+it('can be initialized with complex context', function () {
+ $graph = new Graph([
+ '@vocab' => 'https://schema.org/',
+ '@base' => 'https://domain.com/',
+ ]);
+
+ expect($graph->getContext())->toBe([
+ '@vocab' => 'https://schema.org/',
+ '@base' => 'https://domain.com/',
+ ]);
+
+ expect($graph->toScript())->toBe(
+ ''
+ );
});