forked from codeconsortium/CCDNComponentBBCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
121 lines (100 loc) · 2.73 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of the CCDNComponent BBCode
*
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/>
*
* Available on github <http://www.github.com/codeconsortium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CCDNComponent\BBCode;
/**
*
* @category CCDNComponent
* @package BBCode
*
* @author Reece Fowell <reece@codeconsortium.com>
* @license http://opensource.org/licenses/MIT MIT
* @version Release: 2.0
* @link https://github.com/codeconsortium/CCDNComponentBBCode
*
*/
class Bootstrap
{
/**
*
* @access private
*/
protected $tableContainer;
/**
*
* @access protected
*/
protected $scanner;
/**
*
* @access protected
*/
protected $lexer;
/**
*
* @access protected
*/
protected $parser;
/**
*
* @access private
* @param LexemeTable $lexemeTable
* @param Scanner $scanner
* @param Lexer $lexer
* @param Parser $parser
*/
public function __construct($tableContainer = null, $scanner = null, $lexer = null, $parser = null)
{
if (null == $tableContainer) {
$tableContainer = new \CCDNComponent\BBCode\Engine\Table\TableContainer();
}
if (null == $scanner) {
$scanner = new \CCDNComponent\BBCode\Engine\Scanner();
}
if (null == $lexer) {
$lexer = new \CCDNComponent\BBCode\Engine\Lexer();
}
if (null == $parser) {
$parser = new \CCDNComponent\BBCode\Engine\Parser();
}
$this->tableContainer = $tableContainer;
$this->scanner = $scanner;
$this->lexer = $lexer;
$this->parser = $parser;
}
/**
*
* @access public
* @return string $html
*/
public function process($input, $tableName = null)
{
if ($tableName == null) {
$tableName = 'default';
}
$table = $this->getTableACL($tableName);
if ($table->isParserEnabled()) {
// Split input string by likely tag format.
$scanChunks = $this->scanner->process($input, $table);
// Create a symbol tree via the lexer.
$symbolTree = $this->lexer->process($scanChunks, $table);
// Parse the lexed symbol tree to get an HTML output.
$html = $this->parser->process($symbolTree, $table);
} else {
$html = '<pre>' . htmlentities($input, ENT_QUOTES, 'UTF-8') . '</pre>';
}
return $html;
}
public function getTableACL($tableName)
{
return $this->tableContainer->getTableACL($tableName);
}
}