nouveau-theatre-de-besancon/vendor/spatie/schema-org/generator/Parser/JsonLdParser.php
2024-09-19 07:36:53 +02:00

23 lines
592 B
PHP

<?php
namespace Spatie\SchemaOrg\Generator\Parser;
use Illuminate\Support\Collection;
class JsonLdParser
{
protected Collection $jsonLdGraph;
public function __construct(string $rawJsonLd)
{
$parsedJson = json_decode($rawJsonLd, true);
$this->jsonLdGraph = collect($parsedJson['@graph']);
}
public function filter(string $selector): Collection
{
return $this->jsonLdGraph->filter(static function ($schema) use ($selector): bool {
return array_key_exists('@type', $schema) && $schema['@type'] === $selector;
});
}
}