wproot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/bin/wproot +7 -0
- data/lib/wproot.rb +11 -0
- data/lib/wproot/cli.rb +35 -0
- data/lib/wproot/compass.rb +15 -0
- data/lib/wproot/haml.rb +15 -0
- data/lib/wproot/version.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/wproot_spec.rb +59 -0
- data/vendor/HamlPHP.php +7 -0
- data/vendor/HamlPHP/.gitignore +6 -0
- data/vendor/HamlPHP/MIT-LICENSE +22 -0
- data/vendor/HamlPHP/README.mkd +39 -0
- data/vendor/HamlPHP/src/HamlPHP/CommentNode.php +92 -0
- data/vendor/HamlPHP/src/HamlPHP/Compiler.php +109 -0
- data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/ContentEvaluator.php +16 -0
- data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/DefaultContentEvaluator.php +22 -0
- data/vendor/HamlPHP/src/HamlPHP/DoctypeNode.php +47 -0
- data/vendor/HamlPHP/src/HamlPHP/Element.php +618 -0
- data/vendor/HamlPHP/src/HamlPHP/ElementNode.php +222 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/CssFilter.php +31 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/Filter.php +18 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/FilterContainer.php +34 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/JavascriptFilter.php +29 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/PhpFilter.php +24 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/PlainFilter.php +46 -0
- data/vendor/HamlPHP/src/HamlPHP/FilterNode.php +29 -0
- data/vendor/HamlPHP/src/HamlPHP/HamlNode.php +75 -0
- data/vendor/HamlPHP/src/HamlPHP/HamlPHP.php +191 -0
- data/vendor/HamlPHP/src/HamlPHP/Helpers.php +136 -0
- data/vendor/HamlPHP/src/HamlPHP/Interpolation.php +71 -0
- data/vendor/HamlPHP/src/HamlPHP/NodeFactory.php +80 -0
- data/vendor/HamlPHP/src/HamlPHP/RootNode.php +133 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/DontEvaluateStorage.php +68 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/FileStorage.php +74 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/Storage.php +24 -0
- data/vendor/HamlPHP/src/HamlPHP/TagNode.php +125 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/BaseException.php +340 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/BaseObject.php +94 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/StringScanner.php +989 -0
- data/wproot.gemspec +21 -0
- metadata +126 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class RootNode
|
4
|
+
{
|
5
|
+
private $_children;
|
6
|
+
private $_indentation;
|
7
|
+
private $_childrenCount;
|
8
|
+
private $_parent;
|
9
|
+
private $_compiler;
|
10
|
+
private $_lineNumber;
|
11
|
+
|
12
|
+
public function __construct()
|
13
|
+
{
|
14
|
+
$this->_children = array();
|
15
|
+
$this->_indentation = -1;
|
16
|
+
$this->_childrenCount = 0;
|
17
|
+
$this->_lineNumber = 0;
|
18
|
+
$this->_parent = null;
|
19
|
+
}
|
20
|
+
|
21
|
+
public function setParent(RootNode $node)
|
22
|
+
{
|
23
|
+
$this->_parent = $node;
|
24
|
+
}
|
25
|
+
|
26
|
+
public function getParent()
|
27
|
+
{
|
28
|
+
return $this->_parent;
|
29
|
+
}
|
30
|
+
|
31
|
+
public function hasParent()
|
32
|
+
{
|
33
|
+
return $this->_parent !== null;
|
34
|
+
}
|
35
|
+
|
36
|
+
public function setLineNumber($lineNumber)
|
37
|
+
{
|
38
|
+
$this->_lineNumber = $lineNumber;
|
39
|
+
}
|
40
|
+
|
41
|
+
public function getLineNumber()
|
42
|
+
{
|
43
|
+
return $this->_lineNumber;
|
44
|
+
}
|
45
|
+
|
46
|
+
public function setCompiler(Compiler $compiler)
|
47
|
+
{
|
48
|
+
$this->_compiler = $compiler;
|
49
|
+
}
|
50
|
+
|
51
|
+
public function getCompiler()
|
52
|
+
{
|
53
|
+
return $this->_compiler;
|
54
|
+
}
|
55
|
+
|
56
|
+
public function setIndentationLevel($level)
|
57
|
+
{
|
58
|
+
$this->_indentation = $level;
|
59
|
+
}
|
60
|
+
|
61
|
+
public function getIndentationLevel()
|
62
|
+
{
|
63
|
+
return $this->_indentation;
|
64
|
+
}
|
65
|
+
|
66
|
+
public function addNode(RootNode $node = null)
|
67
|
+
{
|
68
|
+
if ($node === null) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
|
72
|
+
if ($this->shouldGoInsideLastNode($node)) {
|
73
|
+
$lastNode = $this->_children[$this->_childrenCount - 1];
|
74
|
+
$lastNode->addNode($node);
|
75
|
+
} else {
|
76
|
+
$node->setParent($this);
|
77
|
+
$this->_children[] = $node;
|
78
|
+
++$this->_childrenCount;
|
79
|
+
return true;
|
80
|
+
}
|
81
|
+
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
|
85
|
+
protected function shouldGoInsideLastNode($node)
|
86
|
+
{
|
87
|
+
if ($this->_childrenCount == 0) {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
|
91
|
+
$lastNode = $this->_children[$this->_childrenCount - 1];
|
92
|
+
|
93
|
+
return $node->getIndentationLevel() > $lastNode->getIndentationLevel()
|
94
|
+
|| $lastNode->shouldContain($node);
|
95
|
+
}
|
96
|
+
|
97
|
+
public function getChildren()
|
98
|
+
{
|
99
|
+
return $this->_children;
|
100
|
+
}
|
101
|
+
|
102
|
+
public function getChildrenCount()
|
103
|
+
{
|
104
|
+
return $this->_childrenCount;
|
105
|
+
}
|
106
|
+
|
107
|
+
public function hasChildren()
|
108
|
+
{
|
109
|
+
return $this->_childrenCount > 0;
|
110
|
+
}
|
111
|
+
|
112
|
+
public function renderChildren()
|
113
|
+
{
|
114
|
+
$output = '';
|
115
|
+
|
116
|
+
for ($i = 0; $i < $this->_childrenCount; ++$i) {
|
117
|
+
$res = $this->_children[$i]->render();
|
118
|
+
$output .= $res;
|
119
|
+
}
|
120
|
+
|
121
|
+
return $output;
|
122
|
+
}
|
123
|
+
|
124
|
+
public function render()
|
125
|
+
{
|
126
|
+
return $this->renderChildren();
|
127
|
+
}
|
128
|
+
|
129
|
+
public function shouldContain($node)
|
130
|
+
{
|
131
|
+
return false;
|
132
|
+
}
|
133
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class DontEvaluateStorage implements Storage, ContentEvaluator
|
4
|
+
{
|
5
|
+
protected $_path = null;
|
6
|
+
protected $_extension = null;
|
7
|
+
|
8
|
+
public function __construct($cachePath, $extension = '.cached.php')
|
9
|
+
{
|
10
|
+
$this->_path = $cachePath;
|
11
|
+
$this->_extension = $extension;
|
12
|
+
}
|
13
|
+
|
14
|
+
public function evaluate($content, array $contentVariables = array(), $id = null)
|
15
|
+
{
|
16
|
+
if (null === $id) {
|
17
|
+
throw new Exception("FileStorage: Could not evaluate. ID is null.");
|
18
|
+
}
|
19
|
+
return file_get_contents($this->_path . $id . $this->_extension);
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* (non-PHPdoc)
|
24
|
+
* @see Storage::isFresh()
|
25
|
+
*/
|
26
|
+
public function isFresh($id)
|
27
|
+
{
|
28
|
+
$path = $this->_path . $id . $this->_extension;
|
29
|
+
|
30
|
+
return file_exists($id)
|
31
|
+
&& file_exists($path)
|
32
|
+
&& filemtime($id) < filemtime($path);
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* (non-PHPdoc)
|
37
|
+
* @see Storage::cache()
|
38
|
+
*/
|
39
|
+
public function cache($id, $content)
|
40
|
+
{
|
41
|
+
$path = $this->_path . $id . $this->_extension;
|
42
|
+
|
43
|
+
if (!file_exists($path)) {
|
44
|
+
@fopen($path, "x+");
|
45
|
+
}
|
46
|
+
|
47
|
+
file_put_contents($path, $content);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* (non-PHPdoc)
|
52
|
+
* @see Storage::fetch()
|
53
|
+
*/
|
54
|
+
public function fetch($id)
|
55
|
+
{
|
56
|
+
return file_get_contents($this->_path . $id . $this->_extension);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* (non-PHPdoc)
|
61
|
+
* @see Storage::remove()
|
62
|
+
*/
|
63
|
+
public function remove($id)
|
64
|
+
{
|
65
|
+
$path = $this->_path . $id . $this->_extension;
|
66
|
+
return unlink($path);
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class FileStorage implements Storage, ContentEvaluator
|
4
|
+
{
|
5
|
+
protected $_path = null;
|
6
|
+
protected $_extension = null;
|
7
|
+
|
8
|
+
public function __construct($cachePath, $extension = '.cached.php')
|
9
|
+
{
|
10
|
+
$this->_path = $cachePath;
|
11
|
+
$this->_extension = $extension;
|
12
|
+
}
|
13
|
+
|
14
|
+
public function evaluate($content, array $contentVariables = array(), $id = null)
|
15
|
+
{
|
16
|
+
if (null === $id) {
|
17
|
+
throw new Exception("FileStorage: Could not evaluate. ID is null.");
|
18
|
+
}
|
19
|
+
|
20
|
+
ob_start();
|
21
|
+
extract($contentVariables);
|
22
|
+
require $this->_path . $id . $this->_extension;
|
23
|
+
$result = ob_get_clean();
|
24
|
+
|
25
|
+
return $result;
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* (non-PHPdoc)
|
30
|
+
* @see Storage::isFresh()
|
31
|
+
*/
|
32
|
+
public function isFresh($id)
|
33
|
+
{
|
34
|
+
$path = $this->_path . $id . $this->_extension;
|
35
|
+
|
36
|
+
return file_exists($id)
|
37
|
+
&& file_exists($path)
|
38
|
+
&& filemtime($id) < filemtime($path);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* (non-PHPdoc)
|
43
|
+
* @see Storage::cache()
|
44
|
+
*/
|
45
|
+
public function cache($id, $content)
|
46
|
+
{
|
47
|
+
$path = $this->_path . $id . $this->_extension;
|
48
|
+
|
49
|
+
if (!file_exists($path)) {
|
50
|
+
@fopen($path, "x+");
|
51
|
+
}
|
52
|
+
|
53
|
+
file_put_contents($path, $content);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* (non-PHPdoc)
|
58
|
+
* @see Storage::fetch()
|
59
|
+
*/
|
60
|
+
public function fetch($id)
|
61
|
+
{
|
62
|
+
return file_get_contents($this->_path . $id . $this->_extension);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* (non-PHPdoc)
|
67
|
+
* @see Storage::remove()
|
68
|
+
*/
|
69
|
+
public function remove($id)
|
70
|
+
{
|
71
|
+
$path = $this->_path . $id . $this->_extension;
|
72
|
+
return unlink($path);
|
73
|
+
}
|
74
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
interface Storage
|
4
|
+
{
|
5
|
+
/**
|
6
|
+
* Returns true if content is fresh and false if content should be cached.
|
7
|
+
*/
|
8
|
+
public function isFresh($id);
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Cache contents of a file.
|
12
|
+
*/
|
13
|
+
public function cache($id, $content);
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Returns content from a cache
|
17
|
+
*/
|
18
|
+
public function fetch($id);
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Remove cached content.
|
22
|
+
*/
|
23
|
+
public function remove($id);
|
24
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class InvalidTagException extends Exception
|
4
|
+
{
|
5
|
+
public function __construct($msg)
|
6
|
+
{
|
7
|
+
parent::__construct($msg);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
class TagNode extends HamlNode
|
12
|
+
{
|
13
|
+
private $_tags = array(
|
14
|
+
'for' => 'endfor',
|
15
|
+
'if' => 'endif',
|
16
|
+
'else if' => 'endif',
|
17
|
+
'else' => 'endif',
|
18
|
+
'while' => 'endwhile',
|
19
|
+
'foreach' => 'endforeach',
|
20
|
+
);
|
21
|
+
|
22
|
+
private $_line = null;
|
23
|
+
|
24
|
+
private $_isTag = false;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Can be either TagNode::SILENT_MODE or TagNode::LOUD_MODE
|
28
|
+
* @var string
|
29
|
+
*/
|
30
|
+
private $_mode;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* The tag this node represents. One of $_tags.
|
34
|
+
* @var string
|
35
|
+
*/
|
36
|
+
private $_tag;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* The php code whether it's a tag or a script
|
40
|
+
* @var string
|
41
|
+
*/
|
42
|
+
private $_code;
|
43
|
+
|
44
|
+
const CODE_PATTERN = '/(?P<mode>[-=])\s*(?P<code>(?P<tag>[^\:\(\)]+)\s*(\(.+\))?(?P<colon>:)?\s*$|[^\r\n]+)/';
|
45
|
+
const SILENT_MODE = '-';
|
46
|
+
const LOUD_MODE = '=';
|
47
|
+
|
48
|
+
public function __construct($line)
|
49
|
+
{
|
50
|
+
parent::__construct($line);
|
51
|
+
$this->_line = $line;
|
52
|
+
|
53
|
+
if (!preg_match(TagNode::CODE_PATTERN, $this->_line, $matches)) {
|
54
|
+
throw new InvalidTagException('Line does not match the pattern');
|
55
|
+
}
|
56
|
+
|
57
|
+
$this->_mode = $matches['mode'];
|
58
|
+
$this->_code = $matches['code'];
|
59
|
+
|
60
|
+
if (isset($matches['tag'])) {
|
61
|
+
$tag = trim($matches['tag']);
|
62
|
+
|
63
|
+
if (isset($this->_tags[$tag])) {
|
64
|
+
$this->_isTag = true;
|
65
|
+
$this->_tag = $tag;
|
66
|
+
if (!isset($matches['colon']))
|
67
|
+
$this->_code .= ':';
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
if($this->_isTag && TagNode::LOUD_MODE == $this->_mode)
|
72
|
+
throw new InvalidTagException('Loud mode is not allowed for the tags '.join(', ', array_keys($this->_tags)).
|
73
|
+
'. Use silent mode (-).');
|
74
|
+
}
|
75
|
+
|
76
|
+
public function render()
|
77
|
+
{
|
78
|
+
if($this->_isTag)
|
79
|
+
return $this->generateTagContent() . "\n";
|
80
|
+
|
81
|
+
$mode = '';
|
82
|
+
if(TagNode::LOUD_MODE == $this->_mode)
|
83
|
+
$mode = 'echo ';
|
84
|
+
|
85
|
+
return $this->getSpaces() . "<?php $mode{$this->_code} ?>\n";
|
86
|
+
}
|
87
|
+
|
88
|
+
public function getTagName()
|
89
|
+
{
|
90
|
+
return $this->_tag;
|
91
|
+
}
|
92
|
+
|
93
|
+
private function isTag($line)
|
94
|
+
{
|
95
|
+
if (preg_match(TagNode::CODE_PATTERN, $line, $matches)) {
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
|
99
|
+
return false;
|
100
|
+
}
|
101
|
+
|
102
|
+
private function generateTagContent()
|
103
|
+
{
|
104
|
+
$content = $this->getSpaces() . "<?php " . $this->_code . " ?>\n";
|
105
|
+
$content .= $this->renderChildren();
|
106
|
+
|
107
|
+
$compiler = $this->getCompiler();
|
108
|
+
$nextLine = $compiler->getLine($this->getLineNumber() + $this->getChildrenCount() + 1);
|
109
|
+
$nextLineTag = null;
|
110
|
+
|
111
|
+
if ($nextLine !== null && $this->isTag($nextLine)) {
|
112
|
+
$nextLineTag = new TagNode($nextLine);
|
113
|
+
}
|
114
|
+
|
115
|
+
if (!($nextLineTag !== null
|
116
|
+
&& strtolower($nextLineTag->getTagName()) !== 'if'
|
117
|
+
&& strlen($nextLineTag->getSpaces()) == strlen($this->getSpaces()))) {
|
118
|
+
$content .= $this->getSpaces() . "<?php " . $this->_tags[$this->_tag] . "; ?>";
|
119
|
+
} else {
|
120
|
+
$content = rtrim($content);
|
121
|
+
}
|
122
|
+
|
123
|
+
return $content;
|
124
|
+
}
|
125
|
+
}
|
@@ -0,0 +1,340 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Class BaseException
|
5
|
+
*
|
6
|
+
* This is the base exception class for all classes in the framework.
|
7
|
+
* This class provides core funcionality, like automatically replacing
|
8
|
+
* available placeholders.
|
9
|
+
*
|
10
|
+
* The placeholders provided by this class are:
|
11
|
+
*
|
12
|
+
* {{code}} - The user defined exception code
|
13
|
+
* {{file}} - The file where the exception was thrown
|
14
|
+
* {{guiltyFile}} - The file guilty for the exception
|
15
|
+
* {{line}} - The line where the exception was thrown
|
16
|
+
* {{guiltyLine}} - The line guilty for the exception
|
17
|
+
* {{function}} - The function or method where the exception was thrown
|
18
|
+
* {{guiltyFunction}} - The function or method where the exception was thrown
|
19
|
+
* {{class}} - The class, in case the exception occurs inside a method, wich the method belongs to
|
20
|
+
* {{guiltyClass}} - The class, in case the exception occurs inside a method, wich the method belongs to
|
21
|
+
*
|
22
|
+
* @author Saulo Vallory <email@saulovallory.com>
|
23
|
+
*/
|
24
|
+
class BaseException extends Exception
|
25
|
+
{
|
26
|
+
/**
|
27
|
+
* The exception message with the placeholders
|
28
|
+
* replaced by the tokens.
|
29
|
+
*
|
30
|
+
* @var string
|
31
|
+
*/
|
32
|
+
protected $message = 'Unknown exception';
|
33
|
+
|
34
|
+
/**
|
35
|
+
* The original exception message, with the
|
36
|
+
* placeholders intact.
|
37
|
+
*
|
38
|
+
* @var string
|
39
|
+
*/
|
40
|
+
protected $origMsg = 'Unknown exception';
|
41
|
+
|
42
|
+
/**
|
43
|
+
* User defined exception code
|
44
|
+
*
|
45
|
+
* @var string
|
46
|
+
*/
|
47
|
+
protected $code = 0;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Source filename of exception
|
51
|
+
*
|
52
|
+
* @var string
|
53
|
+
*/
|
54
|
+
protected $file;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Source line of exception
|
58
|
+
*
|
59
|
+
* @var string
|
60
|
+
*/
|
61
|
+
protected $line;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Source function of exception
|
65
|
+
*
|
66
|
+
* @var string
|
67
|
+
*/
|
68
|
+
protected $function;
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Source class of exception
|
72
|
+
*
|
73
|
+
* @var string
|
74
|
+
*/
|
75
|
+
protected $class;
|
76
|
+
|
77
|
+
/**
|
78
|
+
* The file guilty for the exception
|
79
|
+
*
|
80
|
+
* @var string
|
81
|
+
*/
|
82
|
+
protected $guiltyFile;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* The line guilty for the exception
|
86
|
+
*
|
87
|
+
* @var int
|
88
|
+
*/
|
89
|
+
protected $guiltyLine;
|
90
|
+
|
91
|
+
/**
|
92
|
+
* The line guilty for the exception
|
93
|
+
*
|
94
|
+
* @var string
|
95
|
+
*/
|
96
|
+
protected $guiltyFunction;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* The line guilty for the exception
|
100
|
+
*
|
101
|
+
* @var string
|
102
|
+
*/
|
103
|
+
protected $guiltyClass;
|
104
|
+
|
105
|
+
/**
|
106
|
+
* A piece of code around where the error or exception was throwed
|
107
|
+
*
|
108
|
+
* @var string
|
109
|
+
*/
|
110
|
+
private $source;
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Constructor
|
114
|
+
*
|
115
|
+
* @param string $message The error message. This can be a string or an instance of
|
116
|
+
* ErrorMsg. The other parameters will be used to replace placeholders
|
117
|
+
* ({0:param name}, {1:param}, {2:name}, etc.) in the message.
|
118
|
+
*/
|
119
|
+
public function __construct($message, $tokens = array())
|
120
|
+
{
|
121
|
+
global $ex;
|
122
|
+
|
123
|
+
foreach($tokens as $tok)
|
124
|
+
$message = preg_replace('%\\{\\{([\\d]+:)?[\\w\\s]*\\}\\}%', (string)$tok, $message, 1);
|
125
|
+
|
126
|
+
$this->origMsg = $message;
|
127
|
+
|
128
|
+
$this->message = $message;
|
129
|
+
$this->updateMessage();
|
130
|
+
|
131
|
+
parent::__construct();
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* This function gets an array with two items
|
136
|
+
* the first is the placeholder found and the second is the
|
137
|
+
* placeholder name (ex: {{file}} and file). The purpose of
|
138
|
+
* this function is replace message placeholders with its
|
139
|
+
* values. If you want to extend this functionality you can
|
140
|
+
* override this function, but you must call this function
|
141
|
+
* at the end of yours.
|
142
|
+
*
|
143
|
+
* @param array $match
|
144
|
+
*/
|
145
|
+
protected static function replacePlaceholder(array $match)
|
146
|
+
{
|
147
|
+
global $_nb_ex;
|
148
|
+
|
149
|
+
if(!isset($match[1]))
|
150
|
+
throw new InvalidArgumentValueException('match', $match, ErrorMsg::$BaseException_invalidPlaceholderMatch);
|
151
|
+
|
152
|
+
$getter = 'get'.ucfirst($match[1]);
|
153
|
+
|
154
|
+
if(method_exists($_nb_ex,$getter))
|
155
|
+
{
|
156
|
+
return $_nb_ex->$getter();
|
157
|
+
}
|
158
|
+
|
159
|
+
return $match[0];
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Get the file guilty for the exception
|
164
|
+
*
|
165
|
+
* @return string
|
166
|
+
*/
|
167
|
+
public function getGuiltyFile()
|
168
|
+
{
|
169
|
+
return $this->guiltyFile;
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Get the line guilty for the exception
|
174
|
+
*
|
175
|
+
* @return int
|
176
|
+
*/
|
177
|
+
public function getGuiltyLine()
|
178
|
+
{
|
179
|
+
return $this->guiltyLine;
|
180
|
+
}
|
181
|
+
/**
|
182
|
+
* @return string
|
183
|
+
*/
|
184
|
+
public function getClass()
|
185
|
+
{
|
186
|
+
if(isset($this->class))
|
187
|
+
return $this->class;
|
188
|
+
|
189
|
+
$this->grabTraceData();
|
190
|
+
|
191
|
+
return $this->class;
|
192
|
+
}
|
193
|
+
|
194
|
+
/**
|
195
|
+
* @return string
|
196
|
+
*/
|
197
|
+
public function getFunction()
|
198
|
+
{
|
199
|
+
if(isset($this->function))
|
200
|
+
return $this->function;
|
201
|
+
|
202
|
+
$this->grabTraceData();
|
203
|
+
|
204
|
+
return $this->function;
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* @return string
|
209
|
+
*/
|
210
|
+
public function getGuiltyClass () {
|
211
|
+
return $this->guiltyClass ;
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* @return string
|
216
|
+
*/
|
217
|
+
public function getGuiltyFunction () {
|
218
|
+
return $this->guiltyFunction ;
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* @return string
|
223
|
+
*/
|
224
|
+
public function getOrigMsg() {
|
225
|
+
return $this->origMsg ;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* This function grabs all the possible useful
|
230
|
+
* data from trace and put it on class properties
|
231
|
+
*/
|
232
|
+
protected function grabTraceData()
|
233
|
+
{
|
234
|
+
$this->trace = $this->getTrace();
|
235
|
+
|
236
|
+
if(isset($this->trace[0]))
|
237
|
+
{
|
238
|
+
if(isset($this->trace[0]['class']))
|
239
|
+
$this->class = $this->trace[0]['class'];
|
240
|
+
|
241
|
+
if(isset($this->trace[0]['function']))
|
242
|
+
$this->function = $this->trace[0]['function'];
|
243
|
+
}
|
244
|
+
else
|
245
|
+
{
|
246
|
+
$this->class = '';
|
247
|
+
$this->function = '';
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @param string $class
|
253
|
+
*/
|
254
|
+
public function setClass($class) {
|
255
|
+
if($this->class === $class)
|
256
|
+
$this->class = $class ;
|
257
|
+
|
258
|
+
if(strpos($this->origMsg,'{{class}}') !== false)
|
259
|
+
$this->updateMessage();
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @param string $function
|
264
|
+
*/
|
265
|
+
public function setFunction($function) {
|
266
|
+
$this->function = $function;
|
267
|
+
}
|
268
|
+
|
269
|
+
/**
|
270
|
+
* @param string $guiltyClass
|
271
|
+
*/
|
272
|
+
public function setGuiltyClass ( $guiltyClass ) {
|
273
|
+
$this->message = str_replace('{{guiltyClass}}', $guiltyClass, $this->message);
|
274
|
+
$this->guiltyClass = $guiltyClass ;
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* @param string $guiltyFunction
|
279
|
+
*/
|
280
|
+
public function setGuiltyFunction ( $guiltyFunction ) {
|
281
|
+
$this->message = str_replace('{{guiltyFunction}}', $guiltyFunction, $this->message);
|
282
|
+
$this->guiltyFunction = $guiltyFunction ;
|
283
|
+
}
|
284
|
+
|
285
|
+
/**
|
286
|
+
* @param string $origMsg
|
287
|
+
*/
|
288
|
+
public function setOrigMsg ( $origMsg ) {
|
289
|
+
$this->origMsg = $origMsg ;
|
290
|
+
}
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Set the line file for the exception
|
294
|
+
*
|
295
|
+
* @param string $filePath
|
296
|
+
*/
|
297
|
+
public function setGuiltyFile($filePath)
|
298
|
+
{
|
299
|
+
$this->message = str_replace('{{guiltyFile}}', $filePath, $this->message);
|
300
|
+
$this->guiltyFile = (string)$filePath;
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Set the line guilty for the exception
|
305
|
+
*
|
306
|
+
* @param int $lineNumber
|
307
|
+
*/
|
308
|
+
public function setGuiltyLine($lineNumber)
|
309
|
+
{
|
310
|
+
$this->message = str_replace('{{guiltyLine}}', $lineNumber, $this->message);
|
311
|
+
$this->guiltyLine = (int)$lineNumber;
|
312
|
+
}
|
313
|
+
|
314
|
+
/**
|
315
|
+
* This function updates the exception message based on
|
316
|
+
* the original message and the current object property values
|
317
|
+
*
|
318
|
+
*/
|
319
|
+
protected function updateMessage()
|
320
|
+
{
|
321
|
+
$_nb_ex = $this;
|
322
|
+
$this->message = preg_replace_callback('|\{\{([\w _]+)\}\}|', array('BaseException', 'replacePlaceholder'), $this->message);
|
323
|
+
$_nb_ex = null;
|
324
|
+
}
|
325
|
+
|
326
|
+
public function getSourceLines()
|
327
|
+
{
|
328
|
+
return $this->source;
|
329
|
+
}
|
330
|
+
|
331
|
+
public function setSourceLines($source)
|
332
|
+
{
|
333
|
+
$this->source = $source;
|
334
|
+
}
|
335
|
+
|
336
|
+
public function setCode($code)
|
337
|
+
{
|
338
|
+
$this->code = $code;
|
339
|
+
}
|
340
|
+
}
|