Completed
Push — master ( 8cebaa...0cc554 )
by Josh
03:33
created

Configurator::escapeAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\Escaper;
9
10
use s9e\TextFormatter\Plugins\ConfiguratorBase;
11
12
class Configurator extends ConfiguratorBase
13
{
14
	/**
15
	* {@inheritdoc}
16
	*/
17
	protected $quickMatch = '\\';
18
19
	/**
20
	* @var string Regexp that matches one backslash followed by the escape character
21
	*/
22
	protected $regexp;
23
24
	/**
25
	* @var string Name of the tag used by this plugin
26
	*/
27
	protected $tagName = 'ESC';
28
29
	/**
30
	* Set whether any Unicode character should be escapable, or limit to some ASCII symbols
31
	*
32
	* @param  bool $bool Whether any Unicode character should be escapable
33
	* @return void
34
	*/
35
	public function escapeAll($bool = true)
36
	{
37
		$this->regexp = ($bool) ? '/\\\\./su' : '/\\\\[-!#()*+.:<>@[\\\\\\]^_`{|}]/';
38
	}
39
40
	/**
41
	* {@inheritdoc}
42
	*/
43
	protected function setUp()
44
	{
45
		// Set the default regexp
46
		$this->escapeAll(false);
47
48
		// Create the tag
49
		$tag = $this->configurator->tags->add($this->tagName);
50
		$tag->rules->disableAutoLineBreaks();
51
		$tag->rules->ignoreTags();
52
		$tag->rules->preventLineBreaks();
53
		$tag->template = '<xsl:apply-templates/>';
54
	}
55
}