Skip to content

Commit b300c3c

Browse files
committed
Add interfaces for Gutenberg blocks parsing
1 parent ed8d800 commit b300c3c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [[*next-version*]] - YYYY-MM-DD
8+
### Added
9+
- Interfaces for Gutenberg blocks parsing.
810

911
## [0.1.0-alpha1] - 2021-03-05
1012
Initial version.

src/Gutenberg/BlockInterface.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WpOop\WordPress\Gutenberg;
6+
7+
/**
8+
* The interface for Gutenberg block data.
9+
*/
10+
interface BlockInterface
11+
{
12+
/**
13+
* Returns name of the block, such as 'core/paragraph'.
14+
* @return string
15+
*/
16+
public function getBlockName(): string;
17+
18+
/**
19+
* Returns block attributes.
20+
* @return array<string, mixed>
21+
*/
22+
public function getAttributes(): array;
23+
24+
/**
25+
* Returns inner blocks (for example, used in the Columns block).
26+
* @return BlockInterface[]
27+
*/
28+
public function getInnerBlocks(): array;
29+
30+
/**
31+
* Returns resultant HTML.
32+
* @return string
33+
*/
34+
public function getInnerHtml(): string;
35+
36+
/**
37+
* Returns list of string fragments and null markers where inner blocks were found.
38+
* @return array<?string>
39+
*/
40+
public function getInnerContent(): array;
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WpOop\WordPress\Gutenberg;
6+
7+
/**
8+
* The interface for parsing Gutenberg blocks.
9+
*/
10+
interface BlockParserInterface
11+
{
12+
/**
13+
* @param string $postContent Content of a WP post (e.g. WP_Post post_content).
14+
* @return BlockInterface[]
15+
*/
16+
public function parseBlock(string $postContent): array;
17+
}

0 commit comments

Comments
 (0)