4242 public static function parse (string $ data , ?array $ tools = null , array $ allowedTags = []): array
4343 {
4444 try {
45+ /** @var array{time: int, blocks: array<array{id: string, type: string, data: mixed}>} $blocks */
4546 $ blocks = json_decode ($ data , true , flags: JSON_THROW_ON_ERROR );
4647 $ mapper = fn (array $ block ): Block => self ::create ($ block , self ::getAllowedTags ($ block , $ allowedTags ));
4748
@@ -56,10 +57,10 @@ public static function parse(string $data, ?array $tools = null, array $allowedT
5657 }
5758 }
5859
59- private static function filter (array $ data , array $ tools ): array
60- {
61- return array_filter ($ data , fn (array $ block ): bool => isset ($ tools [$ block ['type ' ]]));
62- }
60+ // private static function filter(array $data, array $tools): array
61+ // {
62+ // return array_filter($data, fn (array $block): bool => isset($tools[$block['type']]));
63+ // }
6364
6465 /**
6566 * @throws EditorException
@@ -83,25 +84,29 @@ private static function create(array $data, array $allowedTags = []): Block
8384 'raw ' => Raw::create ($ data , $ allowedTags ),
8485 'table ' => Table::create ($ data , $ allowedTags ),
8586 'warning ' => Warning::create ($ data , $ allowedTags ),
87+ default => throw new EditorException (sprintf ('Block type %s not supported ' , $ data ['type ' ])),
8688 };
8789 } catch (\Throwable $ e ) {
8890 throw new EditorException ($ e ->getMessage (), previous: $ e );
8991 }
9092 }
9193
92- private static function getAllowedTags (mixed $ block , array $ allowedTags ): array
94+ private static function getAllowedTags (array $ block , array $ allowedTags ): array
9395 {
9496 Assert::keyExists ($ block , 'type ' );
9597
9698 return $ allowedTags [$ block ['type ' ]] ?? [];
9799 }
98100
99- private static function getSchema (string $ schema ): array
100- {
101- $ filename = sprintf ('%s/schemas/%s.schema.json ' , dirname (__DIR__ ), $ schema );
102- $ content = file_get_contents ($ filename );
103- Assert::string ($ content , sprintf ('Schema for block type %s not found ' , $ schema ));
104-
105- return json_decode ($ content , true );
106- }
101+ // private static function getSchema(string $schema): array
102+ // {
103+ // $filename = sprintf('%s/schemas/%s.schema.json', dirname(__DIR__), $schema);
104+ // $content = file_get_contents($filename);
105+ // Assert::string($content, sprintf('Schema for block type %s not found', $schema));
106+ //
107+ // /** @var array $schema */
108+ // $schema = json_decode($content, true);
109+ //
110+ // return $schema;
111+ // }
107112}
0 commit comments