1<?php
2
3declare(strict_types=1);
4
5/*
6 * This is part of the league/commonmark package.
7 *
8 * (c) Martin Hasoň <martin.hason@gmail.com>
9 * (c) Webuni s.r.o. <info@webuni.cz>
10 * (c) Colin O'Dell <colinodell@gmail.com>
11 *
12 * For the full copyright and license information, please view the LICENSE
13 * file that was distributed with this source code.
14 */
15
16namespace League\CommonMark\Extension\Table;
17
18use League\CommonMark\Block\Element\AbstractBlock;
19use League\CommonMark\Block\Element\AbstractStringContainerBlock;
20use League\CommonMark\Block\Element\InlineContainerInterface;
21use League\CommonMark\ContextInterface;
22use League\CommonMark\Cursor;
23
24final class Table extends AbstractStringContainerBlock implements InlineContainerInterface
25{
26    /** @var TableSection */
27    private $head;
28    /** @var TableSection */
29    private $body;
30    /** @var \Closure */
31    private $parser;
32
33    public function __construct(\Closure $parser)
34    {
35        parent::__construct();
36        $this->appendChild($this->head = new TableSection(TableSection::TYPE_HEAD));
37        $this->appendChild($this->body = new TableSection(TableSection::TYPE_BODY));
38        $this->parser = $parser;
39    }
40
41    public function canContain(AbstractBlock $block): bool
42    {
43        return $block instanceof TableSection;
44    }
45
46    public function isCode(): bool
47    {
48        return false;
49    }
50
51    public function getHead(): TableSection
52    {
53        return $this->head;
54    }
55
56    public function getBody(): TableSection
57    {
58        return $this->body;
59    }
60
61    public function matchesNextLine(Cursor $cursor): bool
62    {
63        return call_user_func($this->parser, $cursor, $this);
64    }
65
66    public function handleRemainingContents(ContextInterface $context, Cursor $cursor): void
67    {
68    }
69}
70